Hi
I have 21 photo JPEG images on a (simulated) SD Card. I want to read
out the binary
image bytes from each image in turn via the Image ContentProvider and
process the
data (upload to a server). I have written the method processImages()
for my Activity -
public void processImages() {
Log.d(TAG,"processImages()---ENTER---");
int cnt=1;
byte [] imageData = null;
Uri extImagesUri = Images.Media.EXTERNAL_CONTENT_URI;
String [] projection = {Images.ImageColumns._ID} ;
Cursor cur = managedQuery(extImagesUri, projection, null,
null, null);
long rowID=0;
int idIndex =0;
//
cur.moveToFirst() ;
while ( cur.moveToNext() ) {
Log.d(TAG,"Picture #"+cnt+" ---begin---");
idIndex = cur.getColumnIndexOrThrow(Images.Media._ID);
rowID = cur.getLong( idIndex );
Uri imageUri = Uri.withAppendedPath(extImagesUri, (new
Long(rowID)).toString() );
Log.d(TAG, "imageUri is " + imageUri.toString() );
try {
Bitmap bitmap = Images.Media.getBitmap(
getContentResolver(),
imageUri );
if (bitmap == null) {
Log.d(TAG, "Sorry no bitmap today :(");
Log.d(TAG,"Picture #"+cnt+" ---end-----");
cnt++;
continue;
}
ByteArrayOutputStream bytes = new
ByteArrayOutputStream();
if (bytes == null) {
Log.d(TAG, "Sorry no ByteArrayOutputStream
today :(");
Log.d(TAG,"Picture #"+cnt+" ---end-----");
cnt++;
continue;
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 90,
bytes);
imageData = bytes.toByteArray() ;
Log.d(TAG,"len of data is " + imageData.length + "
bytes");
// Release bitmap
bitmap = null ;
//
// Do something with imageData
// <SNIP> ... </SNIP>
// release imageData
imageData=null;
if (bytes != null) {
bytes.close();
}
} catch (FileNotFoundException of) {
Log.e(TAG,of.toString(),of);
} catch (IOException ioe) {
Log.e(TAG, ioe.toString(), ioe);
}
Log.d(TAG,"Picture #"+cnt+" ---end-----");
cnt++;
}
Log.d(TAG,"processImages()---EXIT----");
}
When I run this code I get data fbytes or the first Image only, all
the later Bitmap objects
are returned as null by
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---