非托管VC++.net使用GDI+时如何调用LockBits!

seatree 2008-04-23 05:45:05
如题,已经搞定在vc++.net中使用GDI+
但是访问像素就要靠lockbits,现在遇到的问题就是C#中lockbits很好调用,不知VC++.net中如何调用,最好有调用的源代码
...全文
122 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
meiZiNick 2008-05-01
  • 打赏
  • 举报
回复
支持搂主,收藏
蒋晟 2008-04-25
  • 打赏
  • 举报
回复
Bitmap是从Image派生出来的,可以直接传指针
seatree 2008-04-24
  • 打赏
  • 举报
回复
bitmap是有这个方法,但是graphics类的drawimage方法不支持bitmap,只支持image类型,不知如何把bitmap类型转换过去
蒋晟 2008-04-24
  • 打赏
  • 举报
回复
http://msdn2.microsoft.com/en-us/library/ms536291(VS.85).aspx
seatree 2008-04-24
  • 打赏
  • 举报
回复
而且很奇怪GDI+里面的image没有fromHbitmap方法,有的话一下就解决了
seatree 2008-04-24
  • 打赏
  • 举报
回复
就剩下唯一的问题了,经这样处理的bitmap如何显示处理,GDI+的graphics只有drawimage,不知怎么显示!
菜牛 2008-04-23
  • 打赏
  • 举报
回复
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

INT main()
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

Bitmap* bitmap = new Bitmap(L"LockBitsTest1.bmp");
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);

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;
}

不好意思,MSDN上的。

19,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧