一个关于显示图片的问题~!

幸福的小雨 2007-04-06 08:47:14
我建立了一个Win32Application的工程 并且我把.bmp图片保存到工程的1.rc文件了命名为IDB_BITMAP。可是怎么才能把工程里的图片输出到屏幕呀,谢谢朋友们呀

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
while(1)
{
HDC dc;
HICON hicon;
dc=CreateDC("DISPLAY",NULL,NULL,NULL);
hicon=(HICON)LoadImage(hInst,"F:\\Myproject\\project\\1\\ico.ico",IMAGE_ICON,0,0,LR_LOADFROMFILE|LR_DEFAULTCOLOR);
DrawIcon(dc,10,10,hicon);
_sleep(1000);

//这里怎么把.BMP图片显示出来呢?
HBITMAP hbitmap=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP));
HDC hMemDC=CreateCompatibleDC(NULL);
SelectObject(hMemDC,hbitmap);
//DrawState(dc,NULL,NULL,(LPARAM)hBitmap,..........
}
// return msg.wParam;
return 0;
}
...全文
160 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fohonet 2007-04-07
  • 打赏
  • 举报
回复
// C显示 bmp 格式的图片
void vesa_show_bmp_picture( unsigned int x , unsigned int y , void *bmp_addr , unsigned short mask_color , int dose_use_mask_color )
{
// 这里只支持 windows 标准 16 位 bmp 格式图片,(1:5:5:5)
struct bmp_bmp_head_struct *bmp_head = ( struct bmp_bmp_head_struct * )bmp_addr ;
int width = bmp_head->info_head.width ; // 获得图片的宽度
int height = bmp_head->info_head.height ; // 获得图片的高度

// 下面记算存储每个点的色彩的信息所在的位置
unsigned short *color = ( unsigned short * )( ( unsigned int )bmp_addr + bmp_head->offset ) ;

// 由于一行的字节数比须是 4 的倍数,因此,这里先计算每行需要的填充数,除 2 是因为每个像素两个字节
int fill_length = width * 2 % 4 / 2 ;

// bmp 的存放顺序是从下到上,从左到右
for( int i = height - 1 ; i >= 0 ; --i ){
for( int j = 0 ; j < width ; ++j ){
// 取得每个点的色彩信息
// 由于 windows 默认的是 555 格式,而 pyos 用的是 565 格式,因此先进行一下转换
unsigned short temp_color = vesa_change_color_form_555_to_565( *color ) ;
if( !dose_use_mask_color || temp_color != mask_color ){
// 画出每个点
vesa_draw_point( x + j , y + i , temp_color ) ;
}
++color ;
}
// 填充
color += fill_length ;
}
}

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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