Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
How to convert this raw data into jpeg file through c# code.

Thanks & Regards
Shweta
Posted
Comments
[no name] 14-Jun-14 15:01pm    
http://www.google.com/search?q=How+to+convert+RAW+file+into+JPEG+file+c%23
ShwetaSaxena 14-Jun-14 15:33pm    
I googled it several times but unable to get the correct answer.. Kindly help.
[no name] 14-Jun-14 15:49pm    
Help with what exactly? You have not asked any kind of a question, nor have you described any kind of a problem. What effort have you made? Where is the code that you have written that demonstrates a problem? Any kind of a problem? What were those problems? I find it very hard to believe that you went through 90000+ pages and found nothing at all that helped you even the least bit.
ShwetaSaxena 19-Jun-14 13:45pm    
I wrote this code to save the image in .raw format...

// Save to Raw
string strFileName = ConvertStringAnsi(DeviceInfo.pcDeviceName, 260);
strFileName += ".raw";
FileStream vFileStream = new FileStream(strFileName, FileMode.Create);
BinaryWriter vBinaryWriter = new BinaryWriter(vFileStream);
for (int vIndex = 0; vIndex < nFileSize; vIndex++)
{
vBinaryWriter.Write((byte)pImageFile[vIndex]);
}
vBinaryWriter.Close();
vFileStream.Close();
// Save to Raw
ShwetaSaxena 19-Jun-14 13:46pm    
and it works fine. But now i am having problem in saving it in .jpg format

One idea
Raw bytes -> Stream -> Bitmap -> Save to JPEG file

C#
MemoryStream stream = new MemoryStream();
stream.Write(rawdata);
Bitmap bm = new Bitmap(stream);
bm.Save("C:\example.jpg", System.Drawing.Imaging.ImageFormat.JPEG);
 
Share this answer
 
Comments
ShwetaSaxena 19-Jun-14 13:41pm    
It is generating an error

No overload for method 'Write' takes 1 arguments
ShwetaSaxena 19-Jun-14 13:53pm    
I write stream.Write(pImageFile, 0, nFileSize);
instead of stream.Write(rawdata);

Now Bitmap bm = new Bitmap(stream); is giving an Exception that 'Parameter is not valid'
There is no such thing as a common raw format! All those "raw formats" are vendor-specific. You have to use the SDK of that vendor. There you ought to find methods for handling the image.
 
Share this answer
 
I think you can't do it without an external library,as Solution 2 indicates. But have a look at this,maybe could help imagemagick
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900