将位图图像保存到 SD 卡 - API 1.5 中存在问题?
知道为什么这不适用于运行 Android API 1.5 的 HTC Hero 吗?
private static void Save_to_SD (Bitmap bm, String image_name){
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
String meteoDirectory_path = extStorageDirectory + "/Weather_Belgium";
OutputStream outStream = null;
File file = new File(meteoDirectory_path, "/"+ image_name);
try {
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Log.i("Hub", "OK, Image Saved to SD");
Log.i("Hub", "height = "+ bm.getHeight() + ", width = " + bm.getWidth());
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i("Hub", "FileNotFoundException: "+ e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.i("Hub", "IOException: "+ e.toString());
}
}
Logcat 没有显示任何错误,我的图像通常为 340x380:
12-19 12:06:41.035: INFO/Hub(1762): 目录存在
12-19 12:06:41.035: INFO/Hub(1762): isDirectory = true
12-19 12:06:41.045: INFO/Hub(1762): 好的,图像已保存到 SD
12-19 12:06:41.045:INFO/Hub(1762):高度 = 340,宽度 = 380
12-19 12:06:41.055: INFO/Hub(1762): 好的,图像已保存到 SD
当我浏览我的 SD 卡并查看我保存的图像时,这些图像被保存为“无效图像”48 八位字节图像!?
发生什么事了?
清单:
<uses-sdk android:minSdkVersion="3"
android:targetSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
编辑: 看起来这段代码对于 PNG、JPG 图像可以正常工作,但问题与我的图像最初是 GIF 图像(从网上下载)有关。
Any idea why this is not working on a HTC Hero running on Android API 1.5 ?
private static void Save_to_SD (Bitmap bm, String image_name){
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
String meteoDirectory_path = extStorageDirectory + "/Weather_Belgium";
OutputStream outStream = null;
File file = new File(meteoDirectory_path, "/"+ image_name);
try {
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Log.i("Hub", "OK, Image Saved to SD");
Log.i("Hub", "height = "+ bm.getHeight() + ", width = " + bm.getWidth());
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i("Hub", "FileNotFoundException: "+ e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.i("Hub", "IOException: "+ e.toString());
}
}
Logcat doesn't show any error and my images are normally 340x380:
12-19 12:06:41.035: INFO/Hub(1762): directory exists
12-19 12:06:41.035: INFO/Hub(1762): isDirectory = true
12-19 12:06:41.045: INFO/Hub(1762): OK, Image Saved to SD
12-19 12:06:41.045: INFO/Hub(1762): height = 340, width = 380
12-19 12:06:41.055: INFO/Hub(1762): OK, Image Saved to SD
When I then browse my SD card and take a look at my saved images, these are saved as "Invalid Image" 48 octets images !?
What's happening ?
Manifest:
<uses-sdk android:minSdkVersion="3"
android:targetSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
EDIT :
it looks like this code is working properly for PNG, JPG images but the problem has to do with the fact that my images are GIF images initially (downloaded from the web).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论