当前位置 :
急!在线等~~C++怎么把图象缩小或放大一倍?HDIBChangeDIBSize(HDIBhDIB,intnWidth,intnHeight){LPBITMAPINFOlpbmi=NULL;LPBYTElpSourceBits,lpTargetBits,lpResult;HDChDC=NULL,hSourceDC,hTargetDC;HBITMA
更新时间: 2025-08-29 07:59:13
1人问答
问题描述:

急!在线等~~C++怎么把图象缩小或放大一倍?

HDIBChangeDIBSize(HDIBhDIB,intnWidth,intnHeight)

{LPBITMAPINFOlpbmi=NULL;

LPBYTElpSourceBits,lpTargetBits,lpResult;

HDChDC=NULL,hSourceDC,hTargetDC;

HBITMAPhSourceBitmap,hTargetBitmap,hOldTargetBitmap,hOldSourceBitmap;

DWORDdwSourceBitsSize,dwTargetBitsSize,dwTargetHeaderSize;

HDIBhNewDIB;

DWORDdwSize;

WaitCursorBegin()

if(!hDIB)

{WaitCursorEnd();

returnNULL;}

LPBITMAPINFOlpSrcDIB=(LPBITMAPINFO)GlobalLock(hDIB);

if(!lpSrcDIB)

{WaitCursorEnd();

returnNULL;}

dwTargetHeaderSize=sizeof(BITMAPINFOHEADER)+PaletteSize(lpSrcDIB);

lpbmi=(LPBITMAPINFO)malloc(dwTargetHeaderSize);

memcpy(lpbmi,lpSrcDIB,dwTargetHeaderSize);

lpbmi->bmiHeader.biWidth=nWidth;

lpbmi->bmiHeader.biHeight=nHeight;

hDC=GetDC(NULL);

hTargetBitmap=CreateDIBSection(hDC,lpbmi,DIB_RGB_COLORS,(VOID**)&lpTargetBits,NULL,0);

hSourceBitmap=CreateDIBSection(hDC,lpSrcDIB,DIB_RGB_COLORS,(VOID**)&lpSourceBits,NULL,0);

hSourceDC=CreateCompatibleDC(hDC);

hTargetDC=CreateCompatibleDC(hDC);

dwSourceBitsSize=lpSrcDIB->bmiHeader.biHeight*BytesPerLine((LPBYTE)&(lpSrcDIB->bmiHeader));

dwTargetBitsSize=lpbmi->bmiHeader.biHeight*BytesPerLine((LPBYTE)&(lpbmi->bmiHeader));

memcpy(lpSourceBits,FindDIBBits((LPBYTE)lpSrcDIB),dwSourceBitsSize);

lpbmi->bmiHeader.biSizeImage=dwTargetBitsSize;

hOldSourceBitmap=(HBITMAP)SelectObject(hSourceDC,hSourceBitmap);

hOldTargetBitmap=(HBITMAP)SelectObject(hTargetDC,hTargetBitmap);

SetStretchBltMode(hTargetDC,COLORONCOLOR);

StretchBlt(hTargetDC,0,0,lpbmi->bmiHeader.biWidth,lpbmi->bmiHeader.biHeight,hSourceDC,0,0,lpSrcDIB->bmiHeader.biWidth,lpSrcDIB->bmiHeader.biHeight,SRCCOPY);

SelectObject(hSourceDC,hOldSourceBitmap);

SelectObject(hTargetDC,hOldTar

马维英回答:
  HDIB是原始图像的句柄,nWidth和nHeight就是缩小或放大后的大小.直接调用就行.   WaitCursorBegin()   WaitCursorEnd();两句删掉;
最新更新
保卡通(baokatong.com)汇总了汉语字典,新华字典,成语字典,组词,词语,在线查字典,中文字典,英汉字典,在线字典,康熙字典等等,是学生查询学习资料的好帮手,是老师教学的好助手。
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
Copyright©2009-2021 保卡通 baokatong.com 版权所有