我想将图像保存在onPictureTaken回调中
我的消息来源如下
public voID onPictureTaken(byte[] data,Camera camera) { //prevIEw from camera Bitmap bitmap = BitmapFactory.decodeByteArray(data,data.length); // overlay image Bitmap overlayBmp = overlay.getDrawingCache(); //blank beatmap Bitmap blankBitmap = Bitmap.createBitmap(bitmap.getWIDth(),bitmap.getHeight(),Bitmap.Config.ARGB_8888); //make canvas Canvas canvas = new Canvas(blankBitmap); //composite image canvas.drawBitmap(bitmap,null,new Rect(0,bitmap.getWIDth(),bitmap.getHeight()),null); canvas.drawBitmap(overlayBmp,null);
然而,它显示了outofmemoryerrorrror,我怎么能解决这个问题..?
05-20 15:13:49.114: E/AndroIDRuntime(31647): FATAL EXCEPTION: main05-20 15:13:49.114: E/AndroIDRuntime(31647): java.lang.OutOfMemoryError05-20 15:13:49.114: E/AndroIDRuntime(31647): at androID.graphics.Bitmap.nativeCreate(Native Method)05-20 15:13:49.114: E/AndroIDRuntime(31647): at androID.graphics.Bitmap.createBitmap(Bitmap.java:605)05-20 15:13:49.114: E/AndroIDRuntime(31647): at androID.graphics.Bitmap.createBitmap(Bitmap.java:585)05-20 15:13:49.114: E/AndroIDRuntime(31647): at com.example.firstcameraappli.MainActivity.onPictureTaken(MainActivity.java:103)05-20 15:13:49.114: E/AndroIDRuntime(31647): at androID.harDWare.Camera$EventHandler.handleMessage(Camera.java:750)05-20 15:13:49.114: E/AndroIDRuntime(31647): at androID.os.Handler.dispatchMessage(Handler.java:99)05-20 15:13:49.114: E/AndroIDRuntime(31647): at androID.os.Looper.loop(Looper.java:137)05-20 15:13:49.114: E/AndroIDRuntime(31647): at androID.app.ActivityThread.main(ActivityThread.java:4514)05-20 15:13:49.114: E/AndroIDRuntime(31647): at java.lang.reflect.Method.invokeNative(Native Method)05-20 15:13:49.114: E/AndroIDRuntime(31647): at java.lang.reflect.Method.invoke(Method.java:511)05-20 15:13:49.114: E/AndroIDRuntime(31647): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)解决方法 试试这个代码……
PictureCallback myPictureCallback_JPG = new PictureCallback(){ @OverrIDe public voID onPictureTaken(byte[] data,Camera arg1) { BitmapFactory.Options opt; opt = new BitmapFactory.Options(); opt.inTempStorage = new byte[16 * 1024]; Parameters parameters = arg1.getParameters(); Size size = parameters.getPictureSize(); int height11 = size.height; int wIDth11 = size.wIDth; float mb = (wIDth11 * height11) / 1024000; if (mb > 4f) opt.inSampleSize = 4; else if (mb > 3f) opt.inSampleSize = 2; //prevIEw from camera Bitmap bitmap = BitmapFactory.decodeByteArray(data,data.length,opt); }}
在位图中获取图像,然后根据您的要求使用.
总结以上是内存溢出为你收集整理的android – outofmemoryerror同时制作位图全部内容,希望文章能够帮你解决android – outofmemoryerror同时制作位图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)