zoukankan      html  css  js  c++  java
  • 关于android:getSlotFromBufferLocked的问题

    今天写了个调用摄像头之后将照片贴在屏幕上面的demo,出现了这个问题。代码如下

    package android.com.java.choosepictest;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Environment;
    import android.provider.MediaStore;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    
    public class MainActivity extends Activity {
        public static final int TAKE_PHOTO = 1;
        public static final int CROP_PHOTO = 2;
        private Button takePhoto;
        private ImageView picture;
        private Uri imageUri;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            takePhoto = (Button)findViewById(R.id.take_photo);
            picture = (ImageView)findViewById(R.id.picture);
            takePhoto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    File outputImage = new File(Environment.getExternalStorageDirectory(),"output_image.jpg");
                    try{
                        if (outputImage.exists()){
                            outputImage.delete();
                        }
                        outputImage.createNewFile();
                    }catch (IOException e){
                        e.printStackTrace();
                    }
                    imageUri = Uri.fromFile(outputImage);
                    android.util.Log.e("YPC","uri = "+imageUri);
                    Intent intent = new Intent ("android.media.action.IMAGE_CAPTURE");
                    intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
                    startActivityForResult(intent,TAKE_PHOTO);
                }
            });
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            switch (requestCode){
                case TAKE_PHOTO:
                    if (requestCode == RESULT_OK) {
                        Intent intent = new Intent ("com.android.camera.action.CROP");
                        intent.setDataAndType(imageUri,"image/*");
                        intent.putExtra("scale",true);
                        intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
                        startActivityForResult(intent,CROP_PHOTO);
                    }
                    break;
                case CROP_PHOTO:
                    if (resultCode == RESULT_OK){
                        try{
                            Bitmap bitmap = BitmapFactory.decodeStream((getContentResolver().openInputStream(imageUri)));
                            picture.setImageBitmap(bitmap);
                            android.util.Log.e("YPC","bitmap = "+bitmap);
    
                        }catch (FileNotFoundException e){
                            e.printStackTrace();
                        }
                    }
                    break;
                default:break;
            }
        }
    }

    经过一番检查发现这个异常发生在一个Activity的结束的时候,是安卓M比较常见的异常。暂时无解。

  • 相关阅读:
    剑指21.栈的压入、弹出序列
    剑指20.包含min函数的栈
    剑指19.顺时针打印矩阵
    Java--使用反编译工具,打开jar包,查看源码
    没想到 Unicode 字符还能这样玩?
    angularjs中响应回车事件
    两个很好的angular调试工具-——batarang(stable)和ng-inspector
    基于 ThinkPHP5 的 cltphp 被搜索劫持,篡改首页的解决过程记录
    国内外CDN服务商CNAME特征串调研
    开源中国/码云 README.md上传图片的爬坑记录
  • 原文地址:https://www.cnblogs.com/Sample1994/p/6507189.html
Copyright © 2011-2022 走看看