imageview - Android - Get a ScreenShot of the visible area of a Scrollview -
how screen shot of visible area of scrollview in android ?
my view hierarchy below:
scrollview - linear layout - imageview
this code use in utility class of mine:
@suppresslint("simpledateformat") protected final static boolean shoot (final context ctx, final view v, final string appname) { boolean isok = false; // bitmap view v.setdrawingcacheenabled(true); final bitmap bmp = v.getdrawingcache(); final simpledateformat sdf = new simpledateformat("yyyymmdd@hhmmss"); final calendar cal = calendar.getinstance(); // set file properties filejpg = appname + "_" + sdf.format(cal.gettime()); /* create path place our picture in user's public pictures directory. note should careful place here, since user manages these files. pictures , other media owned application, consider context.getexternalmediadir(). */ final file path = environment.getexternalstoragepublicdirectory ( //environment.directory_pictures //environment.directory_dcim environment.directory_dcim + "/yourappname/" ); // make sure pictures directory exists. if(!path.exists()) { path.mkdirs(); } final file file = new file(path, filejpg + ".jpg"); try { final fileoutputstream fos = new fileoutputstream(file); final bufferedoutputstream bos = new bufferedoutputstream(fos, 8192); bmp.compress(compressformat.jpeg, 85, bos); bos.flush(); bos.close(); filejpg = file.getpath(); isok = true; } catch (final ioexception e) { e.printstacktrace(); } return isok; }
Comments
Post a Comment