c++ cx - UWP Converting BitmapImage to WriteableBitmap -


ultimately goal save image remote server via http local storage.

i read this

bitmapimage^ im = ref new bitmapimage(); im->createoptions = bitmapcreateoptions::ignoreimagecache; im->downloadprogress += ref new downloadprogresseventhandler(this, &capture::showdownloadprogress); im->imageopened += ref new routedeventhandler(this, &capture::imagedownloaded); im->urisource = ref new uri(url); 

when imagedownloaded triggered want able save image .jpg file. have write permission destination folder.

i've found approaches read image writeablebitmap constructor requires width , height... not know prior getting image.

what methods can use to...
1. obtain image data in useful format can write disk?
2. display in xaml image uielement?
3. provided callbacks downloadprogress , imageopened or downloaded?

i can't believe how tricky is.

the "writable" in writablebitmap refers being editable (it's not being writable disk).

in order write downloaded image file disk don't need bitmapimage or writablebitmap, can download stream , write directly disk. can create bitmapimage same stream in order display in xaml image element.

// download image , write disk uri uri = new uri("https://assets.onestore.ms/cdnfiles/external/uhf/long/9a49a7e9d8e881327e81b9eb43dabc01de70a9bb/images/microsoft-gray.png"); storagefile file = await storagefile.createstreamedfilefromuriasync("microsoft-gray.png", uri, null); await file.copyasync(applicationdata.current.localfolder, "microsoft-gray.png", namecollisionoption.replaceexisting);  // create bitmapimage , display in xaml irandomaccessstream stream = await file.openasync(fileaccessmode.read); bitmapimage bitmap = new bitmapimage(); await bitmap.setsourceasync(stream); imageelement.source = bitmap; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -