How to maintan aspect ratio with bitblt?

Started by
1 comment, last by Aman 22 years, 3 months ago
Any ideas (theory) on how to maintan an aspect ratio using bitblt? MSVC++ 6, GDI I have a source bitmap of x size (arbatrary size) I have a destination rect of set size (96x96) Currently I just StretchBlt. I would like to maintan the aspect ratio with a black backgound. Any ideas? (theroy, steps, process not just cut/paste code) Thanks up front, Aman
Its better to be silent and thought a foolthen to speak and remove all doubt.
Advertisement
Well.. it''s actually pretty simple... you could trying something like this..

  void BlitImage(long DestHdc, long SrcHdc, BitmapSizeX, BitmapSizeY) { float Ratio, size; if (BitmapSizeX>BitmapSizeY) //X > Y! {  Ratio = 96.0/BitmapSizeX;  size = Ratio*BitmapSizeY; //Size Y in new ratio!//48.0-size/2.0 centers the bitmap!  StretchBlt(DestHdc,0,48.0- size/2.0,96.0,size,SrcHdc,0,0,BitmapSizeX,BitmapSizeY,SRCCOPY); } else //Y > X! {  Ratio = 96.0/BitmapSizeY;  size = Ratio*BitmapSizeX; //Size X in new ratio!//48.0-size/2.0 centers the bitmap!  StretchBlt(DestHdc,48.0-size/2.0,0,size,96.0,SrcHdc,0,0,BitmapSizeX,BitmapSizeY,SRCCOPY); }}  


Basically what this does is checks which ratio is going to be larger (X or Y ratio). If the x is larger, then the bitmap will be completely across, and leave gaps at the top/bottom (to keep aspect ratio). If the y is larger, then the opposite happens. It''s really simple actually.

Billy - BillyB@mrsnj.com

Disclaimer: This was written in this text box, and is subject to mispellings, and non-compiling problems without warning... so use at your own risk :o)
Oh yeah.. and you can just do a clear on the Destination bitmap before blitting.

Billy

This topic is closed to new replies.

Advertisement