我的情况如下:我正在将数组列表中的多个位图保存到设备SD卡中的特定文件夹中(成功),但是,当单击保存的文件时,手机会提示一条消息:"找不到执行此操作的应用程序。"此文件的文件大小与正在保存的位图图像的大小成比例,所以我有点困惑,因为设备打开图像文件没有问题,但无法将其作为媒体文件打开(或识别)。
问题:是什么原因导致保存的图像文件(假设我正确保存了它)在设备中表现出这种行为,我应该如何解决这个问题?
额外:文件的缩略图是系统提供的两篇论文的缩略图。arraylist正从一个活动传递到提供所提供方法的当前活动。
以下是调用将文件保存到指定文件夹/文件目的地的方法:
private void saveImages(){
// to retrieve bitmaps
ArrayList<Bitmap> images = getIntent().getParcelableArrayListExtra("images key");
//to retrieve bitmaps and save in specific order, while also naming them in that order
int loopVal = 0;
int postVal = 9;
while ( loopVal < 9) {
Bitmap Image = images.get(loopVal);
try {
String filedestination = new String(Environment.getExternalStorageDirectory() + "/filedestination");
String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date());
File file = new File(filedestination, postVal + ".post_order" + ".jpg" + timeStamp);
File picfile = file;
FileOutputStream fos = new FileOutputStream(picfile);
Image.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
} catch (Throwable e) {
e.printStackTrace();
}
postVal--;
loopVal++;
}
}
任何见解都将不胜感激,
-Lucas
我认为它无法读取文件类型,因为时间戳在文件扩展名jpg之后,而且你也将其压缩为png,所以你可能想更改或,类似于这个
File file = new File(filedestination, postVal + timeStamp +".post_order" + ".png");
您似乎正在保存一个压缩为PNG的.jpg文件。这可能会使图像阅读器应用程序行为不端。
要么更改Image.compress(Bitmap.CompressFormat.PNG, 100, fos);
至
Image.compress(Bitmap.CompressFormat.JPEG, 100, fos);
或更改
File file = new File(filedestination, postVal + ".post_order" + ".jpg" + timeStamp);
至
File file = new File(filedestination, postVal + ".post_order" + ".png" + timeStamp);