DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 28 Jun 2007 02:39:21 -0700,    posted on: microsoft.public.dotnet.framework.drawing        back       

Thread Index
  1    Sergei Shelukhin
          2    Blake no@email


resizing image defect - strange border appears   
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?
Date:Thu, 28 Jun 2007 02:39:21 -0700   Author:  

Re: resizing image defect - strange border appears   
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"  wrote in message 
news:1183023561.338202.190190@n60g2000hse.googlegroups.com...

> 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?
> 
Date:Thu, 28 Jun 2007 21:21:00 +1000   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us