473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(da ta);
MetaFile metaFile = new MetaFile(memory Stream);

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(da ta);
Image image = Image.FromStrea m(memoryStream) ;

This time I have an ArgumentExcepti on. 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 10338
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:
BITMAPFILEHEADE R
BITMAPINFOHEADE R
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.comwro te in message
news:eH******** *******@TK2MSFT NGP03.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(da ta);
MetaFile metaFile = new MetaFile(memory Stream);

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(da ta);
Image image = Image.FromStrea m(memoryStream) ;

This time I have an ArgumentExcepti on. 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*********@no spam.jun0.c0ma écrit dans le
message de news: eI************* ***@TK2MSFTNGP0 3.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:
BITMAPFILEHEADE R
BITMAPINFOHEADE R
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.comwro te in message
news:eH******** *******@TK2MSFT NGP03.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(da ta);
MetaFile metaFile = new MetaFile(memory Stream);

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(da ta);
Image image = Image.FromStrea m(memoryStream) ;

This time I have an ArgumentExcepti on. 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
4803
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 h = lImage.GetHenhmetafile(); lImage.Dispose(); lImage.GetLifetimeService(); lImage = null;
1
3927
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 which is present in a Picture box. Any ideas to do this? Thanks senthil
3
417
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, EmfType.EmfOnly); grph.ReleaseHdc(ipHDC); grph.Dispose(); grph = Graphics.FromImage(mf); grph.DrawRectangle(aPen, 10, 10, 100, 120); grph.Dispose();
4
2494
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 CF_ENHMETAFILE As Integer = 14 objDoc = objWord.Documents.Open("C:\TEST\Test1.doc") objWord.ActiveDocument.Select() objWord.Selection.CopyAsPicture() Dim ip As IntPtr
0
1792
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 resolution as those properties of my metafile object are read only and are in fact null until the graphics object is disposed of and the file is saved. When I examine the saved file's properties in Windows Explorer, it has 81 dpi horizontal and...
2
1724
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 = OpenClipboard(Me.Handle)
3
4611
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 artical http://www.thescripts.com/forum/thread356836.html but hasnt workfor me Const CF_ENHMETAFILE As Integer = 14 Dim henmetafile As IntPtr Dim metaFile As...
2
2546
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 * g.DpiX ....
1
3631
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. It appears as a metafile type but isn't recognized as an image. Given: DataObject copyObject; copyObject = (DataObject)Clipboard.GetDataObject(); string types = copyObject.GetFormats();
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.