android - picked image as background in image button and convert to byte -


i need upload image in parse picked gallery. use imagebutton call de intent , show image picked , working.

public class datos extends activity implements onitemselectedlistener {   private final int select_photo = 1; private imagebutton imageview; byte [] data;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     requestwindowfeature(window.feature_no_title);     setcontentview(r.layout.activity_datos);     btnclick();  imagebutton pickimage = (imagebutton) findviewbyid(r.id.imagebutton);     pickimage.setonclicklistener(new onclicklistener() {          @override         public void onclick(view view) {             intent photopickerintent = new intent(intent.action_pick);             photopickerintent.settype("image/*");             startactivityforresult(photopickerintent, select_photo);         }     });  }  @override protected void onactivityresult(int requestcode, int resultcode, intent imagereturnedintent) {     super.onactivityresult(requestcode, resultcode, imagereturnedintent);      switch (requestcode) {         case select_photo:             if (resultcode == result_ok) {                 try {                     uri imageuri = imagereturnedintent.getdata();                     inputstream imagestream = getcontentresolver().openinputstream(imageuri);                     bitmap selectedimage = bitmapfactory.decodestream(imagestream);                     imageview.setimagebitmap(selectedimage); bytearrayoutputstream stream = new bytearrayoutputstream();                     selectedimage.compress(bitmap.compressformat.png, 100, stream);                     byte[] data = stream.tobytearray();                      bitmapdrawable bitmapdrawable = new bitmapdrawable(getresources(), selectedimage);                     imageview.setbackgrounddrawable(bitmapdrawable);                    } catch (filenotfoundexception e) {                     e.printstacktrace();                 }               }     } }   public void btnclick() {      button buttonenviar = (button) findviewbyid(r.id.enviar);       buttonenviar.setonclicklistener(new onclicklistener() {           @override         public void onclick(view arg0) {              //storing image in parse passed in  onclick method of button below code:                intent intentdatos = new intent(datos.this, inicio.class);             startactivity(intentdatos);              parseobject testobject = new parseobject("musica");               //data = "".getbytes();             //byte[] data = stream.tobytearray();             parsefile file = new parsefile("selected.png", data);              testobject.put("imagen", file);              testobject.saveinbackground(); 

with code, show selected image in button don't replace background. don't know how change background selected image.

also, next code convert background file , can upload parse, need convert picked image,

byte[] data = "".getbytes(); 

anyone knows how this?

thanks in advance,

firstly have bitmap in selectedimage can convert byte array this:

bytearrayoutputstream stream = new bytearrayoutputstream(); selectedimage.compress(bitmap.compressformat.png, 100, stream); byte[] data = stream.tobytearray(); 

secondly can set background of image button this:

bitmapdrawable bitmapdrawable = new bitmapdrawable(getresources(), selectedimage);  pickimage.setbackgrounddrawable(bitmapdrawable); 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -