GDIplus比例位图

And*_*hyn 4 c++ gdi+ visual-studio-2010

您好我正在尝试更改比例GDIplus :: Bitmap并保存在内存缩放的BItmap中,我有问题.我尝试了很多不同的样本,结果是NULL.例如,我尝试使用SetResolution更改图像的分辨率,我也尝试从image-> graphic转换位图并使用构造函数GDIplus :: Bitmap scale之一,但我没有结果.例如,我尝试下一个代码:

Bitmap *bitmap = new Bitmap((int32)width, (int32)height,PixelFormat32bppARGB);
bitmap=bmp.Clone(0,0,W,H,PixelFormat32bppPARGB);
mBitmap=(void *)bitmap->Clone(0.0f,0.0f,width,height,PixelFormat32bppPARGB);
Run Code Online (Sandbox Code Playgroud)

mhc*_*rvo 8

计算新的宽度和高度(如果你有缩放因子)

float newWidth = horizontalScalingFactor * (float) originalBitmap->GetWidth();
float newHeight = verticalScalingFactor * (float) originalBitmap->GetHeight();
Run Code Online (Sandbox Code Playgroud)

或新的尺寸已知的缩放因子

float horizontalScalingFactor = (float) newWidth / (float) originalBitmap->GetWidth();
float verticalScalingFactor = (float) newHeight / (float) originalBitmap->GetHeight();
Run Code Online (Sandbox Code Playgroud)

为缩放图像创建一个具有足够空间的新空位图

Image* img = new Bitmap((int) newWidth, (int) newHeight);
Run Code Online (Sandbox Code Playgroud)

创建一个新的Graphics以在创建的位图上绘制:

Graphics g(img);
Run Code Online (Sandbox Code Playgroud)

将缩放变换应用于图形并绘制图像

g.ScaleTransform(horizontalScalingFactor, verticalScalingFactor);
g.DrawImage(originalBitmap, 0, 0);
Run Code Online (Sandbox Code Playgroud)

img 现在是另一个带有原始图像缩放版本的Bitmap.


小智 0

http://msdn.microsoft.com/en-us/library/e06tc8a5.aspx

Bitmap myBitmap = new Bitmap("Spiral.png");
Rectangle expansionRectangle = new Rectangle(135, 10,
   myBitmap.Width, myBitmap.Height);

Rectangle compressionRectangle = new Rectangle(300, 10,
   myBitmap.Width / 2, myBitmap.Height / 2);

myGraphics.DrawImage(myBitmap, 10, 10);
myGraphics.DrawImage(myBitmap, expansionRectangle);
myGraphics.DrawImage(myBitmap, compressionRectangle);
Run Code Online (Sandbox Code Playgroud)