【发布时间】:2012-10-10 23:00:48
【问题描述】:
在我的应用程序中,我扩展了 ImageView 并覆盖了它的 onDraw() 方法。我正在使用颜色过滤器来操作位图以添加一些效果,如反转、灰度等。绘制位图后,我试图保存它,但我只能保存原始位图而没有添加效果。这是 onDraw() 和保存方法的代码:
protected void onDraw(Canvas canvas)
{
Paint paint = mPaint;
//cmf is the color matrix filter
paint.setColorFilter(cmf);
if(mBitmap != null)
{
canvas.drawBitmap(mBitmap, offsetW, offsetH, paint);
}
}
位图保存代码:
try
{
FileOutputStream fout = new FileOutputStream(path);
mBitmap.compress(CompressFormat.JPEG, 100, fout);
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
我做错了吗?任何帮助将不胜感激。
【问题讨论】:
-
尝试调用方法invalidate()
-
为什么要保存位图?如果它们变化很大,您可以保存油漆并重新使用它们。如果保存很多位图,可能会遇到内存问题
-
@jay onDraw() 方法被调用,所以不需要调用 invalidate()。
-
@NikkyD 我仅在用户单击保存按钮时才保存位图。所以,内存在这里不是问题。问题是保存在位图上绘制的效果。
标签: android bitmap colormatrixfilter