求助:Bitmap类LockBits使用问题
#include <windows.h>#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;
#pragma comment(lib, "D:/Program Files/Microsoft Platform SDK/Lib/gdiplus.lib")
INT main()
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput,NULL);
Bitmap* bitmap = new Bitmap(L"LockBitsTest1.bmp");
UINT height = bitmap->GetHeight();
UINT width = bitmap->GetWidth();
BitmapData* bitmapData = new BitmapData;
Rect rect(20,30,5,3);
//Lock a 5X3 rectangular portion of the bitmap for reading.
//bitmap->LockBits(&rect,ImageLockModeRead,PixelFormat32bppARGB,bitmapData);
bitmap->LockBits(&rect,ImageLockModeWrite,PixelFormat32bppARGB,bitmapData);
printf("The stride is %d.\n\n",bitmapData->Stride);
//Display the hexadecimal value of each pixel in the 5X3 rectangle.
UINT* pixels = (UINT*)bitmapData->Scan0;
for(UINT row=0;row<3;++row)
{
for(UINT col=0;col<5;++col)
{
printf("%x\n",pixels[row*bitmapData->Stride/4+col]);
}
printf("- - - - - - - - - - - -\n");
}
bitmap->UnlockBits(bitmapData);
delete bitmapData;
delete bitmap;
GdiplusShutdown(gdiplusToken);
return 0;
}
上面是小弟的例程, 通过单步调试结果:
在执行到bitmap->LockBits(&rect,ImageLockModeWrite,PixelFormat32bppARGB,bitmapData);
后,bitmapData的数据没改变...
而如果改成只读模式ImageLockModeRead就没问题,
请问这个是为什么呢????
补充:.NET技术 , C#