c# - Why are my BitmapImages not displaying? -
ad[a,o]pting brundritt's illustration here, referenced in responding my before bingmaps question, have been able display info in "infobox" so:
...but not getting bitmapimage part of info intend display.
my question why images not displaying, , need go in order display them?
it's not info - i've saved thumbnail image sqlite database, stored array of bytes, can seen images in sqlitetoolbox:
:
so can see, string info displaying fine, not image. here pertinent code i've got retrieving info , displaying it:
// class used create sqlite table public class photraxbasedata { [sqlite.primarykey] [sqlite.autoincrement] public int id { get; set; } . . . public datetime datetimetaken { get; set; } public string filepath { get; set; } public byte[] thumbnail { get; set; } } private async void gener8mapmarkers(list<photraxbasedata> _pbd) { foreach (photraxbasedata pbd in _pbd) { string descandfilename = path.getfilename(pbd.filepath); if (null != pbd.imgdescription) { descandfilename = string.format("{0} - {1}", pbd.imgdescription, descandfilename); } bitmapimage bmi = await photraxutils.bytearraytobitmapimage(pbd.thumbnail); if (photraxutils.validlatandlong(pbd.latitude, pbd.longitude)) { location loc = new location(pbd.latitude, pbd.longitude); addpushpin(loc, descandfilename, pbd.datetimetaken, null, datalayer); } } } public static async task<bitmapimage> bytearraytobitmapimage(this byte[] bytearray) { // http://dotnetspeak.com/2013/04/convert-byte-array-to-an-image-in-winrt if (bytearray != null) { using (var stream = new inmemoryrandomaccessstream()) { await stream.writeasync(bytearray.asbuffer()); var image = new bitmapimage(); stream.seek(0); image.setsource(stream); homecoming image; } } homecoming null; } public class pushpinmetadata { public string descandfilename { get; set; } public datetime datetimetaken { get; set; } public bitmapimage thumbnail { get; set; } } public void addpushpin(location latlong, string descandfilename, datetime datetimetaken, bitmapimage thumbnail, maplayer layer) { pushpin p = new pushpin() { tag = new pushpinmetadata() { descandfilename = descandfilename, datetimetaken = datetimetaken, thumbnail = thumbnail } }; maplayer.setposition(p, latlong); p.tapped += pintapped; layer.children.add(p); } private void pintapped(object sender, windows.ui.xaml.input.tappedroutedeventargs e) { pushpin p = sender pushpin; pushpinmetadata m = (pushpinmetadata)p.tag; //ensure there content displayed if (!string.isnullorempty(m.descandfilename)) { infobox.datacontext = m; infobox.visibility = visibility.visible; maplayer.setposition(infobox, maplayer.getposition(p)); } else { infobox.visibility = visibility.collapsed; } }
the xaml:
<bm:map.children> <!-- info layer--> <bm:maplayer name="datalayer"/> <!--common infobox--> <bm:maplayer> <grid x:name="infobox" visibility="collapsed" margin="0,-115,-15,0"> <border width="300" height="110" background="black" opacity="0.8" borderbrush="white" borderthickness="2" cornerradius="5"/> <stackpanel height="100" margin="5"> <grid height="40"> <textblock text="{binding descandfilename}" fontsize="20" width="250" textwrapping="wrap" horizontalalignment="left" /> <button content="x" tapped="closeinfobox_tapped" horizontalalignment="right" verticalalignment="top"/> </grid> <grid height="40"> <viewbox height="200" stretch="uniform" stretchdirection="both"> <image source="{binding thumbnail}" width="auto" height="auto" margin="2"/> </viewbox> </grid> <grid height="40"> <textblock text="{binding datetimetaken}" fontsize="16" width="290" textwrapping="wrap" height="auto"/> </grid> </stackpanel> </grid> </bm:maplayer> <callisto:customdialog content="customdialog" height="100" width="100"/> </bm:map.children>
my guess image's source property doesn't quite know bitmapimage it's bound via "thumbnail"; don't know how unbabelize mismatch (presuming that's problem lies).
updateto reply faye's brother chris, here "database" (sqlite class) declaration:
public byte[] thumbnail { get; set; }
here calling converter method, passing appropriate fellow member of class instance, , adding pushpin:
bitmapimage bmi = await photraxutils.bytearraytobitmapimage(pbd.thumbnail); if (photraxutils.validlatandlong(pbd.latitude, pbd.longitude)) { location loc = new location(pbd.latitude, pbd.longitude); //addpushpin(loc, descandfilename, pbd.datetimetaken, null, datalayer); addpushpin(loc, descandfilename, pbd.datetimetaken, bmi, datalayer); }
however: my bad, peoples!!!
i had neglected replace placeholder "null" arg "bmi" (you can see previous code commented out above, , new working phone call addpushpin() below it). image's size/scale wrong, can fixed enough, reckon.
i don't know whether jump joy or kick myself in keister, think i'll both simultaneously.
thanks mr. dunaway making me closer @ code - should have done before posting.
c# winrt-xaml bing-maps bitmapimage
No comments:
Post a Comment