How to display a bl...
 
Notifications
Clear all

How to display a block of a JPEG image c#?

6 Posts
3 Users
0 Reactions
663 Views
(@dalilasalam09)
New Member
Joined: 11 years ago
Posts: 3
Topic starter  

I have a set of blocks from a disk dump and one of those blocks is a JPEG block how can I display it in a picture box c# (I have all the compression information Huffman table, Quantization table …) ?


   
Quote
(@mscotgrove)
Prominent Member
Joined: 17 years ago
Posts: 940
 

Not easy. I assume you have a cluster, or run of sectors. I think the big problem is that there are not many fixed sizes in JPEG files so it is difficult to know where the data you have fits in with the start of the compressed data

Having said that, it is common to see fragmented files displaying two photos.

You may find that if you take a good JPEG (from the same source)and cut it short, and then append your unknown data, you may get an idea of what the data contains. This may not be a forensically secure answer, but it may be a very good start.


   
ReplyQuote
zoltandfw
(@zoltandfw)
Eminent Member
Joined: 13 years ago
Posts: 27
 

Just read the contents as a byte array and use the FromStream constructor. Don't worry about the internal structure, a byte array is all you need. If you have many chunks for the file, just keep appending until you reach the end of the chunks. The first chunk is the one that starts with FFD8FF … and the last one will end with FFD9. In between, you can use permutation of all the chunks and let the user decide which one to keep. ( If you have the MFT record, you can parse out the dataruns to reassemble the image properly. ) If the header is corrupted, then just read the file dimensions from the file header ( hopefully still intact ), create a new file with the same dimensions and use that header in your reconstructed image.

MemoryStream chunks = new MemoryStream();

using (Stream input_chunk = File.OpenRead(file_contains_chunks))
{
input_chunk.CopyTo(chunks);
}

chunks.Position = 0;
Image created = Image.FromStream(chunks, false, false);
pictureBox1.Image=created;


   
ReplyQuote
(@dalilasalam09)
New Member
Joined: 11 years ago
Posts: 3
Topic starter  

Hello, thanks for your answers ..
I want to know if it is necessary to decompress the block before displaying it ? And
If the file is fragmented ?
If I just have the block that represents the middle part of the image ?
If I have an overwritten JPEG file how to process in order to display the no overwritten part ?


   
ReplyQuote
zoltandfw
(@zoltandfw)
Eminent Member
Joined: 13 years ago
Posts: 27
 

That will be very difficult, but if you have the Huffman table, then you might be able to do it. So, it is not a C# challenge, but a methodology challenge to understand how Huffman table is constructed.

Look at this site and tutorial on how it works and see if that will give with ideas for your project.

You will need to identify all the missing MCUs and add the missing MCUs with a single color value to show missing areas.

http//www.impulseadventure.com/photo/jpeg-huffman-coding.html

Good luck and let us know what you'll come up with.


   
ReplyQuote
(@dalilasalam09)
New Member
Joined: 11 years ago
Posts: 3
Topic starter  

Hello,

I don't think if ti's possible to display a the i block of an image if I don't have the blocks from 1 to (i-1), because the JPEG encoder encodes the DC difference not the DC coefficient Diff DC (i) = DC (i) - DC (i – l). .


   
ReplyQuote
Share: