Click here to Skip to main content
12,997,914 members (57,147 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi. I have some pixels in an byte array.
I want create a bitmap ( or sth else) with these pixels to show in a picture box;
I don't want use wpf application . I want use windows form application;
Please help me;
Posted 25-Jan-13 4:42am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I searched CodeProject Articles with this text
windows forms picture box byte array
and found this this[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

First of all, don't use PictureBox for such purpose. Even though you can, it won't help you at all, will only add some hassles and eat up a bit of extra resources, giving nothing in return. This control in nothing but a shortcut for very simple cases. You need to draw immediately on some control (a custom one derived from System.Windows.Forms.Control, Panel or the like). I'll explain how:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

See also these past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my application?[^].

Now when it's clear, you have a choice: you can draw your pixels immediately in OnPaint (please see below), or you might need to do it on Bitmap. You can even make both in the same method. You only need to abstract out the instance of System.Drawing.Graphics, make it a parameter of drawing function. You will take it parameter from event args, in case of OnPaint, of from bitmap — this way:[^].

Now, the problem could be performance. If you really need to draw the image pixel-by-pixel using SetPixel, and there are many pixels, it will be prohibitively slow, don't do it! In this case, always use bitmap. The only fast way is using System.Drawing.Bitmap.LockBits:[^].


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100