使用 GDIPlus 调整大小模糊顶部边缘

发布于 2024-08-17 08:10:39 字数 745 浏览 2 评论 0原文

我正在使用以下代码来使用 C 中的 GDI+ 调整位图大小。即使对于该区域应该为白色的图像,我也获得了顶部边缘的灰度值。当插值是最近邻时,问题就消失了。但是,我尝试使用 ImageMagick 进行双三次插值,看起来不错。我应该知道什么限制问题吗?我的缩放方法是否错误?谢谢!

(输入: destSize : 目标 Gdiplus::Size m_pBitmap :源位图)

Rect destRect(Point(0,0), destSize);
Bitmap *pBitmap24BPP =  new Bitmap(destSize.Width, destSize.Height, PixelFormat24bppRGB);
pBitmap24BPP->SetResolution(m_pBitmap->GetHorizontalResolution(), m_pBitmap->GetVerticalResolution());  
Graphics *pGraphics = Graphics::FromImage(pBitmap24BPP);
pGraphics->SetInterpolationMode(InterpolationModeHighQualityBilinear);
pGraphics->DrawImage(m_pBitmap, destRect, 0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight()   , UnitPixel, NULL);

//cleanup

I'm using the following code to resize a bitmap using GDI+ in C. I'm getting gray values for the top edge even for images where that area should be white. The problem disappears when the interpolation is nearest neighbor. However, I tried bicubic interpolation with ImageMagick and it seems fine. Any limitations problems I should know of? Is my method of scaling wrong somehow? Thanks!

(inputs:
destSize : destination Gdiplus::Size
m_pBitmap : source bitmap)

Rect destRect(Point(0,0), destSize);
Bitmap *pBitmap24BPP =  new Bitmap(destSize.Width, destSize.Height, PixelFormat24bppRGB);
pBitmap24BPP->SetResolution(m_pBitmap->GetHorizontalResolution(), m_pBitmap->GetVerticalResolution());  
Graphics *pGraphics = Graphics::FromImage(pBitmap24BPP);
pGraphics->SetInterpolationMode(InterpolationModeHighQualityBilinear);
pGraphics->DrawImage(m_pBitmap, destRect, 0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight()   , UnitPixel, NULL);

//cleanup

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长亭外,古道边 2024-08-24 08:10:39

我也见过类似的事情。我没有时间研究它,但我有一种感觉,这是因为 GDI+ 图像缩放器错误地使用了“离开顶部边缘”的像素值,这将全部为零 - 使其变黑。

正确的图像调整大小应该识别出您已经到达图像的边缘,并进行适当的处​​理。

i've been seeing similar things. i've not had time to research it, but i have a feeling it is because the GDI+ image resizer is mistakenly using pixels values "off the top edge", which would be all zero - making it black.

Proper image resizing should recognize that you've reached the edge of the image, and handle it appropriately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文