我从图库中选取图像并在ImageView上显示图像。我能够成功地做到这一点。我的问题是,当我尝试设置从相机捕获的图像(.jpg图像)时,它们不会在imageview中显示,只是出现一个空白屏幕。即使成功显示.jpg类型的图像,也不会从相机捕获。无法理解的原因,可能是由于尺寸较大。请帮助 以下是我的代码:提前无法在ImageView中显示图像
0
A
回答
0
你需要使用的FileInputStream和的BufferedInputStream读取图像
public class ImagePick extends Activity {
private Bitmap bitmap;
private ImageView imv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_upload);
imv = (ImageView) findViewById(R.id.targetimage);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 0);
}
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex); // file path of selected image
cursor.close();
// Convert file path into bitmap image using below line.
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
// put bitmapimage in your imageview
imv.setImageBitmap(yourSelectedImage);
}
}
}
}
感谢那么你将图像转换为位图。
private FileInputStream is = null;
private BufferedInputStream bis = null;
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
还要检查link
感谢
0
相反的:
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex); // file path of selected image
尝试:
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
和关闭游标之后的BitmapDecoding。
请记住,访问SD卡应该在AsynckTasks中完成。你可以调整图像大小以适应屏幕,这样你就不会占用大量的内存,看看我的其他答案Bitmap Out Of Memory Issues。如何做到这一点。
相关问题
- 1. ImageView无法一一显示图像
- 2. ImageView我无法显示图像
- 3. 在imageview中显示图像
- 4. 无法在ImageView中显示位图
- 5. 无法获取bitmoji图像显示在ImageView中从意图Android
- 6. 在imageview上显示图像
- 7. 无法在imageview中显示来自url的图像
- 8. Android:无法在ImageView中显示PNG图像
- 9. 无法在imageview中显示存储的图像?
- 10. 无法在imageview中显示捕获图像
- 11. 如何在ImageView中显示图像?
- 12. Android - 在ImageView中显示图像
- 13. JavaFX ImageView不在BorderLayout中显示图像
- 14. 在ImageView中显示大图像
- 15. 在ImageView中显示边框到图像
- 16. 在ImageView中显示全屏图像
- 17. 显示图像(从Url)在ImageView中
- 18. 无法在Android上使用imageview显示图像
- 19. imageview不显示图像
- 20. ImageView停止显示图像
- 21. imageView不显示图像xcode9
- 22. ImageView不显示图像
- 23. JavaFX ImageView图像不显示
- 24. ImageView未显示图像
- 25. Android ImageView不显示图像?
- 26. ImageView未显示图像钛
- 27. 无法在ImageView中嵌入图像
- 28. 无法让ImageView显示
- 29. 我无法在webview中显示图像
- 30. 无法在secondviewcontroller中显示图像
我将如何使用这些可以解释一点或给我一些代码 –