SurfaceView 上的 Android 相机肖像并保存快照

发布于 2024-12-09 03:39:19 字数 1182 浏览 0 评论 0原文

我的api是2.2,所以我使用camera.setDisplayOrientation(90)来使预览为纵向,这个效果很好,但是当我将图片保存到sd时,图片是水平的而不是纵向。当我使用时:

@Override
    protected Bitmap doInBackground(String... params) {

        int w = bmp.getWidth();
        int h = bmp.getHeight();
        // Setting post rotate to 90
        Matrix mtx = new Matrix();
        mtx.postRotate(90);
        // Rotating Bitmap
        Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
        bmp.recycle();
        return rotatedBMP;
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        dialog.dismiss();

        ivNewPhoto.setImageBitmap(result);
        resultPath = ConstValue.MY_ALBUM_DIR + "/" + System.currentTimeMillis() + ".jpg";
        ImageFile.writePhotoJpg(result), resultPath);
        previewView.setVisibility(View.VISIBLE);
    }

bmp是快照图片但我有错误:

Activity com.android.SuperPictureSearch.photo.PhotoActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43abb200 that was originally added here

你能告诉我如何保存图片为肖像,谢谢

my api is 2.2,so i used camera.setDisplayOrientation(90) to make the preview is Portrait,this work very well,but when i save the pic to sd,the pic is horizontal not Portrait.when i used :

@Override
    protected Bitmap doInBackground(String... params) {

        int w = bmp.getWidth();
        int h = bmp.getHeight();
        // Setting post rotate to 90
        Matrix mtx = new Matrix();
        mtx.postRotate(90);
        // Rotating Bitmap
        Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
        bmp.recycle();
        return rotatedBMP;
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        dialog.dismiss();

        ivNewPhoto.setImageBitmap(result);
        resultPath = ConstValue.MY_ALBUM_DIR + "/" + System.currentTimeMillis() + ".jpg";
        ImageFile.writePhotoJpg(result), resultPath);
        previewView.setVisibility(View.VISIBLE);
    }

bmp is the Snapshot pic but i have mistakes:

Activity com.android.SuperPictureSearch.photo.PhotoActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43abb200 that was originally added here

can you tell me how to save the pic is Portrait,thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的笑 2024-12-16 03:39:19
 public void onPictureTaken(byte[] data, Camera camera) {

          Bitmap mutableBitmap = null;
          BitmapFactory.Options options = new BitmapFactory.Options();
          Bitmap  bm= BitmapFactory.decodeByteArray(data, 0, data.length, options);
           mutableBitmap =Bitmap.createScaledBitmap( bm , h, w,true);
             bm.recycle();
                Matrix matri = new Matrix();
                matri.postRotate(90);

                Bitmap  mBitmap = Bitmap.createBitmap(mutableBitmap, 0, 0, mutableBitmap.getWidth(), mutableBitmap.getHeight(), matri, true);
                mutableBitmap.recycle();

因为照片对于相机来说太大了,所以我调整了尺寸

 public void onPictureTaken(byte[] data, Camera camera) {

          Bitmap mutableBitmap = null;
          BitmapFactory.Options options = new BitmapFactory.Options();
          Bitmap  bm= BitmapFactory.decodeByteArray(data, 0, data.length, options);
           mutableBitmap =Bitmap.createScaledBitmap( bm , h, w,true);
             bm.recycle();
                Matrix matri = new Matrix();
                matri.postRotate(90);

                Bitmap  mBitmap = Bitmap.createBitmap(mutableBitmap, 0, 0, mutableBitmap.getWidth(), mutableBitmap.getHeight(), matri, true);
                mutableBitmap.recycle();

because the pic is too big form camera,so i size it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文