sql server 2008 - How to display image fast from MS SQL in Android -
i have using android application , saved more images ms-sql server in nvarchar(max) format,now i'm displaying more images in android-recyclerview, time taken lot of time. want images getting fast database do, 1 me please thanks..
mycode: save images:
private void oncaptureimageresult(intent data) { bitmap thumbnail = (bitmap) data.getextras().get("data"); imgadminview.setimagebitmap(thumbnail); bytearrayoutputstream bytes = new bytearrayoutputstream(); thumbnail.compress(bitmap.compressformat.jpeg, 100, bytes); bytearray = bytes.tobytearray(); encodedimage = base64.encodetostring(bytearray, base64.default); btarray = base64.decode(encodedimage, base64.default); bmimage = bitmapfactory.decodebytearray(bytearray, 0, btarray.length); } private void onselectfromgalleryresult(intent data) { bitmap bm = null; if (data != null) { try { bm = mediastore.images.media.getbitmap(admin.this.getapplicationcontext().getcontentresolver(), data.getdata()); imgadminview.setimagebitmap(bm); bytearrayoutputstream bytes = new bytearrayoutputstream(); bm.compress(bitmap.compressformat.jpeg, 100, bytes); bytearray = bytes.tobytearray(); encodedimage = base64.encodetostring(bytearray, base64.default); btarray = base64.decode(encodedimage, base64.default); bmimage = bitmapfactory.decodebytearray(bytearray, 0, btarray.length); } catch (ioexception e) { e.printstacktrace(); } } imgadminview.setimagebitmap(bm); }
display images:
public class fetch extends asynctask<string, string, string> { string z = ""; string ownid; arraylist<data_model> arraylist=new arraylist<>(); @override protected void onpreexecute() { pbd=new progressdialog(getactivity()); pbd.setmessage("please wait..."); pbd.setcancelable(false); pbd.show(); } @override protected void onpostexecute(string r) { // pbbar.setvisibility(view.gone); if (pbd.isshowing()) pbd.dismiss(); if(r!="success"){ toast.maketext(getactivity(), r, toast.length_short).show(); } try { recyclerview_adapter adapter = new recyclerview_adapter(getactivity(), arraylist); recyclerview.setadapter(adapter);// set adapter on recyclerview adapter.notifydatasetchanged();// notify adapter } catch (exception ex){ z= ex.tostring(); toast.maketext(getactivity(),z,toast.length_short).show(); } } @override protected string doinbackground(string... params) { try { connection con = connectionclass.conn(); if (con == null) { z = "error in connection sql server"; } else {// string query=""; query = "select id,itemname,image fd_itemmaster catid='"+itemid+"' , datastatus='"+1+"'"; preparedstatement ps2 = con.preparestatement(query); resultset rs2 = ps2.executequery(); arraylist data1 = new arraylist(); while (rs2.next()) { imgid=rs2.getint("id"); title = rs2.getstring("itemname"); img = rs2.getstring("image"); //convertong images string bitmap byte[] decodestring = base64.decode(img, base64.default); bitmap decodebitmap = bitmapfactory.decodebytearray(decodestring, 0, decodestring.length); arraylist.add(new data_model(title,decodebitmap,imgid)); } z="success"; } } catch (exception ex) { z = ex.tostring(); } return z; } }
Comments
Post a Comment