我正在创建一个加载 2 个图像的方法,对它们应用一些转换(缩放/旋转),然后使用 .NET Graphics 类在另一个图像上的某个点绘制它们。
我目前正在尝试的过程如下:
Load bmp1
Load bmp2
Create graphics object from bmp1
Apply tranformations
Save
Repeat process for bmp2
Instantiate new merged bmp obj
Create graphics object from merged bmp
Draw bmp1 & bmp2 on merged bmp
Save
我正在尝试使用以下代码执行此操作:
// load existing bmps
var bmp1 = new Bitmap(Path.Combine(_staticIconsPath, staticIcon.Filename));
var bmp2 = new Bitmap(Path.Combine(_movableIconsPath, movableIcon.Filename));
// apply transforms to bmp1
var canvas1 = Graphics.FromImage(bmp1);
canvas1.ScaleTransform(0.5f, 0.5f);
canvas1.RotateTransform(45.0f);
canvas1.Save();
// apply transforms to bmp2
var canvas2 = Graphics.FromImage(bmp2);
canvas2.ScaleTransform(0.5f, 0.5f);
canvas2.RotateTransform(45.0f);
canvas2.Save();
// create final merged bmp
var mergedBmp = new Bitmap(590, 590);
mergedBmp.SetResolution(bmp1.HorizontalResolution, bmp1.VerticalResolution);
// draw transformed images on to final bmp
var mergedCanvas = Graphics.FromImage(mergedBmp);
mergedCanvas.DrawImage(bmp1, 0, 0);
mergedCanvas.DrawImage(bmp2, 0, 0);
mergedCanvas.Save();
然而,最终结果只是加载了两个原始位图,它们都按预期绘制在彼此之上,但没有应用任何变换。
我以前从未使用过 GDI 或做过任何图像处理,所以我认为我误解了必须遵循的过程的基本内容。任何人都可以帮助我并指出我正确的方向吗?