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

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -