By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,553 Members | 1,542 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,553 IT Pros & Developers. It's quick & easy.

Image scaling problem

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Larry Serflaten" <se*******@usinternet.com> wrote

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


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)


Nov 21 '05 #2

P: n/a
Larry,

"Larry Serflaten" <se*******@usinternet.com> schrieb:
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...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote
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...

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
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.