I have to create grey Scale camera live Preview. It is working fine. But i want to make the code faster.
private android.hardware.Camera.PreviewCallback previewCallback = new android.hardware.Camera.PreviewCallback()
{
public void onPreviewFrame(byte abyte0[] , Camera camera)
{
Size size = cameraParams.getPreviewSize();
int[] rgbData = YuvUtils.decodeGreyscale(abyte0, size.width, size.height);
Bitmap bitmapung = Bitmap.createBitmap(rgbData, size.width, size.height, Bitmap.Config.ARGB_8888);
Bitmap bitmapToSet = Bitmap.createBitmap(bitmapung, 0, 0, widthPreview, heightPreview, matrix, true);
MyActivity.View.setBitmapToDraw(bitmapToSet);
};
- As i am creating
Bitmap object twice
.Can i do this job with onebitmap Object
. - where (on which method like onResume or onCreate) should i getCamera
Size(means width and height once). So that i don't need to set it for each
callback
. - And I know i should use
AsyncTask
to do it. I will do it after solving my current issue.
EDIT
I can create bitmap while getting Camera Size(width,height)
. Then single instance of bitmap is associated to my Class. but i have to call setPixels
for it.
bitmapung.setPixels(rgbData, offset, stride, x, y, size.width, size.height);
What should I set the values of Stride ,offset and x,y. And also explain them plz.
Also have a look on these questions also