Friday, May 7, 2010

thumbs116x116.dat reader

I know this is very ugly, and I wished that I have time to improve it.

If anyone can beautify it, please send me a copy, thanks.


public static Bitmap readThumbsAlternative(byte[] search, String szSearch) {
// file:///SDCard/BlackBerry/pictures/image.jpg
szSearch = szSearch.substring(szSearch.lastIndexOf('/')+1,szSearch.length());
// convert the search string to bytes for easier comparison
byte[] searchtmp = szSearch.getBytes();
int lastbyte = 0;
int endIndex = 0;
for (int x = 0; x < search.length; x++) {
boolean found = false;
// For the length of searchtmp trying to find a match in the byte file
// we could also have converted search to String [new String(search)]
// and have done an index of however I prefer direct byte access as lookups tend to be faster
for (int y = 0; y < searchtmp.length; y++) {
if (search[x + y] == searchtmp[y]) {
lastbyte = x + y + 1;
found = true;
} else {
found = false;
break;
}
}
if (found) {
for (int y = lastbyte; y < search.length; y++) {
byte first = search[y];
byte second = (y < search.length - 1) ? search[y + 1] : search[y];
String firstS = Integer.toString((first & 0xff) + 0x100, 16).substring(1);
String secondS = Integer.toString((second & 0xff) + 0x100, 16).substring(1);
if (firstS.equals("ff") && secondS.equals("d9")) {
endIndex = y + 1;
break;
}
}
if (endIndex>0) {
break;
}
}
}
if (lastbyte > 0 && endIndex > 0) {
byte[] b = new byte[lastbyte + endIndex];
int counter = 0;
for (int i = lastbyte; i <= endIndex; i++) {
b[counter] = search[i];
counter++;
}
EncodedImage ei = EncodedImage.createEncodedImage(b, 0, b.length);
Bitmap bt = ei.getBitmap();
return bt;
}
return _loadingImage;
}

1 comment:

  1. I have tried this work fine for the loading the first image but it doesn't load the other images in the same folder i given that in a for loop. to display the all image can i keno what is happening in this

    ReplyDelete