Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DrawImage without interpolation

Posted on 2014-02-15
5
Medium Priority
?
403 Views
Last Modified: 2014-03-03
So, I'm working on a sort-of image manipulation program in .NET, and I'm trying to draw an image to the screen, and when you mouse wheel you zoom into the image to view individual pixels (similar to microsoft paint, etc).

I'm using the code

pe.Graphics.DrawImage(m_Bitmap, draw_rect)

in the form OnPaint method to do this.

However, I noticed I was getting smoothing when I zoomed in, and the pixels were looking blurry.  I found on another topic that I could set the "InterpolationMode" and adjust the smoothing method to get the "blocky" pixels I wanted, the other article said "NearestNeighbor" would do it.

However this isn't quite right... it is shifting the first pixel for some reason.  See the attached image.  Also see the original bitmap in microsoft paint,  Each row is supposed to be two pixels wide, and the "Nearestneighbor" interpolation seems to halve the first row and column of pixels.

Is there a way to turn interpolation off altogether?   I'm trying to find a way to not iterate through each pixel and draw the individual squares...

Thanks for any thoughts.
shifted.png
paint.png
0
Comment
Question by:RonMexico
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 39862247
Hi RonMexico;

Using NearestNeighbor Will produce an image of lower quality. To get the best image quality use HighQualityBicubic. InterpolationMode must be set to a value. Be advised that the higher the quality, InterpolationMode, the longer it takes to process the image.
0
 

Author Comment

by:RonMexico
ID: 39862266
Sorry, probably wasn't clear:

I actually don't want smoothing/interpolation at all.  I want to zoom in and examine pixels and have them look like perfect squares that can be clicked on.  (I'm creating an image manipulation program.)

When I use NearestNeighbor my first row and columns are halved, as shown in the first attached picture.  What I want is behavior like in MS Paint, such as in the second attached picture.
0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 1500 total points
ID: 39862751
Hi RonMexico;

The InterpolationMode enumeration specifies the algorithm that is used when images are scaled or rotated.. It must be set to one of the enumeration values. The only enumeration that may not do any interpolation may be the Default setting, it does not say specifically what it does.

There is another property that handles smoothing and that is SmoothingMode. If you do not what smoothing set the SmoothingMode property to Drawing2D.SmoothingMode.None
0
 

Accepted Solution

by:
RonMexico earned 0 total points
ID: 39863040
Default performs interpolation, unfortunately.

And the SmoothingMode doesn't seem to affect DrawImage (it seems to only affect GDI drawing commands such as DrawLine).

This is starting to appear like a bug, or at least an oversight in .NET.
0
 

Author Closing Comment

by:RonMexico
ID: 39900012
Seems to me at this point that this is design behavior, although it *ought* to behave like I suggest.  Awarding Fernando the points for the insight but the answer ought to lead to my comment I think.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question