Re: DrawImage and NearestNeighbor bug?



Thanks a lot Bob!

I must say I find it difficult to find out which of the properties to set,
in order to create the effect that I have in mind. Not very intuitive imho.
Microsoft decided to set properties in the Graphics object instead of, for
instance, passing an options struct to the various draw methods. I can
understand this, but the two are inseparatable. At least the class reference
could assist here: the help on DrawImage could point to the properties that
affect the drawing. Same goes for all Graphics.Draw* and Graphics.Fill*
methods.


"Bob Powell [MVP]" wrote:

> Set your PixelOffsetMode to Half.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Ramuseco Limited .NET consulting
> http://www.ramuseco.com
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Jelle van der Beek" <JellevanderBeek@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> message news:6EC2A962-5B49-4E0A-8E00-363E0D505AF5@xxxxxxxxxxxxxxxx
> > Hi,
> >
> > I am drawing an image, stretched, with interpolation set to
> > NearestNeighbor.
> > I want to be able to count the pixels and all. There seems to be a bug in
> > the
> > scaling in this interpolation mode. I actually think it occurs in all
> > modes,
> > but it is best visible in this mode. Somebody else has already posted this
> > problem but now I have a very simple piece of code to reproduce it.
> >
> > I created a checkboard of 5x5 pixels and painted it in a panel. I stretch
> > the image exactly 10 times in x and y. So I take the bitmap width and
> > height
> > and multiply it by 10. You can see that the left column and top column are
> > scaled exactly half the width that they should be. This sounds like an
> > rounding error in the interpolation code to me, but maybe it's by design?
> >
> > If it is by design, can anybody tell me how to do this the right way? If
> > it's not, then consider this a bug-report ;).
> >
> > Here's the code. Create your own 5x5 checkerboard tiff.
> >
> > public partial class Form1 : Form
> > {
> > private Panel m_PaintPanel;
> >
> > public Form1()
> > {
> > InitializeComponent();
> > }
> >
> > private void InitializeComponent()
> > {
> > this.m_PaintPanel = new System.Windows.Forms.Panel();
> > this.SuspendLayout();
> > //
> > // m_PaintPanel
> > //
> > this.m_PaintPanel.Location = new System.Drawing.Point( 48,
> > 48 );
> > this.m_PaintPanel.Name = "m_PaintPanel";
> > this.m_PaintPanel.Size = new System.Drawing.Size( 156, 104 );
> > this.m_PaintPanel.TabIndex = 0;
> > this.m_PaintPanel.Paint += new
> > System.Windows.Forms.PaintEventHandler( this.panel1_Paint );
> > //
> > // Form1
> > //
> > this.ClientSize = new System.Drawing.Size( 292, 266 );
> > this.Controls.Add( this.m_PaintPanel );
> > this.Name = "Form1";
> > this.Load += new System.EventHandler( this.Form1_Load );
> > this.ResumeLayout( false );
> >
> > }
> >
> > private Bitmap m_Bitmap = null;
> >
> > private void Form1_Load( object sender, EventArgs e )
> > {
> > m_Bitmap = new Bitmap( @"..\..\test.tif" );
> > }
> >
> > private void panel1_Paint( object sender, PaintEventArgs e )
> > {
> > e.Graphics.InterpolationMode =
> > System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
> > e.Graphics.DrawImage( m_Bitmap, new Rectangle( 0, 0,
> > m_Bitmap.Width * 10, m_Bitmap.Height * 10 ) );
> > }
> > }
>
>
>
.



Relevant Pages

  • Re: DrawImage and NearestNeighbor bug?
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... > I am drawing an image, stretched, with interpolation set to ... > rounding error in the interpolation code to me, but maybe it's by design? ...
    (microsoft.public.dotnet.framework.drawing)
  • DrawImage and NearestNeighbor bug?
    ... I am drawing an image, stretched, with interpolation set to NearestNeighbor. ... I created a checkboard of 5x5 pixels and painted it in a panel. ... I stretch ... If it is by design, can anybody tell me how to do this the right way? ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Lets Review
    ... reason that can happen there ('ID is just evidence for design nothing ... Featured articles: ... Place in the Cosmos is Designed for Discovery (Regnery Publishing, ... Finally some statistics to conclusively support ID based purely on the ...
    (talk.origins)
  • Re: Video scaler for Spartan 3E?
    ... must be done in different "blocks" of the design (i.e. they use more ... instinct would be that linear interpolation will be NO problem at all ... Will check out the DSP books that you recommended too! ...
    (comp.arch.fpga)
  • Lets Review
    ... reason that can happen there ('ID is just evidence for design nothing ... Featured articles: ... Finally some statistics to conclusively support ID based purely on the ... of atheist scientists (not that ID has anything to do with God ...
    (talk.origins)

Quantcast