android - Fit just taken photo into imagebutton -


i have imagebutton, when press can take picture phone. when take picture imagebuttons gets picture source. problem is, image doesn't scale down dimensions of imagebutton. shows part of image in imagebutton instead of scaling down. after doing bit of research saw have use draw 9 patch. not possible in case, because image aren't in resources, made user itself.

can me this?

my code:

if (requestcode == request_camera) {     file f = new file(environment.getexternalstoragedirectory().tostring());     (file temp : f.listfiles()) {         if (temp.getname().equals("temp.jpg")) {             f = temp;             break;         }     }      try {         bitmap bm;         bitmapfactory.options btmapoptions = new bitmapfactory.options();         bm = bitmapfactory.decodefile(f.getabsolutepath(),btmapoptions);         // bm = bitmap.createscaledbitmap(bm, 70, 70, true);         btnimg.setimagebitmap(bm);         string path = android.os.environment.getexternalstoragedirectory() + file.separator + "phoenix" + file.separator + "default";         f.delete();         outputstream fout = null;         file file = new file(path, string.valueof(system.currenttimemillis()) + ".jpg");          try {                 fout = new fileoutputstream(file);             bm.compress(bitmap.compressformat.jpeg, 85, fout);             fout.flush();             fout.close();         } catch (filenotfoundexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         } catch (exception e) {             e.printstacktrace();         }     } catch (exception e) {             e.printstacktrace();         }             } }  else if (requestcode == select_file) { uri selectedimageuri = data.getdata(); string temppath = getpath(selectedimageuri, mainactivity.this); bitmap bm; bitmapfactory.options btmapoptions = new bitmapfactory.options(); bm = bitmapfactory.decodefile(temppath, btmapoptions); btnimg.setimagebitmap(bm); } 

use imageview's method setscaletype. pass scaletype.center_inside parameter.

btnimg.setimagebitmap(bm); btnimg.setscaletype(scaletype.center_inside); 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -