使用 GDIPlus 调整大小模糊顶部边缘
我正在使用以下代码来使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也见过类似的事情。我没有时间研究它,但我有一种感觉,这是因为 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.