WP8 C# // Save image from web, in isolate storage -
i know how save image in isolate storage using following :
private void addbutton_click(object sender, routedeventargs e) { memorystream stream = new memorystream(); writeablebitmap wb = new writeablebitmap(myimage, null); bitmapimage bi = new bitmapimage(); wb.savejpeg(stream, wb.pixelwidth, wb.pixelheight, 0, 100); stream.seek(0, seekorigin.begin); string data = convert.tobase64string(stream.getbuffer()); appsettings.add("image", data); }
i know how load using following :
private void loadimage_click(object sender, routedeventargs e) { byte[] imagebytes = convert.frombase64string(appsettings["image"].tostring()); memorystream ms = new memorystream(imagebytes); bitmapimage bitmapimage = new bitmapimage(); bitmapimage.setsource(ms); myimage.source = bitmapimage; }
but don't know how load , read url, how can accomplished?
thx help.
from image url stream:
webclient client = new webclient(); client.openreadcompleted += (s, e) => { byte[] imagebytes = new byte[e.result.length]; e.result.read(imagebytes, 0, imagebytes.length); // can use returned stream set image source var image = new bitmapimage(); image.setsource(e.result); nlbi.thumbnail.source = image; }; client.openreadasync(new uri(article.imageurl));
edit: here more info on openreadcomplete(msdn) , how use it
Comments
Post a Comment