使用旋转矩阵大的位图 [英] Rotate Large bitmap using matrix

查看:237
本文介绍了使用旋转矩阵大的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我转动我的使用矩阵,应用程序崩溃,我不想用帆布大的位图。
我使用低于code,请帮我谢谢

 矩阵mMatrix =新的Matrix();
rotateRight.postRotate(90);
rotateBitmap = Bitmap.createBitmap(BM,0,0,bm.getWidth(),
                        bm.getHeight(),rotateRight,真正的);

请参见下面logcate

  java.lang.OutOfMemoryError
在android.graphics.Bitmap.nativeCreate(本机方法)
在android.graphics.Bitmap.createBitmap(Bitmap.java:924)
在android.graphics.Bitmap.createBitmap(Bitmap.java:901)
在android.graphics.Bitmap.createBitmap(Bitmap.java:833)
在com.insta.fragment.HomeFragment.rotateBitmap(HomeFragment.java:1363)
在com.insta.fragment.HomeFragment.getBitmap(HomeFragment.java:1376)
在com.insta.customcontrol.Camera preVIEW $ 3.onPictureTaken(相机preview.java:447)
在android.hardware.Camera $ EventHandler.handleMessage(Camera.java:998)
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:136)
在android.app.ActivityThread.main(ActivityThread.java:5586)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:515)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1268)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
在dalvik.system.NativeStart.main(本机方法)


解决方案

我觉得你需要设置的选项

  BitmapFactory.Options选项=新BitmapFactory.Options();
options.inJustDe codeBounds = TRUE;
BitmapFactory.de codeByteArray的(数据0,数据。长度,期权);

更多的解释文档

或与尝试以下code

  {尝试
            //德code图像尺寸
            BitmapFactory.Options O =新BitmapFactory.Options();
            o.inJustDe codeBounds = TRUE;
            BitmapFactory.de codeByteArray的(数据0,数据。长度,O);            //我们希望新的大小缩放到
            最终诠释REQUIRED_WIDTH =宽度;
            最终诠释REQUIRED_HIGHT = HIGHT;
            //找到正确的比例值。它应该是2的幂。
            int标= 1;
            而(o.outWidth /规模/ 2 - = REQUIRED_WIDTH和放大器;&安培; o.outHeight /规模/ 2 - = REQUIRED_HIGHT)
                规模* = 2;            //德code。与inSampleSize
            BitmapFactory.Options O2 =新BitmapFactory.Options();
            o2.inSampleSize =规模;
            位图finalBitmap = BitmapFactory.de codeByteArray的(数据0,数据。长度,O2);
        }
            赶上(例外五){
         }

When i rotate my large bitmap using matrix so application crash,i don't want to using canvas. i am using below code,please help me Thanks

Matrix mMatrix = new Matrix();
rotateRight.postRotate(90);
rotateBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
                        bm.getHeight(), rotateRight, true);

See below logcate

java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:924)
at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
at android.graphics.Bitmap.createBitmap(Bitmap.java:833)
at com.insta.fragment.HomeFragment.rotateBitmap(HomeFragment.java:1363)
at com.insta.fragment.HomeFragment.getBitmap(HomeFragment.java:1376)
at com.insta.customcontrol.CameraPreview$3.onPictureTaken(CameraPreview.java:447)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:998)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5586)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)

解决方案

I think you need to set options for that

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data , 0, data .length,options);

more explanations at docs

OR try with below code

            try {
            //Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeByteArray(data , 0, data .length,o);

            //The new size we want to scale to
            final int REQUIRED_WIDTH=WIDTH;
            final int REQUIRED_HIGHT=HIGHT;
            //Find the correct scale value. It should be the power of 2.
            int scale=1;
            while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
                scale*=2;

            //Decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize=scale;
            Bitmap finalBitmap =  BitmapFactory.decodeByteArray(data , 0, data .length,o2);
        }
            catch (Exception e) {
         }

这篇关于使用旋转矩阵大的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆