android - problems in uploading image to mysql server (large images) -
hello in code uploading image android phone mysql server , database, there problem large images specially photos captured phone camera, when select image gallery image not set in imageview in layout while other images set, , in logcat have this:
w/openglrenderer: bitmap large uploaded texture (4128x2322, max=4096x4096)
also when select image other images captured phone camera, have smaller size, message uploaded image image uloaded twice!!! please can me solve these 2 problems(twice ulpload+ large images) thank you, bellow code of uploading :
public class send extends appcompatactivity { private button buttonchoose; private button buttonupload; private imageview imageview; private edittext edittextname; private edittext edittextphone; private edittext edittexttext; private bitmap bitmap; private int pick_image_request = 1; private static string host=pathconfig.hostname; private string upload_url ="http://"+host+"/upload.php"; private string key_image = "image"; private string key_name = "name"; private string key_phone = "phone"; private string key_text = "text"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_send); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); setsupportactionbar(toolbar); getsupportactionbar().sethomeasupindicator(r.drawable.arrowb); getsupportactionbar().setdisplayhomeasupenabled(true); // setting arrow in toolbar // getsupportactionbar().setdisplayshowhomeenabled(true); settitle("إرسال شكوى أو إقتراح"); buttonchoose = (button) findviewbyid(r.id.choosebutton); buttonupload = (button) findviewbyid(r.id.sendbutton); edittextname = (edittext) findviewbyid(r.id.name); edittextphone= (edittext) findviewbyid(r.id.phone); edittexttext= (edittext) findviewbyid(r.id.text); imageview = (imageview) findviewbyid(r.id.imageview4); buttonchoose.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { showfilechooser(); } }); buttonupload.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { uploadimage(); } }); } public string getstringimage(bitmap bmp){ bytearrayoutputstream baos = new bytearrayoutputstream(); if(bmp!=null){ bmp.compress(bitmap.compressformat.jpeg, 100, baos); } byte[] imagebytes = baos.tobytearray(); string encodedimage = base64.encodetostring(imagebytes, base64.default); return encodedimage; } private void uploadimage() { final string name = edittextname.gettext().tostring().trim(); final string phone = edittextphone.gettext().tostring().trim(); final string text = edittexttext.gettext().tostring().trim(); if (name.matches("") || phone.matches("") || text.matches("")) { toast.maketext(this, " عذرا, لا يمكن ترك حقول فارغة", toast.length_short).show(); } else { //showing progress dialog final progressdialog loading = progressdialog.show(this, "جاري الإرسال...", "الرجاء الإنتظار...", false, false); stringrequest stringrequest = new stringrequest(request.method.post, upload_url, new response.listener<string>() { @override public void onresponse(string s) { //disimissing progress dialog loading.dismiss(); //showing toast message of response toast.maketext(send.this, s, toast.length_long).show(); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror volleyerror) { //dismissing progress dialog loading.dismiss(); if (volleyerror != null) { log.e(" upload error ", "volley " + volleyerror.getmessage().tostring()); //showing toast toast.maketext(send.this, volleyerror.getmessage().tostring(), toast.length_long).show(); } } }) { @override protected map<string, string> getparams() throws authfailureerror { //converting bitmap string string image = getstringimage(bitmap); //getting image name //creating parameters map<string, string> params = new hashmap<string, string>(); //adding parameters params.put(key_image, image); params.put(key_name, name); params.put(key_phone, phone); params.put(key_text, text); //returning parameters return params; } }; //creating request queue requestqueue requestqueue = volley.newrequestqueue(this); //adding request queue requestqueue.add(stringrequest); } } private void showfilechooser() { intent intent = new intent(); intent.settype("image/*"); intent.setaction(intent.action_get_content); startactivityforresult(intent.createchooser(intent, "select picture"), pick_image_request); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if (requestcode == pick_image_request && resultcode == result_ok && data != null && data.getdata() != null) { uri filepath = data.getdata(); try { //getting bitmap gallery bitmap = mediastore.images.media.getbitmap(getcontentresolver(), filepath); //setting bitmap imageview imageview.setimagebitmap(bitmap); } catch (ioexception e) { e.printstacktrace(); } } } @override public boolean onsupportnavigateup() { onbackpressed(); return true; }
Comments
Post a Comment