我有一个应用程序拍摄照片并将其保存在文件中。之后,该文件应该被转换为位图。我尝试将文件转换为位图和字节数组到位图,但都在真实设备中崩溃。这是我的代码:
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Bitmap bmp1;
File dir_image2 = new File(Environment.getExternalStorageDirectory()+
File.separator+"Ultimate Entity Detector");
dir_image2.mkdirs();
String path = (Environment.getExternalStorageDirectory()+
File.separator+"Ultimate Entity Detector"+File.separator+"TempGhost.jpg");
File tmpFile = new File(dir_image2,"TempGhost.jpg");
try {
FileOutputStream fos = new FileOutputStream(tmpFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Toast.makeText(getApplicationContext(),"DoneOP",Toast.LENGTH_LONG).show();
//FOR THE CONVERSION I USE :
bmp1 = BitmapFactory.decodeFile(path, options);//File to bitmap <------
//OR
bmp1 = BitmapFactory.decodeByteArray(data , 0,
data.length,options);//Byte array to bitmap <------
//BUT BOTH CRASH
}
};
我的代码有问题吗?还有其他方式我可以转换我上面的东西 (FileOutputStream,Byte Array,File)在位图中?有没有办法将文件放在imageView中而不在位图中转换它?
更新:我在更多设备上测试了应用程序,我发现它在三星星系名声和星系y前进时正常运行,但它在xperia T上崩溃。