简体   繁体   中英

Reading data from a JPEG image

I want to read data from a .jpg file (header, DCT information, Huffman table, quantization table, ...)

I tried this piece of code but I'm not sure if it's correct (in fact I don't know what to get!)

byte[] my = new byte[5];
    try 
    {
        RandomAccessFile file = new RandomAccessFile("001.jpg", "rw");
        file.read(my, 0, 5);
        for(int i = 0; i < my.length; i++)
            System.out.printf("%s\n", my[i]);

    } 
    catch (IOException e) 
    {

    }

This code just prints some number (it's supposed to be beginning of the image)

There is a lot of work between reading a "JPEG file" and getting to the pixel data.

If you are really interested, I suggest starting with one of the many JPEG dump programs that are out there to learn about the structure of the the JPEG stream. A JPEG stream consists of a sequence of markers.

The compressed data is in the scans. In progressive JPEG, multiple scans have to be combined.

The basis sequence of decoding is run-length/huffman, DCT, sampling, conversion to RGB.

That's a lot of code to get to that point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM