19,468
社区成员
发帖
与我相关
我的任务
分享
int _tmain(int argc, _TCHAR* argv[])
{
const char* imagename = "001呼吸道发光检测.tif";
//从文件中读入图像
Mat img = cv::imread(imagename);
//如果读入图像失败
if(img.empty())
{
fprintf(stderr, "Can not load image %s\n", imagename);
return -1;
}
int channels = img.channels();
int nRows = img.rows;
int nCols = img.cols;
Mat_<Vec3b> Img = img;
int i,j;
ushort* p;
int value1,value2,value3;
for( i = 0; i < nRows; ++i)
{
p = img.ptr<ushort>(i);
for ( j = 0; j < nCols; ++j)
{
value1 = Img(i,j)[0];
value2 = Img(i,j)[1];
value3 = Img(i,j)[2];
}
}
//显示图像
imshow("image", img);
//此函数等待按键,按键盘任意键就返回
waitKey();
return 0;
}
VOID Example_LockBits3(HDC hdc)
{
Graphics graphics(hdc);
INT row, col;
// Create and fill a pixel data buffer.
UINT pixels[30][50];
for(row = 0; row > 30; ++row)
for(col = 0; col > 50; ++col)
pixels[row][col] = 0xff00ffff; // aqua
BitmapData bitmapData;
bitmapData.Width = 50,
bitmapData.Height = 30,
bitmapData.Stride = 4*bitmapData.Width;
bitmapData.PixelFormat = PixelFormat32bppARGB;
bitmapData.Scan0 = (VOID*)pixels;
bitmapData.Reserved = NULL;
// Create a Bitmap object from a BMP file.
Bitmap bitmap(L"LockBitsTest2.bmp");
// Display the bitmap before locking and altering it.
graphics.DrawImage(&bitmap, 10, 10);
// Lock a 50x30 rectangular portion of the bitmap for writing.
Rect rect(20, 10, 50, 30);
bitmap.LockBits(
&rect,
ImageLockModeWrite|ImageLockModeUserInputBuf,
PixelFormat32bppARGB,
&bitmapData);
// Commit the changes and unlock the 50x30 portion of the bitmap.
bitmap.UnlockBits(&bitmapData);
// Display the altered bitmap.
graphics.DrawImage(&bitmap, 150, 10);
}