gpt4 book ai didi

android - 如何将 Canvas 绘图保存为图像?

转载 作者:行者123 更新时间:2023-11-30 04:15:30 38 4
gpt4 key购买 nike

在我的 android 应用程序中,我将绘图保存为图像。我能够保存文件,但它并没有完美地保存 100%,即,一些内容丢失了,空格即将到来。下面的函数是我通过 onclick 调用的。请帮助我如何保存完美的绘图如需屏幕截图,请访问以下链接: http://www.flickr.com/photos/77093196@N03/7066979339 , http://www.flickr.com/photos/77093196@N03/7066979341

DigitalSignatureActivity.java

private DrawingSurface drawingSurface;

// To save file as Image
public void saveDrawing(View v) throws IOException {

File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"MySignatures");
Bitmap nBitmap = drawingSurface.getBitmap();
try {
if (!mediaStorageDir.exists()) {
mediaStorageDir.mkdirs();
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
File mediaFile = new File(mediaStorageDir.getPath()
+ File.separator + "SIGN_" + timeStamp + ".png");
FileOutputStream out = new FileOutputStream(mediaFile);

nBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
Toast.makeText(this, "Signature saved to " + mediaFile,
Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Not saved",
Toast.LENGTH_SHORT).show();
}

}

绘图表面.java

public class DrawingSurface extends SurfaceView implements SurfaceHolder.Callback {
//some code
}

最佳答案

我通过设置 canvas.drawColor(Color.WHITE, PorterDuff.Mode.DARKEN) 来解决;在 DrawingSurface.java 类中

关于android - 如何将 Canvas 绘图保存为图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10101060/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com