Image scaling problem

  • Thread starter Larry Serflaten
  • Start date
L

Larry Serflaten

I am taking a 256 color bitmap from a file
and scaling it up X 16 to a 32bppPARGB bitmap
in memory. I copy that image to the screen.

After scaling, the edges of all the lines and
colors are blurred. I want the edges all
crisp, including inherent pixelation (jaggies).

Setting smoothing to none, or adjusting the
composting mode on the Graphics object still
yields blurred edges. What do I need to do
to the scale up the image, pixel for pixel?

The bitmaps are created like:

Maps = DirectCast(Bitmap.FromFile("..\images\maps.bmp"), Bitmap)
LargeMap = New Bitmap(MapSize.Width * 16 + 4, MapSize.Height * 16 + 4, Imaging.PixelFormat.Format32bppPArgb)


Then later;

Dim grx As Graphics = Graphics.FromImage(LargeMap)

grx.Clear(Color.DarkGreen)
grx.SmoothingMode = Drawing2D.SmoothingMode.None
grx.CompositingMode = Drawing2D.CompositingMode.SourceCopy

grx.DrawImage(Maps, New Rectangle(0, 0, MapSize.Width * 16, MapSize.Height * 16), _
New Rectangle(0, Index * MapSize.Height, MapSize.Width, MapSize.Height), _
GraphicsUnit.Pixel)


The image should be scaled there, and is later copied to the screen:

Dim grx As Graphics = Me.CreateGraphics

grx.SmoothingMode = Drawing2D.SmoothingMode.None
grx.DrawImage(LargeMap, New Rectangle(10, 40, 400, 400), New Rectangle(80, 80, 400, 400), GraphicsUnit.Pixel)


What I see on the screen is blurred, but I suspect I need to address the
problem during the scaling process.

Any/all help will be appreciated....
LFS
 
L

Larry Serflaten

I found it! It was the Nearest-Neighbor interpolation mode I needed....
Setting smoothing to none, or adjusting the
composting mode on the Graphics object still
yields blurred edges. What do I need to do
to the scale up the image, pixel for pixel?


grx.Clear(Color.DarkGreen)
grx.SmoothingMode = Drawing2D.SmoothingMode.None



grx.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
 
H

Herfried K. Wagner [MVP]

Larry,

Larry Serflaten said:
Dim grx As Graphics = Me.CreateGraphics

grx.SmoothingMode = Drawing2D.SmoothingMode.None
grx.DrawImage(LargeMap, New Rectangle(10, 40, 400, 400), New
Rectangle(80, 80, 400, 400), GraphicsUnit.Pixel)

Just to make sure you don't forget to do that: The 'Graphics' objects in
the snippets you provided "should" be disposed...
 
L

Larry Serflaten

Herfried K. Wagner said:
Just to make sure you don't forget to do that: The 'Graphics' objects in
the snippets you provided "should" be disposed...


Thanks for the reminder. Those were 'snippets' and not full examples of
working code. I still had other uses for that object that were not pertinant
to the discussion, and that code did not get included...

;-)
LFS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top