15,979
社区成员
发帖
与我相关
我的任务
分享
例如:(图像不能太大,背景必须为单色)
Bitmap bmp(L"米老鼠和唐老鸭.bmp");
Graphics graph(pDC->m_hDC);
graph.DrawImage(&bmp, 0, 0);
int w = bmp.GetWidth(), h = bmp.GetHeight();
Region rgn(Rect(0, 0, w, h));
Color col, col0;
bmp.GetPixel(0, 0, &col0); // 获取背景色 Image.GetPixel(x,y,&Color);
ARGB argb0 = col0.GetValue();
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
bmp.GetPixel(i, j, &col);
if (col.GetValue() == argb0) { // ARGB可直接比较
Region pixelRgn(Rect(i, j, 1, 1)); // 单像素矩形(x,y,高,宽)
rgn.Exclude(&pixelRgn); // 挖去
}
}
}
graph.TranslateTransform(REAL(w), 0.0f);
graph.FillRegion(&SolidBrush(Color::Green), &rgn); // 容易溢出???