Android bitmap.compress from Uri导致OutOfMemoryError
我正在尝试将用户选择的位图保存到我自己的应用程序路径中 不幸的是,对于非常大的图像,我得到了记忆错误 我正在使用以下代码:Android bitmap.compress from Uri导致OutOfMemoryError,android,bitmap,out-of-memory,Android,Bitmap,Out Of Memory,我正在尝试将用户选择的位图保存到我自己的应用程序路径中 不幸的是,对于非常大的图像,我得到了记忆错误 我正在使用以下代码: private String loadImage (Uri filePath) { File fOut = new File(getFilesDir(),"own.jpg"); inStream = getContentResolver().openInputStream(filePath); selectedImage = BitmapFacto
private String loadImage (Uri filePath) {
File fOut = new File(getFilesDir(),"own.jpg");
inStream = getContentResolver().openInputStream(filePath);
selectedImage = BitmapFactory.decodeStream(inStream);
selectedImage.compress(CompressFormat.JPEG, 100, new FileOutputStream(fOut));
}
我有没有办法将任何大小的Uri图像文件保存到一个文件中
*我无法调整图像大小,例如使用calculateInSampleSize方法
我有没有办法将任何大小的Uri图像文件保存到一个文件中
由于它已经是一个映像,只需将字节从InputStream
复制到OutputStream
:
private void copyInputStreamToFile( InputStream in, File file ) {
try {
FileOutputStream out = new FileOutputStream(file);
byte[] buf = new byte[8192];
int len;
while((len=in.read(buf))>0){
out.write(buf,0,len);
}
out.flush();
out.getFD().sync();
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
(改编自)
我有没有办法将任何大小的Uri图像文件保存到一个文件中
由于它已经是一个映像,只需将字节从InputStream
复制到OutputStream
:
private void copyInputStreamToFile( InputStream in, File file ) {
try {
FileOutputStream out = new FileOutputStream(file);
byte[] buf = new byte[8192];
int len;
while((len=in.read(buf))>0){
out.write(buf,0,len);
}
out.flush();
out.getFD().sync();
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
(改编自)这不适合我。。。没有错误,只是没有文件!我的Uri(文件路径)指向本地文件。有什么想法吗?@user1148358:使用调试器逐步检查代码。如果代码正在将大量字节写入所需的
文件
,则该文件显然存在。这对我不起作用。。。没有错误,只是没有文件!我的Uri(文件路径)指向本地文件。有什么想法吗?@user1148358:使用调试器逐步检查代码。如果代码正在将大量字节写入所需的文件
,则该文件显然存在。