android - not able to extract the drawing cache with overlayed bitmap images -
i trying save canvas on sdcard. drawing 2 bitmaps (one on top of another) in ondraw(canvas canvas) method. when save file, bottom layered bitmap stored. posting code ondraw method here:
paint paint = new paint(); paint.setcolor(color.black); //rectangle first image rct = new rect(10, 10, canvas.getwidth(), canvas.getheight()); // rectangle second image, secong image drawn user touches screen new_image = new rectf(touchx, touchy, touchx + secondbitmap.getwidth(), touchy + secondbitmap.getheight()); //this bitmap drawn first canvas.drawbitmap(firstbitmap, null, rct, paint); //this bitmap drawn on top of first bitmap on user touch canvas.drawbitmap(secondbitmap, null, new_image, paint); canvas.save();
the code saving canvas on sdcard written on mainactivity is:
bitmap bm = canvas.getdrawingcache() // canvas in object of class extended view string path = environment.getexternalstoragedirectory() .getabsolutepath(); boolean exists = (new file(path)).exists(); outputstream outstream = null; file file = new file(path, "drawn_image" + ".jpg"); try { outstream = new fileoutputstream(file); bmp.compress(bitmap.compressformat.jpeg, 100, outstream); outstream.flush(); outstream.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); }
the problem base image(firstbitmap of ondraw() method) saved on sdcard instead of entire canvas(with both images). new canvas...so appreciated
when getdrawingcache() called invalidates view full cache. debug code , check if going through each , every line of ondraw() method in view.
Comments
Post a Comment