我试图在图像上绘制画布并保存更改。当应用程序启动时,我可以看到我的画布绘图,但它保存没有画布绘图。这是我的代码:
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new DrawView(this));
}
class DrawView extends View {
Paint p;
Path path;
public DrawView(Context context) {
super(context);
p = new Paint();
p.setStrokeWidth(30);
p.setStyle(Paint.Style.STROKE);
path = new Path();
}
@Override
protected void onDraw(Canvas can) {
Bitmap bm = BitmapFactory.decodeFile("/sdcard/MANUAL/img1394916221.png");
can.drawBitmap(bm, 0, 0, p);
path.reset();
path.moveTo(250, 100);
path.lineTo(300, 200);
path.lineTo(200, 200);
path.close();
p.setColor(Color.RED);
can.drawPath(path, p);
FileOutputStream out;
try {
out = new FileOutputStream("/sdcard/MANUAL/img.png");
bm.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
我的错误在哪里?
答案 0 :(得分:0)