[英]Saving canvas drawing to sd card
I m currently working on canvas drawing in which i hv a canvas with white colored background ( with canvas.drawColor(Color.WHITE); ) and a sketched image of cartoons comics that allows to paint with some colors. 我目前正在研究画布绘图,在该绘图中,我使用白色背景的画布(用canvas.drawColor(Color.WHITE); )和允许以某些颜色绘画的卡通漫画的素描图像。 The problem is that when i go to save the canvas image only a black screen with color done get saved neither the canvas white background nor the sketched image is appeared.. I m using this code for saving canvas
问题是,当我去保存画布图像时,只会保存完成颜色的黑色屏幕,而不会出现画布白色背景或草绘图像。.我正在使用此代码来保存画布
public void saveAsJpg (File f)
{
String fname = f.getAbsolutePath ();
FileOutputStream fos = null;
try
{
fos = new FileOutputStream (f);
mBitmap.compress (CompressFormat.JPEG, 95, fos);
Toast.makeText (getApplicationContext(), "Saved " + fname, Toast.LENGTH_LONG).show ();
}
catch (Throwable ex)
{
Toast.makeText (getApplicationContext(), "Error: " + ex.getMessage (), Toast.LENGTH_LONG).show ();
ex.printStackTrace ();
}
}
Please help,,,, Thnx in advance 请提前帮助,,,, Thnx
Have you tried this? 你有尝试过吗? Write in your manifest file this permittion.
将此许可记录在清单文件中。 .
。 .
。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I got my drawing get saved. 我的图纸被保存了。 The changes i need to made in code is to create a bitmap along-with the canvas by command mCanvas = new Canvas( mBitmap );
我需要在代码中进行的更改是通过命令mCanvas = new Canvas(mBitmap);与画布一起创建位图。 , which turn my canvas background as the image background..
,这会将我的画布背景作为图像背景。
Previously i had only started to painting the canvas which has black color background by default. 以前我只是开始绘画默认情况下具有黑色背景的画布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.