问题
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. 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
回答1:
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 );, 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.
回答2:
Have you tried this? Write in your manifest file this permittion. . .
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
来源:https://stackoverflow.com/questions/5295041/saving-canvas-drawing-to-sd-card