SetDIBitsToDevice和stretchBlt 函数显示JPG PNG图片

www2t 2009-10-31 11:29:11
MSDN代码
//
// pvJpgImage points to a buffer containing the JPEG image
// nJpgImageSize is the size of the buffer
// ulJpgWidth is the width of the JPEG image
// ulJpgHeight is the height of the JPEG image
//

//
// Check if CHECKJPEGFORMAT is supported (device has JPEG support)
// and use it to verify that device can handle the JPEG image.
//

ul = CHECKJPEGFORMAT;

if (
// Check if CHECKJPEGFORMAT exists:

(ExtEscape(hdc, QUERYESCSUPPORT,
sizeof(ul), &ul, 0, 0) > 0) &&

// Check if CHECKJPEGFORMAT executed without error:

(ExtEscape(hdc, CHECKJPEGFORMAT,
pvJpgImage, nJpgImageSize, sizeof(ul), &ul) > 0) &&

// Check status code returned by CHECKJPEGFORMAT:

(ul == 1)
)
{
//
// Initialize the BITMAPINFO.
//

memset(&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = ulJpgWidth;
bmi.bmiHeader.biHeight = -ulJpgHeight; // top-down image
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 0;
bmi.bmiHeader.biCompression = BI_JPEG;
bmi.bmiHeader.biSizeImage = nJpgImageSize;

//
// Do the SetDIBitsToDevice.
//

iRet = SetDIBitsToDevice(hdc,
ulDstX, ulDstY,
ulDstWidth, ulDstHeight,
0, 0,
0, ulJpgHeight,
pvJpgImage,
&bmi,
DIB_RGB_COLORS);

if (iRet == GDI_ERROR)
return FALSE;
}
else
{
//
// Decompress image into a DIB and call SetDIBitsToDevice
// with the DIB instead.
//
}

这里的 ulJpgHeight ulJpgWidth pvJpgImage nJpgImageSize 初值从哪里来 ul又是个什么类型
那位大哥能不能给详细解释一下
最好能给个完整的代码
...全文
239 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
crjwlaq 2011-03-04
  • 打赏
  • 举报
回复
vs2008 中使用 CImage

vc6使用ole吧
dzq138 2011-03-03
  • 打赏
  • 举报
回复
初值可以从IImage *pImage = NULL;中得动
先打开一个文件.


CFile file;
CFileException fe;
CString FileName ;
DWORD dwFileLength;
BYTE* pBuff;

FileName=L"\\Storage Card\\读取内存jpgg\\0-1-10.jpg";
if(0 == file.Open(FileName, CFile::modeRead | CFile::shareDenyWrite, &fe)) //打开文件
{
AfxMessageBox(L"打开文件失败");
return ;
}
dwFileLength = file.GetLength(); //取得文件总长度
pBuff=new BYTE[dwFileLength];
file.Seek(0 ,CFile::begin); //定位
file.Read((BYTE*)(pBuff) , dwFileLength); //读字节
file.Close();
IImagingFactory *pImgFactory = NULL;
IImage *pImage = NULL;
HRESULT hrCoInit;
HDC hdcCont=NULL,hdcMem=NULL;
ImageInfo pimageinfo;//= new sizeof(ImageInfo);
RECT rect;

hrCoInit=CoInitializeEx(NULL, COINIT_MULTITHREADED);
CoCreateInstance(CLSID_ImagingFactory,NULL,1,IID_IImagingFactory,(void**) &pImgFactory);
pImgFactory->CreateImageFromBuffer(pBuff,dwFileLength,BufferDisposalFlag::BufferDisposalFlagNone ,&pImage);
pImage->GetImageInfo( &pimageinfo);
rect.top =0;
rect.left =0;
rect.right =pimageinfo.Width ; //这里可以得到宽
rect.bottom =pimageinfo.Height ;//这里可以得到高

pImage->Draw(m_dcCompatible,&rect,NULL); //m_dcCompatible 是一个CDC....


fandh 2009-11-02
  • 打赏
  • 举报
回复
ul估计是UINT类型吧!
ulJpgHeight ulJpgWidth pvJpgImage nJpgImageSize 应该是你要显示的JPG的一些信息,高度、宽度等

19,468

社区成员

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

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