PC Review


Reply
Thread Tools Rate Thread

Converting RAW data to MetaFile

 
 
Laurent Navarro
Guest
Posts: n/a
 
      22nd Dec 2006
Hello,


I am using a library which returns a byte[] containing RAW data, ie all
pixels' color values coded in a byte array without header. I would like to
save those data into a JPEG file so I tried to use the MetaFile class.

byte[] data;
(...) // Creating the RAW image through the DLL call.
MemoryStream memoryStream = new MemoryStream(data);
MetaFile metaFile = new MetaFile(memoryStream);

Unfortunately, this code throws an exception which description is: "GDI+
encounters an internal error". I also tried this:

byte[] data;
(...) // Creating the RAW image through the DLL call.
MemoryStream memoryStream = new MemoryStream(data);
Image image = Image.FromStream(memoryStream);

This time I have an ArgumentException. I guess I can't use a stream
linking to RAW data as it is not an image with header. But then, how can I
make the MetaFile class read my data and convert them to JPEG file ???

Thank you !


Laurent


 
Reply With Quote
 
 
 
 
Michael Phillips, Jr.
Guest
Posts: n/a
 
      22nd Dec 2006
If you wish to save your raw data as a .jpeg file, you need to create a
bitmap from the raw bytes and then have the gdiplus encoder create a .jpeg
file for you.

1) Using your memory stream, create and populate in order:
BITMAPFILEHEADER
BITMAPINFOHEADER
palette(i.e., if raw data is indexed)
RAW bytes
2) You now have a correctly formatted bitmap that the gdiplus decoder will
create a bitmap from your memory stream.
3) Use the save method to save your bitmap as a .jpeg encoded file.


"Laurent Navarro" <(E-Mail Removed)> wrote in message
news:eH%(E-Mail Removed)...
> Hello,
>
>
> I am using a library which returns a byte[] containing RAW data, ie all
> pixels' color values coded in a byte array without header. I would like to
> save those data into a JPEG file so I tried to use the MetaFile class.
>
> byte[] data;
> (...) // Creating the RAW image through the DLL call.
> MemoryStream memoryStream = new MemoryStream(data);
> MetaFile metaFile = new MetaFile(memoryStream);
>
> Unfortunately, this code throws an exception which description is:
> "GDI+ encounters an internal error". I also tried this:
>
> byte[] data;
> (...) // Creating the RAW image through the DLL call.
> MemoryStream memoryStream = new MemoryStream(data);
> Image image = Image.FromStream(memoryStream);
>
> This time I have an ArgumentException. I guess I can't use a stream
> linking to RAW data as it is not an image with header. But then, how can I
> make the MetaFile class read my data and convert them to JPEG file ???
>
> Thank you !
>
>
> Laurent
>



 
Reply With Quote
 
Laurent Navarro
Guest
Posts: n/a
 
      27th Dec 2006
Hi Michel,


Thank you for your answer. I tried and it worked, but I had a bad
surprise: the GDI+ works in BGR and not RGB. So before saving my datas I had
to swap the R and B value for each pixel of my data.

Is there an easier way to make the Bitmap class work in RGB without
converting the image first ?

Thanks



"Michael Phillips, Jr." <(E-Mail Removed)0m> a écrit dans le
message de news: eI3%(E-Mail Removed)...
> If you wish to save your raw data as a .jpeg file, you need to create a
> bitmap from the raw bytes and then have the gdiplus encoder create a .jpeg
> file for you.
>
> 1) Using your memory stream, create and populate in order:
> BITMAPFILEHEADER
> BITMAPINFOHEADER
> palette(i.e., if raw data is indexed)
> RAW bytes
> 2) You now have a correctly formatted bitmap that the gdiplus decoder will
> create a bitmap from your memory stream.
> 3) Use the save method to save your bitmap as a .jpeg encoded file.
>
>
> "Laurent Navarro" <(E-Mail Removed)> wrote in message
> news:eH%(E-Mail Removed)...
>> Hello,
>>
>>
>> I am using a library which returns a byte[] containing RAW data, ie
>> all pixels' color values coded in a byte array without header. I would
>> like to save those data into a JPEG file so I tried to use the MetaFile
>> class.
>>
>> byte[] data;
>> (...) // Creating the RAW image through the DLL call.
>> MemoryStream memoryStream = new MemoryStream(data);
>> MetaFile metaFile = new MetaFile(memoryStream);
>>
>> Unfortunately, this code throws an exception which description is:
>> "GDI+ encounters an internal error". I also tried this:
>>
>> byte[] data;
>> (...) // Creating the RAW image through the DLL call.
>> MemoryStream memoryStream = new MemoryStream(data);
>> Image image = Image.FromStream(memoryStream);
>>
>> This time I have an ArgumentException. I guess I can't use a stream
>> linking to RAW data as it is not an image with header. But then, how can
>> I make the MetaFile class read my data and convert them to JPEG file ???
>>
>> Thank you !
>>
>>
>> Laurent
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
windows metafile vs enhanced metafile =?Utf-8?B?VG9t?= Microsoft Powerpoint 4 1st Jul 2005 01:41 AM
Problem converting OLE Metafile to Bitmap =?Utf-8?B?QnJldCBQaGlsbGlwcw==?= Microsoft Dot NET Framework 0 9th Dec 2004 03:19 PM
Font colours disappear when pasting to Powerpoint as Metafile/Enhanced metafile Dean Painter Microsoft Powerpoint 1 10th Apr 2004 03:28 AM
Font colours disappear when pasting to Powerpoint as Metafile/Enhanced metafile Dean Painter Microsoft Excel Discussion 0 7th Apr 2004 12:35 PM
converting to Windows metafile weirdness Tracy Microsoft Powerpoint 1 8th Dec 2003 10:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 AM.