【问题标题】:open and save same image again on android在android上再次打开并保存相同的图像
【发布时间】:2014-05-04 06:50:01
【问题描述】:

我正在尝试在图库中打开保存的图像,并在此打开的图像上写了一些文本后,尝试将其关闭。但到目前为止,它不起作用。你能告诉我我做错了什么吗?

**我检查了路径,它是正确的。这是我的代码:

String path = android.os.Environment.getExternalStorageDirectory().toString() + "/DCIM/100LGDSC/";
String pathiki = path+filename;
Log.d("pathiki:",pathiki);

try {
  Bitmap bm = BitmapFactory.decodeFile(pathiki);  
  Typeface tf = Typeface.create("Helvetica", Typeface.BOLD);

  Paint paint = new Paint();
  paint.setStyle(Style.FILL);
  paint.setColor(Color.WHITE);
  paint.setTypeface(tf);
  paint.setTextAlign(Align.CENTER);
  paint.setTextSize(14);

  Canvas canvas = new Canvas(bm);
  canvas.drawText("bla bla bla", 100, 100, paint);

  OutputStream fOut = new FileOutputStream(new File(pathiki));
  bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
  fOut.flush();
  fOut.close();
} catch (Exception e) {
  // TODO: handle exception
  e.toString();
}

【问题讨论】:

  • 查看日志猫,你可能会得到一些提示。它很可能在覆盖文件时抛出错误。
  • 没有错误抛出,当我检查 logcat 时,

标签: android android-image


【解决方案1】:

BitmapFactory.decodeFile 总是返回一个不可变的位图。使用Bitmap.copy 制作可变位图的副本。现在对复制的位图进行修改。

Bitmap bm = BitmapFactory.decodeFile(pathiki).copy(Bitmap.Config.ARGB_8888, true); 

更新异常处理程序代码。将e.getMessage() 记录到logcat 或使用e.printStackTrace()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多