Android如何调整相机图片的大小并将其保存为位图,以便在活动中的固定矩形区域中显示

时间:2011-05-02 22:42:33

标签: android bitmap

我有一个应用程序来拍摄项目,这些项目必须在ActivityScreen的某个固定区域中可见。问题是从保存的位图中显示在活动中的图片,看起来与我预览和拍摄的内容完全不同。它看起来放大并显示我拍摄时我在预览中看不到的区域:这是关键代码行

图片捕捉

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;
            }
        }
 }

图片保存

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.inSampleSize = 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) {} }

图像显示在活动中可绘制 不工作的图像显示的图像是在图片拍摄时没有在预览中看到的.......

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);

0 个答案:

没有答案