By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Pixels(really important)

P: 1
I have an array of int pixels in my c# program and i want to convert it into an image. The problem is i am converting java source code for a program into equivalent c# code. In java the line reads which displays the array of int pixels into image.

Image output = createImage(new MemoryImageSource(width, height, orig, 0, width));

can someone tell me the c# equivalent? Here orig is the array of int pixels. I searched the Bitmap class and there is a method called SetPixel but the problem is it takes a x , y coordinate number. But what i have in my code is an array of int pixels. Another weird thing is my orig array has negative number and they are way far away from 255. In java this is teh same case(meaning both the array in c# and java have equivalent value) and the values is workign fine in java.
But i cant get that line translated in c#. Please help .
Thank you
Dec 24 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 190
Unless someone posts a better suggestion, I would say you will have to loop thru the source array and set each pixel using the Bitmap.SetPixel method.

There is also the Bitmap.Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr) Constructor where IntPtr is a pointer to an array of bytes holding the pixel data.
Dec 26 '08 #2

Expert 100+
P: 750
try this
Expand|Select|Wrap|Line Numbers
  1. Bitmap my = new Bitmap(@"C:\Bernese Oberland.jpg");
  3.             MemoryStream ms = new MemoryStream();
  4.             my.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  5. // ms=new new MemoryStream(yourByteArray);
  7.             pictureBox1.Image= Image.FromStream(ms);
check Image.FromStream Method (Stream)
Dec 26 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.