Pixels(really important)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • n3ts3cur3
    New Member
    • Dec 2008
    • 1

    Pixels(really important)

    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 MemoryImageSour ce(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
  • mldisibio
    Recognized Expert New Member
    • Sep 2008
    • 191

    #2
    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(I nt32, Int32, Int32, PixelFormat, IntPtr) Constructor where IntPtr is a pointer to an array of bytes holding the pixel data.

    Comment

    • PRR
      Recognized Expert Contributor
      • Dec 2007
      • 750

      #3
      Originally posted by n3ts3cur3
      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 MemoryImageSour ce(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
      try this
      Code:
      Bitmap my = new Bitmap(@"C:\Bernese Oberland.jpg");
      
                  MemoryStream ms = new MemoryStream();
                  my.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
      // ms=new new MemoryStream(yourByteArray);
      
                  pictureBox1.Image= Image.FromStream(ms);
      check Image.FromStrea m Method (Stream)

      Comment

      Working...