Saving canvas drawing to sd card

Deadly 提交于 2020-01-06 12:47:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!