java - How to: Save the canvas as image on SD card and always keeps the first picture -


i'm creating android app has following purpose:

  • save canvas image on sd card
  • always keep first picture after clean (with clearpaint button)
  • paint new picture keep previous image again

code:

button colorpaint = (button) findviewbyid(r.id.color); colorpaint.setonclicklistener(new onclicklistener() {  public void onclick(view v) {      int _color = r.color.red;     new pickerdialog(v.getcontext(),new oncolorchangedlistener()  {               public void colorchanged(int color) {               mpaint.setcolor(color);               log.i("tag", "mpaint one" +mpaint);               }           }, mpaint.getcolor(), _color).show();           log.i("tag", "mpaint two" +mpaint);    }   });        clearpaint = (button) findviewbyid(r.id.clearpaint);   clearpaint.setonclicklistener(new onclicklistener() {     public void onclick(view v) {      mbitmap.erasecolor(color.transparent);      mpath.reset();     mview.invalidate();       }   });        btn_shoot = (button)findviewbyid(r.id.btn_shoot);   btn_shoot.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {                  view view = findviewbyid(r.id.item);                 view.setdrawingcacheenabled(true);               bitmap bitmap = view.getdrawingcache();               bitmapdrawable bitmapdrawable = new bitmapdrawable(bitmap);                if (environment.media_mounted.equals(environment.getexternalstoragestate())) {                 //we check if external storage available, otherwise display error message user                     file sdcard = environment.getexternalstoragedirectory();                    file directory = new file (sdcard.getabsolutepath() + "/basketball_coach_board");                    directory.mkdirs();                     string filename = "tactics" + + ".jpg";                     file yourfile = new file(directory, filename);                     while (yourfile.exists()) {                     i++;                        filename = "tactics" + + ".jpg";                          yourfile = new file(directory, filename);                        }                      if (!yourfile.exists()) {                        if (directory.canwrite())                        {                            try {                              fileoutputstream out = new fileoutputstream(yourfile, true);                              bitmap.compress(bitmap.compressformat.png, 90, out);                              out.flush();                              out.close();                              toast.maketext(mainactivity.this, "tactics saved @ /sdcard/basketball_coach_board/tactics" + + ".jpg", toast.length_short).show();                              i++;                             } catch (ioexception e) {                            e.printstacktrace();                         }                         }                    }                  }                 else                 {                    toast.maketext(mainactivity.this, "sd card not available!", toast.length_short).show();                 }           }     }); 

i guess because after taking picture don't reset drawing cache false with: view.setdrawingcacheenabled(false);


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -