public static Bitmap loadFromFile(String filename) {      try {          File f = new File(filename);          if (!f.exists()) { return null; }          Bitmap tmp = BitmapFactory.decodeFile(filename);          return tmp;      } catch (Exception e) {          return null;      }  }
   

import java.io.File;import java.io.FileOutputStream;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Bitmap.CompressFormat;import android.os.Environment;class PictUtil {  public static File getSavePath() {      File path;      if (hasSDCard()) { // SD card          path = new File(getSDCardPath() + "/Tegaky/");          path.mkdir();      } else {           path = Environment.getDataDirectory();      }      return path;  }  public static String getCacheFilename() {      File f = getSavePath();      return f.getAbsolutePath() + "/cache.png";  }  public static Bitmap loadFromFile(String filename) {      try {          File f = new File(filename);          if (!f.exists()) { return null; }          Bitmap tmp = BitmapFactory.decodeFile(filename);          return tmp;      } catch (Exception e) {          return null;      }  }  public static Bitmap loadFromCacheFile() {      return loadFromFile(getCacheFilename());  }  public static void saveToCacheFile(Bitmap bmp) {      saveToFile(getCacheFilename(),bmp);  }  public static void saveToFile(String filename,Bitmap bmp) {      try {          FileOutputStream out = new FileOutputStream(filename);          bmp.compress(CompressFormat.PNG, 100, out);          out.flush();          out.close();      } catch(Exception e) {}  }  public static boolean hasSDCard() { // SD????????      String status = Environment.getExternalStorageState();      return status.equals(Environment.MEDIA_MOUNTED);  }  public static String getSDCardPath() {      File path = Environment.getExternalStorageDirectory();      return path.getAbsolutePath();  }}

Now question comes,about the "Bitmap tmp = BitmapFactory.decodeFile(filename);",no matter how I modify it ,the result tmp is always null!
the main point is options,the options should be specifid,indicate the format of the image.So it should be like this:

BitmapFactory.Options opts = new Options();opts.inPreferredConfig = Config.RGB_565;tmp=BitmapFactory.decodeFile(bitmapPath,opts);



更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android:layout_weight的真实含义
  2. Android碎片化问题 java.lang.NoClassDef
  3. Android中两种设置全屏的方法 && Android
  4. android studio 怎么取消默认AppcompatAc
  5. listview 左滑弹出删除按钮,需要折腾一下
  6. Android样式——Styles
  7. Android(安卓)Recovery的汉化 显示中文
  8. Android(安卓)Service用法讲解与实例
  9. Android开发学习之设置Android壁纸的功能
  10. Linux下Android内核源码下载