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?
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...