Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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;
Thanks
Posted 25-Jan-13 5:42am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I searched CodeProject Articles with this text
Quote:
windows forms picture box byte array
and found this this[^]
  Permalink  
Rate this: bad
good
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 vb.net 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:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx[^].
 
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:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^].
 
—SA
  Permalink  

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

  Print Answers RSS
0 DamithSL 285
1 Zoltán Zörgő 170
2 OriginalGriff 140
3 BillWoodruff 125
4 Sergey Alexandrovich Kryukov 120
0 OriginalGriff 7,740
1 DamithSL 5,769
2 Sergey Alexandrovich Kryukov 5,424
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2014
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