I have 1 file that has records in it and a directory that contains images (one image per data record).
I read the data record and then read the matching image and then merge them and create a new record that contains both. The issue is that when I write out the merged data and look at the image in a viewer it does not look right (it looks scrambled compared to the original)..
Basically, here is what I'm doing.. Got any hints??
Image image = Toolkit.getDefaultToolkit().getImage(dataRec.getPhotoFileName() );
ImageSizer.waitForImage(image);
int imageWidth = image.getWidth( null );
int imageHeight = image.getHeight( null );
if (imageWidth != maxImageWidth || imageHeight != maxImageHeight) {
System.out.println("Error image not sized correctly");
}
long length;
byte[] bytes = null;
InputStream is = null;
is = new FileInputStream(file);
length = is.available();
if (length > Integer.MAX_VALUE) {
throw new Exception("Error Converting File - File Too Large To Handle ("+file.getName()+"), length of file was "+length+" max allowable length is "+Integer.MAX_VALUE);
}
bytes = new byte[(int)length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
-- I then take the bytes and append them to the end of the output record..
byte[] bb = FiletoBytes.convert(dataRec.getPhotoFileName());
I then take the bytes and append them on to the end of the output record.