c# - Set secondary tile image from programatically created writeable bitmap -
i'm desperately trying set writeable bitmap source of secondary tiles image. think i'm there refuses work. can see i'm missing? grateful!
i'm creating bitmap using:
var bitmap = new writeablebitmap(150, 150); stream stream = bitmap.pixelbuffer.asstream(); stream.seek(0, seekorigin.begin); var pixels = new byte[stream.length]; (int = 0; < pixels.length; += 4) { pixels[i] = 255; pixels[i + 1] = 0; pixels[i + 2] = 189; pixels[i + 3] = 9; } stream.write(pixels, 0, pixels.length); bitmap.invalidate(); the image saved computer with:
await writeablebitmapsaveextensions.savetofile(bitmap, applicationdata.current.localfolder,"image.png", creationcollisionoption.replaceexisting); the image can found in directory:
c:\users\<user>\appdata\local\packages\<pkgid>\localstate i'm creating secondary tile using method:
createsecondarytilefromwebimage("image.png", "tildid","shortname","displayname","arguments", mainpage.getelementrect((frameworkelement)sender)); public async task createsecondarytilefromwebimage(string bitmapname, string tileid, string shortname, string displayname, string arguments, rect selection) { //create uri var bitmap = new uri(string.format("ms-appdata:///local/{0}", bitmapname)); //create tile secondarytile secondarytile = new secondarytile(tileid, shortname, displayname, arguments, tileoptions.shownameonlogo, bitmap); //confirm creation await secondarytile.requestcreateforselectionasync(selection, windows.ui.popups.placement.above); } the tile created , pinned startscreen image 100% transparent.
after correcting code produced valid .png file in directory mentioned here: c:\users\\appdata\local\packages\\localstate
it turns out simple problem how writing writeablebitmap pixels. although writeablebitmap data stream format argb, bytes need written backwards. in question, i'm actually assigning every pixel to: bgra = 255,0,189,9
where transparency byte set 9, making image 100% transparent , giving appearance didn't load correctly.
therefore, in order desired color, instead need write:
var pixels = new byte[stream.length]; (int = 0; < pixels.length; += 4) { pixels[i] = 9; pixels[i + 1] = 189; pixels[i + 2] = 0; pixels[i + 3] = 255; }
Comments
Post a Comment