作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 Activity ,第一个是按钮,它调用 void openCamera,第二个是我需要获取位图。
我有两个问题:
1、哪一行代码是保存图片?
2. 如何从 OnActivityResult 获取位图并在另一个 Activity 中获取它?
private void openCamera() {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "Taking pic from the Camera");
image_uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, image_uri);
startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
SelectedImage.setImageURI(image_uri);
try {
Bitmap ImageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), image_uri);
detectImage(ImageBitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
最佳答案
不要考虑通过Bundle
传递它(文档:https://developer.android.com/guide/topics/resources/runtime-changes.html#RetainingAnObject)
我认为,您应该将图像保存在应用程序的内部存储中,然后将其加载到第二个 Activity 中。以下是解释如何执行此操作的答案:Saving and Reading Bitmaps/Images from Internal memory in Android
关于java - 如何将图像传输到另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61558063/
我是一名优秀的程序员,十分优秀!