bitmap镜像
大家好,我用以下方法将图片镜像,不知道还有没有更好的方法,谢谢!
BYTE *ptr;
for (int y = 0; y < Height; y++)
{
ptr =(BYTE *) Bmp-> ScanLine[y];
int wid = Width * 3;
BYTE bTmp;
for (int x = 0; x < wid/2; x+=3)
{
bTmp = ptr[x];
ptr[x]=ptr[wid - x-1];
ptr[wid - x-1] = bTmp;
bTmp = ptr[x+1];
ptr[x+1]=ptr[wid - x-2];
ptr[wid - x-2] = bTmp;
bTmp = ptr[x+2];
ptr[x+2]=ptr[wid - x-3];
ptr[wid - x-3] = bTmp;
}
}
[解决办法]
用指针比数组快些
[解决办法]
代码如下
HDC hdc;
HDC mdc;
BITMAP bm;
HBITMAP hBmp;
unsigned char *px; // 指向存储像素的地址
hdc = GetDC(hWnd);
mdc = CreateCompatibleDC(hdc);
hBmp = LoadImage(NULL, "test.bmp ", IMAGE_BITMAP, 40, 40, LR_LOADFROMFILE);
GetObject(hBmp, sizeof(BITMAP), &bm);
px = new unsigned char[bm.bmHeight * bmWidthBytes];
//把图片的内容存储到px数组中
GetBitmapBits(hBmp, bm.bmHeight * bm.WidthBytes, px);
//接下来就是镜像了
.....
//把数据再写回到hBmp
GetBitmapBits(hBmp, bm.bmHeight * bm.WidthBytes, px);
delete []px;
DeleteObject(hBmp);
DeleteDC(hdc);
[解决办法]
CopyRect就可以了。