C++ 可以调用的更改图片大小的SDK或者COM组件

wangxiaoyong 2009-05-17 02:57:25
小弟的C++程序需要用到的一个功能就是更改图片的大小,比如jpg,gif,bmp等图片格式,希望通过调用某些SDK或者动态链接库,可以使resize图片,有谁知道怎么实现吗?
...全文
172 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
使用StretchDIBits函数调整JPEG or PNG Image


Sizing a JPEG or PNG Image
The StretchDIBits function copies the color data for a rectangle of pixels in a DIB to the specified destination rectangle. If the destination rectangle is larger than the source rectangle, this function stretches the rows and columns of color data to fit the destination rectangle. If the destination rectangle is smaller than the source rectangle, StretchDIBits compresses the rows and columns by using the specified raster operation.

Windows 98/Me, Windows 2000/XP: StretchDIBits is extended to allow a JPEG or PNG image to be passed as the source image.

For example:

// 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,
nJpgImageSize, pvJpgImage, 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 StretchDIBits.
//

iRet = StretchDIBits(hdc,
// destination rectangle
ulDstX, ulDstY, ulDstWidth, ulDstHeight,
// source rectangle
0, 0, ulJpgWidth, ulJpgHeight,
pvJpgImage,
&bmi,
DIB_RGB_COLORS,
SRCCOPY);

if (iRet == GDI_ERROR)
return FALSE;
}
else
{
//
// Decompress image into a DIB and call StretchDIBits
// with the DIB instead.
//
}
liliangbao 2009-05-18
  • 打赏
  • 举报
回复
学习~
amossavez 2009-05-17
  • 打赏
  • 举报
回复
帮顶!!
星羽 2009-05-17
  • 打赏
  • 举报
回复
yuanhong2910 2009-05-17
  • 打赏
  • 举报
回复
如果是在Windows CE5.0以上的平台上可以使用IImage API

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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