.NET Framework - I need to zoom a bitmap with no interpolation

Asked By Jeff Johnson
23-May-07 11:20 PM
I'm making a small Paint-like program and when I zoom in I want to see each
individual pixel as its own block of solid color. Everything I've tried with
the Graphics methods has resulted in smoothed images, even if I use
InterpolationMode.Low. Is there any way to get .NET to do this for me or am
I going to have to walk through every pixel and paint my own rectangles?
PixelFormat
(1)
SetPixel
(1)
DrawImage
(1)
Color
(1)
Dispose
(1)
Paint
(1)
  Michael C replied...
24-May-07 08:54 AM
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;

Second line is optional
  Michael C replied...
24-May-07 08:57 AM
BTW, here's the complete code I use to test the different enum values. Paste
this into a form and run and you will get a very clear idea of what each of
the enums does.

protected override void OnPaint(PaintEventArgs e)
{
Bitmap bitmap = new Bitmap(2, 2, PixelFormat.Format24bppRgb);
bitmap.SetPixel(0, 0, Color.Red);
bitmap.SetPixel(0, 1, Color.Green);
bitmap.SetPixel(1, 0, Color.Blue);
bitmap.SetPixel(1, 1, Color.Orange);
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.DrawImage(bitmap, this.ClientRectangle);
bitmap.Dispose();
}
  Jeff Johnson replied...
24-May-07 05:32 PM
Wow, I feel like a lazy bum now. A simple search on "nearest neighbor
interpolation" gave me the exact answer (as did you). Thanks for the
pointer!
help
ReaderWriterLockSlim + Dispose? .NET Framework One last question today :) Most locks I've used never had a Dispose (Monitor, ReaderWriterLock, etc). Looking at the ReaderWriterLockSlim's Dispose method its just cleaning up some Threading.WaitHandle's. Whenever I see a Dispose method I always want to call it after I'm done with the object. All examples I've ever found online don't use dispose with the ReaderWriterLockSlim. Making my classes that use this lock IDisposable for this reasion alone ReaderWriterLockSlim? Is there performance increases in using the disposable WaitHandles vs how other locks without Dispose() do it? Thanks :) I'm mostly just curious. NB C# Discussions ThreadPool.QueueUserWorkItem (1) ReaderWriterLockSlim.Dispose (1) RWLS.Aquire (1) System.Collections.Generic (1) ObjectDisposedException (1) QueueUserWorkItem (1) ReaderWriterLock (1) AutoResetEvent that implement IDisposable, they "just" clean up some things. Are you implying that the ReaderWriterLockSlim.Dispose() is less important than for other classes that implement IDisposable? Yes. Do you mean that
I'm accessing a shared member through an instance variable (the Private Sub X(ByVal color As Color) Me.BackColor = color.AliceBlue End Sub On *some* computers this produces the expected warning. On others it does to fail to complain? TIA - Bob VB.NET Discussions Visual Studio 2005 (1) System.Drawing.Color (1) Color.FromName (1) DateTime (1) VB (1) Drawing.Color (1) FromBinary (1) FromName (1) Vb.net is not case sensitive, so in general, having a variable called color could be bad. Change the parameter to colorparam and then the line to Me.BackColor a variable to it - - your code is not doing that, it is associating a variable (color) to represent a static type. But, when you write color.AliceBlue, the compiler doesn't
when to dispose a datatable? .NET Framework I have a list box on my form, but I need Public Class MyForm priate m_MyTable as new datatable End Class now where would I properly dispose of this? In the finalize method? I am loading the data for the table in its life time to be that of the form. . thanks! ADO.NET Discussions GC (1) Dispose (1) SQL Server (1) ASP.NET (1) MarshalByValueComponent (1) IIS (1) SharePoint (1) DataTable (1) Dispose it when you do not need table anymore. You can do that in FormClosing or in form Dispose if you implement it HTH Just a note that you don't actually need to dispose datatable, but it is a good practice. And yes, dispose it when you are done with it (form's dispose might be a good place if you can't dispose it earlier) - - Miha Markic [MVP
that region here. Indicate which line you added / changed to try to change the background color. protected void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InvoiceForm)); this.textBox17 SuspendLayout(); this.panel7.SuspendLayout(); this.panel6.SuspendLayout(); this.SuspendLayout(); / / / / textBox17 / / this.textBox17.BackColor = System.Drawing.Color.GhostWhite; this.textBox17.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.textBox17.Location = new System.Drawing textBox17.KeyPress + = new System.Windows.Forms.KeyPressEventHandler(this.keypressed17); / / / / textBox15 / / this.textBox15.BackColor = System.Drawing.Color.GhostWhite; this.textBox15.BorderStyle = System.Windows.Forms.BorderStyle.None; this.textBox15.Location = new System.Drawing System.Drawing.Size(576, 124); this.textBox15.TabIndex = 0; / / / / textBox7 / / this.textBox7.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(219)))), ((int)(((byte)(219)))), ((int)(((byte)(200))))); this.textBox7.BorderStyle = System.Windows System.Drawing.Size(156, 20); this.textBox7.TabIndex = 5; / / / / textBox6 / / this.textBox6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(219)))), ((int)(((byte)(219)))), ((int)(((byte)(200))))); this.textBox6.BorderStyle = System.Windows System.Drawing.Size(176, 20); this.textBox6.TabIndex = 12; / / / / textBox5 / / this.textBox5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(219)))), ((int)(((byte)(219)))), ((int)(((byte)(200))))); this.textBox5.BorderStyle = System.Windows System.Drawing.Size(176, 20); this.textBox5.TabIndex = 11; / / / / textBox4 / / this.textBox4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(219)))), ((int)(((byte)(219)))), ((int)(((byte)(200))))); this.textBox4.BorderStyle = System.Windows System.Drawing.Size(176, 20); this.textBox4.TabIndex = 10; / / / / textBox3 / / this.textBox3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(219)))), ((int)(((byte)(219)))), ((int)(((byte)(200))))); this.textBox3.BorderStyle = System.Windows
CHEAP TEXTBOOKS microsoft.public.dotnet.framework.aspnet .NET Framework [CENTER][SIZE = "6"][COLOR = "Red"][B]BUY CHEAP TEXTBOOKS at [URL = "http: / / cheap-textbooks.oq.pl"]www.CHEAP-TEXTBOOKS.oq.pl[ / URL][ / B] [ / COLOR][ / SIZE] [SIZE = "4"][COLOR = "Green"][B]Compare prices on over 9 million new and Used textbooks in one convenient location. We've already helped people save millions of dollars.[ / B][ / COLOR][ / SIZE] [SIZE = "5"][COLOR = "Red"][B]Find the Lowest Prices Online at Our Catalog - [URL = "http: / / cheap-textbooks.oq.pl"]CLICK HERE TO VIEW[ / URL]! Use code: "3160229101" to get 50% discount![ / B][ / COLOR][ / SIZE] [B]Today's top searches: [ / B] ASP.NET Discussions Ex4dnHYARbk (1) SuztZvIlaoI (1) Choose Enter (1) SIZE (1) Online (1) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN (1) D000000000000000000000fjd (1) g - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [CENTER][SIZE = 3D"7"][COLOR = 3D"Red"][B]BUY CHEAP TEXTBOOKS at [URL = 3D"http: / / cheap-textbooks.oq.pl"]www.CHEAP-TEXTBOOKS.oq.pl[ / URL][ / B] [ / COLOR][ / SIZE] [COLOR = 3D"Green"][SIZE = 3D"4"][B]Compare prices on over 9 million new