Rotating Bitmaps !!!!
-
Im using this method needless to say is not working and need some help.
void rotateb(Bitmap* image, HDC dc){ Graphics graphics(dc); Bitmap* SrcBitmap1 = image; Color mc; int angle=45; //45° for example //Convert degrees to radians float radians=(2*3.1416*angle)/360; float cosine=(float)cos(radians); float sine=(float)sin(radians); float Point1x=(-SrcBitmap1->GetHeight()*sine); float Point1y=(SrcBitmap1->GetHeight()*cosine); float Point2x=(SrcBitmap1->GetWidth()*cosine-SrcBitmap1->GetHeight()*sine); float Point2y=(SrcBitmap1->GetHeight()*cosine+SrcBitmap1->GetWidth()*sine); float Point3x=(SrcBitmap1->GetWidth()*cosine); float Point3y=(SrcBitmap1->GetWidth()*sine); float minx=min(0,min(Point1x,min(Point2x,Point3x))); float miny=min(0,min(Point1y,min(Point2y,Point3y))); float maxx=max(Point1x,max(Point2x,Point3x)); float maxy=max(Point1y,max(Point2y,Point3y)); int DestBitmapWidth=(int)ceil(fabs(maxx)-minx); int DestBitmapHeight=(int)ceil(fabs(maxy)-miny); Bitmap* DestBitmap = new Bitmap(DestBitmapWidth, DestBitmapHeight); //---------- for(int x=0;x=0&&SrcBitmapxGetWidth() && SrcBitmapy>= 0 && SrcBitmapyGetHeight()) { SrcBitmap1->GetPixel(SrcBitmapx,SrcBitmapy,&mc); DestBitmap->SetPixel(x,y,mc); } } } graphics.DrawImage(DestBitmap,0, 0); <-- this does not //graphics.DrawImage(SrcBitmap1,0,0); <-- this displays }
Thank you -
Im using this method needless to say is not working and need some help.
void rotateb(Bitmap* image, HDC dc){ Graphics graphics(dc); Bitmap* SrcBitmap1 = image; Color mc; int angle=45; //45° for example //Convert degrees to radians float radians=(2*3.1416*angle)/360; float cosine=(float)cos(radians); float sine=(float)sin(radians); float Point1x=(-SrcBitmap1->GetHeight()*sine); float Point1y=(SrcBitmap1->GetHeight()*cosine); float Point2x=(SrcBitmap1->GetWidth()*cosine-SrcBitmap1->GetHeight()*sine); float Point2y=(SrcBitmap1->GetHeight()*cosine+SrcBitmap1->GetWidth()*sine); float Point3x=(SrcBitmap1->GetWidth()*cosine); float Point3y=(SrcBitmap1->GetWidth()*sine); float minx=min(0,min(Point1x,min(Point2x,Point3x))); float miny=min(0,min(Point1y,min(Point2y,Point3y))); float maxx=max(Point1x,max(Point2x,Point3x)); float maxy=max(Point1y,max(Point2y,Point3y)); int DestBitmapWidth=(int)ceil(fabs(maxx)-minx); int DestBitmapHeight=(int)ceil(fabs(maxy)-miny); Bitmap* DestBitmap = new Bitmap(DestBitmapWidth, DestBitmapHeight); //---------- for(int x=0;x=0&&SrcBitmapxGetWidth() && SrcBitmapy>= 0 && SrcBitmapyGetHeight()) { SrcBitmap1->GetPixel(SrcBitmapx,SrcBitmapy,&mc); DestBitmap->SetPixel(x,y,mc); } } } graphics.DrawImage(DestBitmap,0, 0); <-- this does not //graphics.DrawImage(SrcBitmap1,0,0); <-- this displays }
Thank you -
Im using this method needless to say is not working and need some help.
void rotateb(Bitmap* image, HDC dc){ Graphics graphics(dc); Bitmap* SrcBitmap1 = image; Color mc; int angle=45; //45° for example //Convert degrees to radians float radians=(2*3.1416*angle)/360; float cosine=(float)cos(radians); float sine=(float)sin(radians); float Point1x=(-SrcBitmap1->GetHeight()*sine); float Point1y=(SrcBitmap1->GetHeight()*cosine); float Point2x=(SrcBitmap1->GetWidth()*cosine-SrcBitmap1->GetHeight()*sine); float Point2y=(SrcBitmap1->GetHeight()*cosine+SrcBitmap1->GetWidth()*sine); float Point3x=(SrcBitmap1->GetWidth()*cosine); float Point3y=(SrcBitmap1->GetWidth()*sine); float minx=min(0,min(Point1x,min(Point2x,Point3x))); float miny=min(0,min(Point1y,min(Point2y,Point3y))); float maxx=max(Point1x,max(Point2x,Point3x)); float maxy=max(Point1y,max(Point2y,Point3y)); int DestBitmapWidth=(int)ceil(fabs(maxx)-minx); int DestBitmapHeight=(int)ceil(fabs(maxy)-miny); Bitmap* DestBitmap = new Bitmap(DestBitmapWidth, DestBitmapHeight); //---------- for(int x=0;x=0&&SrcBitmapxGetWidth() && SrcBitmapy>= 0 && SrcBitmapyGetHeight()) { SrcBitmap1->GetPixel(SrcBitmapx,SrcBitmapy,&mc); DestBitmap->SetPixel(x,y,mc); } } } graphics.DrawImage(DestBitmap,0, 0); <-- this does not //graphics.DrawImage(SrcBitmap1,0,0); <-- this displays }
Thank youAlso, if you aren't required to write the rotation code yourself, GDI+ will do it for you :) Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Also, if you aren't required to write the rotation code yourself, GDI+ will do it for you :) Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
hi the GDI+ i find is not very precise Mark i mean the image center shifts, and you have to draw the image then rotate the DC then draw it again you end up with two images and a rotated DC lol the method i posted is skipping the second for loop for some reason :wtf: thanks for your replies... back to digging :)
-
hi the GDI+ i find is not very precise Mark i mean the image center shifts, and you have to draw the image then rotate the DC then draw it again you end up with two images and a rotated DC lol the method i posted is skipping the second for loop for some reason :wtf: thanks for your replies... back to digging :)
hmm I've found it to be precise. Controlling the image center is easy handled. I'm not sure what you mean by rotating a DC and ending up with two images - It uses pretty much the same technique you are using. Check this out (if you want to :)). This spins an image (in a window, so you can watch) around its center point (like a propellor LOL) at 5 degree increments...
Gdiplus::Bitmap SrcBitmap(L"C:\\test.bmp", FALSE);
Graphics DstGraphics(*this); //
use an appropriate HWND here
REAL angle = 0.0f;
for (int i = 0; i < 200; ++i)
{
DstGraphics.ResetTransform();
DstGraphics.RotateTransform(angle);
DstGraphics.TranslateTransform(SrcBitmap.GetWidth() / 2.0f, SrcBitmap.GetWidth() / 2.0f, MatrixOrderAppend);
DstGraphics.DrawImage(&SrcBitmap, -((INT)SrcBitmap.GetWidth() / 2), -((INT)SrcBitmap.GetHeight() / 2),
SrcBitmap.GetWidth(), SrcBitmap.GetHeight());angle += 5.0f;
if (angle >= 360.0f)
angle -= 360.0f;//::Sleep(70);
}"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
hmm I've found it to be precise. Controlling the image center is easy handled. I'm not sure what you mean by rotating a DC and ending up with two images - It uses pretty much the same technique you are using. Check this out (if you want to :)). This spins an image (in a window, so you can watch) around its center point (like a propellor LOL) at 5 degree increments...
Gdiplus::Bitmap SrcBitmap(L"C:\\test.bmp", FALSE);
Graphics DstGraphics(*this); //
use an appropriate HWND here
REAL angle = 0.0f;
for (int i = 0; i < 200; ++i)
{
DstGraphics.ResetTransform();
DstGraphics.RotateTransform(angle);
DstGraphics.TranslateTransform(SrcBitmap.GetWidth() / 2.0f, SrcBitmap.GetWidth() / 2.0f, MatrixOrderAppend);
DstGraphics.DrawImage(&SrcBitmap, -((INT)SrcBitmap.GetWidth() / 2), -((INT)SrcBitmap.GetHeight() / 2),
SrcBitmap.GetWidth(), SrcBitmap.GetHeight());angle += 5.0f;
if (angle >= 360.0f)
angle -= 360.0f;//::Sleep(70);
}"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder