473,228 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

Converting RAW data to MetaFile

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
Dec 22 '06 #1
2 10280
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" <yo*@yop.comwrote in message
news:eH***************@TK2MSFTNGP03.phx.gbl...
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

Dec 22 '06 #2
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." <mp*********@nospam.jun0.c0ma écrit dans le
message de news: eI****************@TK2MSFTNGP03.phx.gbl...
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" <yo*@yop.comwrote in message
news:eH***************@TK2MSFTNGP03.phx.gbl...
> 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


Dec 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Julian Ziersch | last post by:
This code causes a severe memory leak - the critical part is the call to GetHenhmetafile(). System.Drawing.Imaging.Metafile lImage = new System.Drawing.Imaging.Metafile("C:\\meta0.emf"); IntPtr...
1
by: sendhil | last post by:
hi, Iam doing some graphics programming with C#. I have to create a Windows MetaFile from a base64 encoded string. How do i create the file. I want to Overlay this Windows MetaFile on a image...
3
by: Richard Skopal | last post by:
In .NET Windows forms I can create a metafile using this code: Graphics grph = aControl.CreateGraphics(); IntPtr ipHDC = grph.GetHdc(); Metafile mf = new Metafile(aImgFilePath, ipHDC,...
4
by: mabosch | last post by:
I'm trying to convert a DOC to JPG it works in Windows Forms, but I run under asp.net the clipboard its empty, I'm doing Dim objWord As New Word.Application Dim objDoc As Word.Document Const...
0
by: weiruic | last post by:
I am trying to create a metafile (.emf) on the harddisk, write graphics from a graphics object to it, and then save it. I can do this successfully except I cannot set the horizontal and vertical...
2
by: NickP | last post by:
Hi there, I am obtaining a meta file from the clipboard via the following code Dim CF_ENHMETAFILE As Integer = 14 Dim cMFeImage As Imaging.Metafile Dim pIPrClipboard As IntPtr =...
3
by: atif283 | last post by:
Hi I m worki on clip board m trying to copy RTF data(Text+Image) both txt and image on clip board its only pasting text On Excel not the image can any one help me in this regard I m using your...
2
by: Alexander Gorbylev | last post by:
Hi! Let the size of vector is e.g. 3.5". I render the same vector on a printer & a screen on the same procedure: printDoc_BeginPrint(object sender, PrintEventArgs e) { .... vector.Width *...
1
by: bern11 | last post by:
I can get bitmaps from the clipboard, but how do I get Metafiles? The specific instance I am testing is copying a piece of Word clip-art into the clipboard and trying to read it in an application. ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.