2

知道为什么这不适用于在 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:信息/集线器(1762):isDirectory = true

12-19 12:06:41.045: INFO/Hub(1762): OK, 图像保存到 SD

12-19 12:06:41.045:信息/集线器(1762):高度 = 340,宽度 = 380

12-19 12:06:41.055: INFO/Hub(1762): OK, 图像保存到 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 图像(从网络下载)这一事实有关。

4

0 回答 0