Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

resizing image defect - strange border appears

179 views
Skip to first unread message

Sergei Shelukhin

unread,
Jun 28, 2007, 5:39:21 AM6/28/07
to
Hi. I am implementing a code that takes an image of arbitrary size,
then crops it to proprotion and resizes the result to some set
thumbnail size.
The problem is, when the image is resized there's a visible darker
border along its edges (usually top and left), 1px wide, that is often
perceived as black border when the image is shown (even though the
border is actullay psrt of the image if you zoom in except that all
pixels are sufficiently darker).

Image are photographs and have no borders that could potentially be
exaggerated by decreasing size; I use bicubic interpolation and smooth
and high-quality everything.

Thus far, I wrote a code that makes an image 2px wider and higher than
required and then trims 1px from all sides.
Is there any better way to get rid of this bug border? Why does it
appear?

Blake

unread,
Jun 28, 2007, 7:21:00 AM6/28/07
to
Hi Sergei,

This problem is occuring because you are interpolating your image data to a
new size, but along the edges there are no pixels to interpolate and .NET
uses black pixels for these edges by default. To fix this you need to use an
ImageAttributes class in your DrawImage call....

Dim targetBitmap as new bitmap("...")
Dim sourceBitmap as new bitmap("...")

Using g As Graphics = Graphics.FromImage(targetBitmap)
sourceBitmap.SetResolution(g.DpiY, g.DpiY)
g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
Using ia As New ImageAttributes
' THE FOLLOWING LINES ENSURES GDI+ USES
' THE RIGHT PIXELS WHEN INTERPOLATING NEAR EDGES
ia.SetWrapMode(Drawing2D.WrapMode.TileFlipXY)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(sourceBitmap , New Rectangle(0, 0, width, height), 0, 0,
targetBitmap.Width, targetBitmap.Height, GraphicsUnit.Pixel, ia)
End Using
End Using


No more dark or edges when resizing.

Hope this helps.

-Blake


"Sergei Shelukhin" <real...@gmail.com> wrote in message
news:1183023561.3...@n60g2000hse.googlegroups.com...

0 new messages