Originally posted by: marco
So, in the last code it's better to substitute each
x/8 with (x>>3)
Or should I trust the copiler to do it? I doubt it.
What I belive (correct me if I'm wrong) is that bitwise operations are to be very mu8ch preferred to modules ("%") and divisions.
x/4 with (x>>2)
x/2 with (x>>1)
x%8 with (x & 7)
x%16 with (x & 15)
x*2 with (x<<1)
and so on.
Originally posted by: Marsh
The Win32 API docs for BitBlt and StretchBlt say "If the source transformation has a rotation or shear, an error occurs.".
Of course the error that occurs is not a nice error return value, but it returns success and produces a distorted bitmap as a result. It works often enough (on NT 4 SP 6) to make one think it's reliable, but it's not. It doesn't even work reliably with 90 degree rotations.
This was demonstrated with both video and printer drivers.
(but that URL may change)
ReplyOriginally posted by: chungsu Kim
modify....
int w = maxx - minx + 1;
int h = maxy - miny + 1;
Reply
Originally posted by: Hyun
i'm working on a graphic editor which rotates an image.
i made a dll file that includes function above and i called it from Visual Basic. i succeeded with function 1 which is available for NTs only as far as i know, so now i'm trying to use the function 3. i was confronted by the fact that function 3 has a different type of incoming value(i mean 'HANDLE hDIB'). for function 1, i just made a handle of bitmap like this: ' hbitmap = loadimage(.....)' and i cast this handle to the function 1 and it worked.
Would anybody tell me how i get the Handle of DIB in Visual Basic, or any other way i can use to get the function 3 into operation related to visual basic?
Please help me out...
Originally posted by: The G Man
#include <math.h>
/*
Bitmap Rotation Code By The G Man
radians, angle in radians you what to rotate the bitmap
clrBack, The Color in the bimap you dont want to draw
XX, The X location you want the center to be
YY, The Y location you want the center to be
Height, Height of bitmap
Width, width of bitmap
Source, pointer to a CBitmap
Center CPoint of the center off set, 0,0 is the center - is top left + botom right
theHDC the HDC
*/
void RotatedBitmap2(float radians,
COLORREF clrBack,
int XX,
int YY,
int Height,
int Width,
CBitmap *Source,
CPoint Center,
HDC theHDC);
void RotatedBitmap2(float radians, COLORREF clrBack, int XX, int YY, int Height, int Width, CBitmap *Source, CPoint Center, HDC theHDC)
{
CDC Bitmap_DC;
Bitmap_DC.CreateCompatibleDC( NULL );
Bitmap_DC.SelectObject(Source);
COLORREF C[4];
double Pi = 3.14159265359;
int c1x;
int c1y;
float a=0;
int r;
int p1x;
int p1y;
int p2x;
int p2y;
int n;
float cosine = (float)cos(radians);
float sine = (float)sin(radians);
int modX = (int)(Center.x*cosine + Center.y*sine);
int modY = (int)(Center.y*cosine - Center.x*sine);
c1x = Width / 2;
c1y = Height / 2;
n = sqrt((c1x * c1x) + (c1y * c1y));
for(p2x = 0;p2x<n;p2x++)
{
for(p2y=0;p2y<n;p2y++)
{
if(p2x==0)a=Pi/2.0;
else a=tanh(p2y/(p2x*1.0));
r = sqrt(p2x*p2x + p2y*p2y);
p1x = (int)(p2x*cosine - p2y*sine);
p1y = (int)(p2y*cosine + p2x*sine);
C[0] = Bitmap_DC.GetPixel(c1x + p1x,c1y + p1y);
C[1] = Bitmap_DC.GetPixel(c1x - p1x,c1y - p1y);
C[2] = Bitmap_DC.GetPixel(c1x + p1y,c1y - p1x);
C[3] = Bitmap_DC.GetPixel(c1x - p1y,c1y + p1x);
if(C[0] !=clrBack&&C[0] !=-1) ::SetPixel(theHDC,c1x + p2x+XX+modX, c1y + p2y+YY+modY, C[0]);
if(C[1] !=clrBack&&C[1] !=-1) ::SetPixel(theHDC,c1x - p2x+XX+modX, c1y - p2y+YY+modY, C[1]);
if(C[2] !=clrBack&&C[2] !=-1) ::SetPixel(theHDC,c1x + p2y+XX+modX, c1y - p2x+YY+modY, C[2]);
if(C[3] !=clrBack&&C[3] !=-1) ::SetPixel(theHDC,c1x - p2y+XX+modX, c1y + p2x+YY+modY, C[3]);
}
}
}
Originally posted by: Sarorn Rith
I'm not that good in math. But i'm trying to understand the formula of rotating in degrees of fixed area. Say i have a 500x500 height/width & want to draw a line rotating. Can ya give me a quick example =]
ReplyOriginally posted by: Winstone Jordaan
How about trying a 3D rotation for bitmaps ???
ReplyOriginally posted by: Todd Cherry
This rotation works great for simple 90/180 degree flips; However, i noticed that i run out of memory when doing continuious rotations, the reason? Add these lines to solve that problem right before you return the new handle.
DeleteObject(hbmOldSource);
DeleteObject(hbmOldDest);
DeleteObject(hBitmap);
Regards,
Todd
Originally posted by: Roger
Is it possible to call the BMP rotation (WIN95) from Visual Basic App.?
If so ; How ? Grateful for any suggestions.
Roger.......................
ReplyOriginally posted by: Simon Capewell
That would be a bit tricky seeing as this particular part of the standard library is the bit calling WinMain!
You could always write your own startup code that is called by CreateProcess yourself, but why reinvent
the wheel?