The Artima Developer Community
Sponsored Link

Java Answers Forum
reading binary files

1 reply on 1 page. Most recent reply: Jun 17, 2002 12:34 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
jayakumar perumal

Posts: 16
Nickname: jai
Registered: Feb, 2002

reading binary files Posted: Jun 10, 2002 9:33 PM
Reply to this message Reply
Advertisement
hi
iam having a *.pat file(raw image binary file) containing 10 frames of 256X256 images. can anyone let me know how to read this file. further each pixel corresponds to 2 bytes, how can i convert this into int values
thanks
jai


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: reading binary files Posted: Jun 17, 2002 12:34 AM
Reply to this message Reply
create a FileInputStream with the file you want to read as its argument:
File dataFile = new File("data.pat");
FileInputStream fis = new FileInputStream(dataFile);
DataInputStream dis = new DataInputStream(file);

//then its just a matter of reading in the 256x256 //pixel data bytes in some kind of loop.
int framepixels = 256*256;
for (int frame = 0;frame<10;frame++){
for (int i = 0;i<framepixels;i++){
byte firstPixelByte = dis.readByte();
byte secondPixelByte = dis.readByte();
//add your code to process the bytes here
}
}

//Its your program, finish it.



256x256 pixels corresponds to one frame
loop 10 times for ten frames

Flat View: This topic has 1 reply on 1 page
Topic: Orionserver ClassLoad issue Previous Topic   Next Topic Topic: Dynamic Binding

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use