[Java] image file openen die alleen raw data bevat

Pagina: 1
Acties:

  • Neptunus
  • Registratie: Januari 2001
  • Laatst online: 13-11-2025
Hallo mensen,

ik vroeg me af of er mede tweakers waren die ervaring hadden met het openen van raw image data file's. Zelf krijg ik het op het moment alleen nog voor elkaar om een array in java te vullen en deze weer te geven. Alleen moeten de gegevens nu uit een raw data file komen.

Die ziet er in hex zo uit:

F3 H3 DD E3 enz enz.

Deze gegevens moeten omgezet worden naar iets wat bruikbaar is in java. Heeft iemand ervaring of ideeën!

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 15-04 22:07

NMe

Quia Ego Sic Dico.

[google=java "raw image data"]
Staat daar niets zinnigs tussen? Ik zie redelijk wat links die me best bruikbaar lijken namelijk. :)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


  • Neptunus
  • Registratie: Januari 2001
  • Laatst online: 13-11-2025
-NMe- schreef op woensdag 22 juni 2005 @ 01:24:
[google=java "raw image data"]
Staat daar niets zinnigs tussen? Ik zie redelijk wat links die me best bruikbaar lijken namelijk. :)
Onderstaande code heb ik tot de laatste try catch werkend. De BufferedImage wordt niet gevult(of beter gezegt er wordt geen plaatje van gemaakt). Hij blijft null. Ik weet nu niet zo goed hoe ik nu verder moet. Zijn er miscshien tips.

Java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;

public class Apl {
    public static void main(String[] args) {

        File file = new File("test.bin");
       
        InputStream is = null;
        try {
            is = new FileInputStream(file);
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
        }
            // Get the size of the file
            long length = file.length();
            
            System.out.println(length);
        
            // You cannot create an array using a long type.
            // It needs to be an int type.
            // Before converting to an int type, check
            // to ensure that file is not larger than Integer.MAX_VALUE.
            if (length > Integer.MAX_VALUE) {
                // File is too large
            }
        
            // Create the byte array to hold the data
            byte[] bytes = new byte[(int)length];
        
            // Read in the bytes
            int offset = 0;
            int numRead = 0;
            try {
                while (offset < bytes.length
                       && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
                    offset += numRead;
                }
            } catch (IOException e3) {
                e3.printStackTrace();
            }
        
            // Ensure all the bytes have been read in
            if (offset < bytes.length) {
                try {
                    throw new IOException("Could not completely read file "+file.getName());
                } catch (IOException e4) {
                    e4.printStackTrace();
                }
            }
        
            try {
                // Close the input stream and return bytes
                is.close();
            } catch (IOException e4) {
                e4.printStackTrace();
            }
           
            System.out.println("tja...");
           
            ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
            System.out.println(bin.available());
            
            try {
                BufferedImage plaatje = ImageIO.read(bin);
                System.out.println(plaatje.getHeight());
                System.out.println(plaatje.getWidth());
            } catch (IOException e) {
                e.printStackTrace();
            } 
      }
}