前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >GDI+缩放拉伸旋转图片时出现黑边黑框等问题

GDI+缩放拉伸旋转图片时出现黑边黑框等问题

作者头像
大菊观
发布2021-03-05 11:22:48
1.4K0
发布2021-03-05 11:22:48
举报

之前用GDI+做图片旋转,发现图片旋转后会漂移,偏离原中心位置几个像素。

后来发现用GDI+的InterpolationModeHighQualityBicubic高质量模式去缩放或者拉伸图片时,可能会出现边缘少几个像素或者黑边问题。

解决方法:

代码语言:javascript
复制
Gdiplus::Bitmap dstBmp(nCW, nCH);

Gdiplus::Graphics gdip(&dstBmp);
gdip.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
gdip.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);

Gdiplus::ImageAttributes imgAttr;
imgAttr.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
Gdiplus::Rect rect(0, 0, nCW, nCH);
gdip.DrawImage(pSrcBmp, rect,0,0,pSrcBmp->GetWidth(),pSrcBmp->GetHeight(),Gdiplus::UnitPixel,&imgAttr);

通过设置SetInterpolationMode为InterpolationModeHighQualityBicubic,设置SetPixelOffsetMode为PixelOffsetModeHalf,设置ImageAttributes的SetWrapMode为WrapModeTileFlipXY,经过验证可以解决。

其实黑边问题如果对图像质量要求不那么高,可以设置SetInterpolationMode为InterpolationModeNearestNeighbor,设置SetPixelOffsetMode为PixelOffsetModeNone,应该也能解决。

主要参考:http://webserver2.tecgraf.puc-rio.br/~scuri/gdiplus/drawimage_scale_problem.html

https://blog.csdn.net/chi001/article/details/6076712?utm_medium=distribute.pc_relevant_bbs_down.none-task-blog-baidujs-2.nonecase&depth_1-utm_source=distribute.pc_relevant_bbs_down.none-task-blog-baidujs-2.nonecase

另一种思路放大缩小:https://blog.csdn.net/tianmuxia/article/details/38593349

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-03-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档