Link to home
Start Free TrialLog in
Avatar of Sindibad_123
Sindibad_123

asked on

to convert raw byte array(its not actual image) to Bitmap image?

Hi, I need to convert raw  byte array(its not actual image) to image?

Regards.
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Load the byte array into a memorystream, then just load the image from the memorystream

     MemoryStream ms = new MemoryStream(imgData);
     Image img = Image.FromStream(ms);

Open in new window

please shed more light on "its not actual image" if the above does nto work.
Avatar of Sindibad_123
Sindibad_123

ASKER

I mean, it is just a buffer of raw pixel data, and not a complete image file so  MemoryStream will not work.
I think the asker of this question: http://social.msdn.microsoft.com/Forums/en-SG/clr/thread/220095e4-0150-4c23-a613-7276494290 did it but he did not put the all code, do someone have a such code?
link seems to be invalid
also sounds like you just talking about a bitmap
     MemoryStream ms = new MemoryStream(BitmapData);
     return (new Bitmap(ms));

Open in new window

CodeCruiser I tried the function that suggested in that link:

 public Bitmap CopyDataToBitmap(byte[] data)
        {
            Bitmap bmp = new Bitmap( 900, 600, PixelFormat.Format16bppRgb565);
                       BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
           
            Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
            //set the beginning of pixel data

            bmp.UnlockBits(bmpData);
            return bmp;
        }

but the image got displayed as a black image, any suggestion?
Make sure you are using the correct format and depth.
How can I know what's the correct format & depth?
Where is the raw data coming from? You need to confirm from the source.
Actually the data is a web page request that come as stream.
A web page request? Not sure I understand.
Something like this:
HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
 System.Net.HttpWebResponse httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();

System.IO.Stream stream = httpWebResponse.GetResponseStream();
 byte[] imageData  = ConverToByteArray(stream, 32768);

I want to take a screenshot without using thirdparty app.
Ah. So you want to convert HTML to pixels? :-)
We do not want to use WebBrowser control.
SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial