[android-developers] lockCanvas() returns null when it is invisible
Hi all
I want to display an image, on custom class (BufferView) derived from the SurfaceView class. The image is loaded from an intent which allows user to select of of the pictures in the default Android's gallery.
Unfortunately, the view is occcluded by the gallery intent so lockCanvas() returns null when the root Activity tries to render the RGBA buffer retrieved from the image. (The image is fine---I can render the image to the view by pressing a "display" button afterwards) I also tried to render the image in "onResume" method yet it doesn't work.
The image is loaded from an intent of Android's default gallery, so I put the render function in the onActivityResult() like this:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == 1 && data != null) {
Uri contentURI = Uri.parse(data.getDataString());
ContentResolver cr = getContentResolver();
InputStream in = null;
try {
in = cr.openInputStream(contentURI);
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap galleryFile = BitmapFactory.decodeStream(in,null,options);
imgHeight = galleryFile.getHeight();
imgWidth = galleryFile.getWidth();
img = new int[imgWidth * imgHeight];
galleryFile.getPixels(img, 0, imgWidth, 0, 0, imgWidth, imgHeight);
bufferView.render(img, imgWidth, imgHeight);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
In bufferView.render(), it contains a typical routine of rendering a RGBA buffer:
public void render(int buf[], int w, int h) {
if (buf != null) {
canvas = holder.lockCanvas();
if (canvas != null) {
canvas.drawBitmap(buf, 0, w, 0, 0, w, h, false, null);
holder.unlockCanvasAndPost(canvas);
}
}
}
I wonder if there is any method, better without creating a new thread, to display the image in the view (i.e. the lockCanvas does not return null)?
Thanks very much,
TH
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home