【问题标题】:saving a bitmap in android using camera intent使用相机意图在android中保存位图
【发布时间】:2013-04-26 00:07:44
【问题描述】:

我正在尝试按照本教程进行操作,但是问题是当我单击应该确认图像的复选标记时,它根本没有做任何事情。我觉得我缺少某种访问 SD 卡或其他东西的权限。我正在调试模式下测试nexus 7。感谢所有帮助。

public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888; 
private static ImageView imageView;
protected String _path;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.imageView = (ImageView)this.findViewById(R.id.imageView1);
    Button photoButton = (Button) this.findViewById(R.id.button1);

    _path =  Environment.getExternalStorageDirectory() + "/images/camocr";


    photoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            File file = new File( _path );
            Uri outputFileUri = Uri.fromFile( file );
            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
            intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );

            //Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
            startActivityForResult( intent, 0 );
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == -1) {  
       // Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 4;
        Bitmap bitmap = BitmapFactory.decodeFile( _path, options );
        imageView.setImageBitmap(bitmap);

    }  
} 
protected static void identifyunicode() {
    // DATA_PATH = Path to the storage
    // lang for which the language data exists, usually "eng"


}

}

【问题讨论】:

  • 您将请求代码设置为 0,并在 onActivityResult 中检查 -1

标签: java android image android-camera save


【解决方案1】:

尝试在onCreate 方法中将requestCode 更改为-1。这应该可以解决您的问题。

【讨论】:

    【解决方案2】:

    在您的 startActivity for result 中,请求代码为 0,在 onActivity 结果中,您还必须使用检查 -1:

    sendBroadcast(new Intent(
                Intent.ACTION_MEDIA_MOUNTED,
                Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    

    为了显示图片,如果没有,直到你下次打开手机时才会显示

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 2011-12-04
      相关资源
      最近更新 更多