DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Windows 8 Store Apps: Secondary Tiles

Windows 8 Store Apps: Secondary Tiles

Robert Maclean user avatar by
Robert Maclean
·
Sep. 22, 12 · Mobile Zone · Interview
Like (0)
Save
Tweet
3.68K Views

Join the DZone community and get the full member experience.

Join For Free

the call to pin a secondary tile looks like this:

secondarytile(string tileid, string shortname, string displayname, string arguments, tileoptions tileoptions, uri logoreference);

the important part for this post is the last parameter: uri logoreference. this is the the path to the image you want to show on the tile – but i had a problem, i didn’t want to show an image! i just had some text i wanted to show on the tile. after a lot of digging the solution was non trivial – generate an image at runtime. this was made even harder as the render method in wpf does not exist in the xaml implementation used in winrt.

winrt does include a writablebitmap class which allows you to create a in memory bitmap, manipulate the pixels and save to a file format with the bitmapencoder classes. the problem for me is i do not want to fiddle with pixels manually – this lead me to writablebitmapex which is a great library for having primitives (fill, line, circle etc…), the only down side was that i wanted text, not graphic primitives.

title more searching lead to two posts on stackoverflow from xxx (post 1, post 2) which provided a solution:

  1. create a sprite map using a free tool called  spritefont201
  2. use the code provided in the answers with writablebitmapex to extract the sprites and combine them with a writablebitmap.

i took the code and adjusted it slightly so text would always be centred and allowed me to play with font scaling. i’ve attached the modified code to the post below.

in the end the code i used looks like this:

public async task<storagefile> createimage()
{
    uint width = 512;
    uint height = 512;
    var writablebitmap = bitmapfactory.new((int)width, (int)height);
    writablebitmap.clear((app.current.resources["secondtilecolour"] as solidcolorbrush).color);
    
    writablebitmap.drawstringhoriztonallycentred(this.displaypostalcode, 50, "title", colors.white, 4);
    writablebitmap.drawstringhoriztonallycentred(this.town, 175, "title", colors.white, 2);
    writablebitmap.drawstringhoriztonallycentred(this.city, 275, "title", colors.white, 2);
    writablebitmap.drawstringhoriztonallycentred(string.format("box code: {0}", this.boxcode), 375, "title", colors.white, 2);
    writablebitmap.drawstringhoriztonallycentred(string.format("street code: {0}", this.streetcode), 450, "title", colors.white, 2);

    var file = await windows.storage.applicationdata.current.localfolder.createfileasync(guid.newguid().tostring("n"), windows.storage.creationcollisionoption.replaceexisting);
    using (var filestream = await file.openasync(windows.storage.fileaccessmode.readwrite))
    {
        var encoder = await bitmapencoder.createasync(bitmapencoder.pngencoderid, filestream);

        encoder.setpixeldata(bitmappixelformat.bgra8, bitmapalphamode.straight, width, height, 96, 96, writablebitmap.tobytearray());

        await encoder.flushasync();
    }

    return file;
}
app

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • AWS, Azure, and GCP: Find the Right Platform
  • Shared Kubernetes Clusters for Hybrid and Multi-Cloud
  • A Breakdown of Continuous Testing
  • Getting Started With Nose in Python

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo