一.
二. 微软做好的,GDI+绘制代码:
Graphics graphics(hdc);
Image myImage(L"Image.jpg");
RectF source(0.0f, 0.0f, 330.0f, 300.0f);
RectF destination(20.0f, 20.0f, 330.0f, 300.0f);
DrawImage(graphics, &myImage, destination, source, UnitPixel, NULL); // 绘制原始图像
RectF destination2(420.0f, 20.0f, 330.0f, 300.0f);
#define GRAY 32/256.0f /* gray/full, 0 - 256 : black to white, 16 - 64 is recommended */
#define GRAY 0.125f /* 0.000 - 1.000 : black to white, 0.062 - 0.250 is recommended */
#define FULL 1.000f
#define ZERO 0.000f
// 自由转换
ColorMatrix matrix = {
GRAY, GRAY, GRAY, FULL, ZERO,
GRAY, GRAY, GRAY, FULL, ZERO,
GRAY, GRAY, GRAY, FULL, ZERO,
GRAY, GRAY, GRAY, FULL, ZERO,
ZERO, ZERO, ZERO, ZERO, FULL,
};
ImageAttributes attributes;
attributes.SetColorMatrix(&matrix);
DrawImage(graphics, &myImage, destination2, source, UnitPixel, &attributes); // 绘制转换图像
DrawImage 是自定义函数
C/C++ code
void DrawImage(Graphics& graphics, Image* image, RectF& destination, RectF& source, Unit unit, ImageAttributes* attributes)
{
graphics.DrawImage(image, destination, source.X, source.Y, source.Width, source.Height, unit, attributes);
}