2

I am trying to open a bitmap that has already been stored in SdCard as follows:

    String imageFilePath= "/sdcard/SoftCopy/"+mybitmap.png;
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
    Bitmap loadedWork= BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);

I have a second Bitmap named currentWork. This bitmap is actually the current drawing that has been done. I have combined two bitmaps as follows:

Canvas c = new Canvas(loadedWork);
c.drawBitmap(currentWork, 0, 0, null); //so that currentWork get drawn on loadedWork

Now i am saving the combined bitmap (now in loadedWork) to file as follows:

try {

final FileOutputStream out = new FileOutputStream(new File("/sdcard/SoftCopy" + "/mybitmap.png"));

            loadedWork.compress(Bitmap.CompressFormat.PNG, 90, out);
            out.flush();
            out.close();

            return true;
        }

        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

THE problem is that the combined bitmap(loadedWork) gets saved as png file for 1st time and i am able to load it, however WHEN I AGAIN TRY TO SAVE AFTER MAKING SOME MODIFICATIOns, then the application crashes. Can someone tell me how can I be able to resave the combined bitmap.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Waneya Iqbal
  • 1,559
  • 4
  • 13
  • 17
  • Actually I am new to android development. I dont know how to use logcat :s – Waneya Iqbal Aug 10 '11 at 18:21
  • At the bottom of Eclipse's window there is Logcat tab. Logcat output is printed there. Check what's in it after your application crashes and post error (marked red). Usually logcat output is self explainatory as it consists of error class, source code file and line and call stack. – Im0rtality Aug 10 '11 at 18:24
  • On resaving, the application crashes and LogCat is indicating a problem at line Canvas c= new Canvas(loadedWork); – Waneya Iqbal Aug 10 '11 at 19:02
  • Post whole error (Exception class, ...) – Im0rtality Aug 10 '11 at 19:08
  • E 980 AndroidRuntime – Waneya Iqbal Aug 10 '11 at 19:13
  • Need whole line error log not fraction of it... – Im0rtality Aug 10 '11 at 19:29
  • Caused by: java.IllegalStateException: Immutable bitmap passed to Canvas Constructor at android.graphics.Canvas. (Canvas.java:83) at neduet.telecom.softcopy.surface.SoftCopyInterface.getBitmap(SoftCopyInterface.java:128) Actually SoftCopyInterface is a SurfaceView. And getBitmap() is a method defined in it to get the current contents of surface. public Bitmap getBitmap() { Canvas c = new Canvas(loadedWork); c.drawBitmap(currentWork, 0, 0, null); return loadedWork; } – Waneya Iqbal Aug 10 '11 at 19:49
  • Now Google "Immutable bitmap passed to Canvas Constructor" (from logcat) gives you http://stackoverflow.com/questions/3693060/loading-a-resource-to-a-mutable-bitmap – Im0rtality Aug 10 '11 at 20:48
  • Thanks alot Im0rtality.... my problem has solved =D – Waneya Iqbal Aug 11 '11 at 16:41

0 Answers0