导入高分辨率照片 android 应用无法运行
importing high resolution photos android app not working
我正在使用基本程序将图像从我的 phone 导入到我编写的应用程序中,并且运行良好。
唯一的问题是当我想要导入高分辨率照片 (+9 Mpx) 时,照片不会显示
setContentView(R.layout.activity_create_new_user);
contactImgView = (ImageView) findViewById(R.id.ChosenPhoto);
public void onActivityResult(int reqCode,int resCode, Intent data) {
contactImgView.setImageURI(data.getData());
}
public void AddPicture(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select contact image"),1);
}
这可能是因为它的分辨率太高了。
您必须使用 BitmapFactory methods with BitmapFactory.Options first detecting resolution of image using inJustDecodeBounds and then after counting if outWidth*outHeight > moreThenAppCanHandle you can decode it using inSampleSize 和适当的因子解码该位图,这将适当降低输出图像分辨率,这意味着消耗更少的内存。
希望这会奏效并对您有所帮助。
解决方案是不使用位图直接加载图像,而是使用名为 Picasso 的很棒的库,它的速度非常快。
将 picasso jar 文件添加到您的项目中,使用 picasso 像这样加载图像
Picasso.with(context).load(new File(title)).centerCrop()
.resize(150, 150).error(R.drawable.ic_launcher).into(imageview);
其中title是你要加载的图片路径。裁剪、调整大小、错误是可选的。
您还可以从 url.
加载图像
我正在使用基本程序将图像从我的 phone 导入到我编写的应用程序中,并且运行良好。 唯一的问题是当我想要导入高分辨率照片 (+9 Mpx) 时,照片不会显示
setContentView(R.layout.activity_create_new_user);
contactImgView = (ImageView) findViewById(R.id.ChosenPhoto);
public void onActivityResult(int reqCode,int resCode, Intent data) {
contactImgView.setImageURI(data.getData());
}
public void AddPicture(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select contact image"),1);
}
这可能是因为它的分辨率太高了。
您必须使用 BitmapFactory methods with BitmapFactory.Options first detecting resolution of image using inJustDecodeBounds and then after counting if outWidth*outHeight > moreThenAppCanHandle you can decode it using inSampleSize 和适当的因子解码该位图,这将适当降低输出图像分辨率,这意味着消耗更少的内存。
希望这会奏效并对您有所帮助。
解决方案是不使用位图直接加载图像,而是使用名为 Picasso 的很棒的库,它的速度非常快。
将 picasso jar 文件添加到您的项目中,使用 picasso 像这样加载图像
Picasso.with(context).load(new File(title)).centerCrop()
.resize(150, 150).error(R.drawable.ic_launcher).into(imageview);
其中title是你要加载的图片路径。裁剪、调整大小、错误是可选的。 您还可以从 url.
加载图像