Android How to size and save camera picture as bitmap for display in fixed rect area within activity
I have an app that takes pictures of items, and these items must be viewable in a certain fixed region on the ActivityScreen. The problem is the picture displayed in the activity from the saved bitmap, looks nothing like what I previewed and photographed. It looks zoomed in and shows areas I did not even see in the preview when I took the picture: Here is the key code lines
IMAGE CAPTURE:
surfHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
captImageView = (ImageView)findViewById(R.id.CamImageView);
byte [] photoData;
Camera cam;
SurfaceHolder surfHolder;
SurfaceView surfView;
Camera.PictureCallback cback;
cback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
final int length = data.length;
opts.inSampleSize = 4;
final BitmapFactory.Options opts = new BitmapFactory.Options();
Bitmap bMap = null;
try {
bMap = BitmapFactory.decodeByteArray(data, 0, length, opts);
} catch(Exception e) {
}catch(OutOfMemoryError e) {
}
captImageView.setImageBitmap(bitmap);
if(bMap==null) {
cam.startPreview();
} else {
savePhotoButton.setVisibility(ImageView.VISIBLE);
takePhotoButton.setVisibility(ImageView.INVISIBLE);
photoData = data;
}
}
}
IMAGE SAVE:
captImageView.setImageBitmap(null);
// SAVE THE PICTURE THIS SAVES PICTURE IN WRONG SIZE. LOOKS LIKED ZOOMED IN NOT WHAT WAS PREVIEWED!!!
public void photoSave(byte[] data) {
final int length = data.length;
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSi开发者_Go百科ze = 2;
try {
Bitmap bMap = BitmapFactory.decodeByteArray(data, 0, length, options);
int quality = 75;
File file = new File(getDir(), fname);
fileOutputStream = new FileOutputStream(file);
bMap.compress(CompressFormat.JPEG, quality, fileOutputStream);
}catch(FileNotFoundException e) {
} catch(OutOfMemoryError e) {} }
IMAGE DISPLAY as DRAWABLE in ACTIVITY DOES NOT WORK SHOWS IMAGE AS ZOOMED OR PORTIONS NOT SEEN IN PREVIEW AT ALL WHEN PICTURE WAS TAKEN!!
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = inSampSize;
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
Drawable drawable = bitmap;
ImageView pictureView = (ImageView)findViewById(R.id.pictureViewer);
pictureView.setImageDrawable(drawable);
精彩评论