Advanced transparent live tiles with count for windows phone

本文介绍如何创建带有透明效果和平滑边界的Windows Phone Live Tile。通过使用WritableBitmap进行图像合成并解决预乘Alpha问题,实现高质量的Live Tile显示。

The live tiles are brilliant to show information regarding your application without forcing the user to open it up. The basic live tile gives you two sides with some text, a count and ability to set background images. Outlined in the MSDN documentation, and thousands sites with getting started information. However, when you want to do something more advanced your mostly on your own. Here is a walkthrough with how you handle images, texts and the hardest part transparencies.

In the post Crafting the Øredev Windows Phone app live tile we explained the basic idea how this works. Using a WritableBitmap for composition and saving that result in isolated storage for your tile. Here the focus is on saving it as transparent images and how to place and define text and fonts.

Designing your live tile

The first idea in my head was to have a live tile that was more like the messaging, phone an mail tiles. I start out with a sketch of what I want to accomplish, and move that over Photoshop to handle the image parts that are needed for the tile. The first sketch was something like this:

sketch

I wanted to have a count that follows the style and tone of the native application tiles (messaging, mail, etc). I also wanted it to be transparent and follow white on accent color. After some Photoshopping I ended up with this look as empty and with a count notification:

WithoutCount   WithCount

This design above already have space for the count but you could easily extend the code to use two images, one for the count and a bigger empty one without the count.  Other things that are important is that the correct size and font weight is used as well as everything being transparent to let the accent color come through. I cut out the graphics, save it to a PNG, 173×173 with alpha channel to get smooth lines.

PNG format caveat

Here I made a little mistake: Make sure you save it in the correct PNG format – Windows Phone supports 8 pixel color depths + alpha (ARGB32), by mistake I first saved with 16 bit color depth. The result is horrible…

Composing with WritableBitmap

As with the Øredev tile you start out with images, canvas and WritableBitmap as the tools. First off  is to open the background image with the following:

Even if the image is included in the project as content it will be loaded asynchronously, thus you need to handle it on the Image opened event. First is a call for creating the tile image, then save to isolated storage and finally update the live tile, like this:

So for the details of CreateTileImage(image), this is where the the composition is taking place. We take the image that was read, render the text and place it all in a canvas to align it properly. And after that we render it with WritableBitmap:

Notes on image composition

  • Use a canvas to compose on and remember to set top/left. There are no bottom/right so you have to calculate where stuff goes from top/left
  • ActualWidth/ActualHeight gives you the calculated dimensions for a UI element
  • Use FontFamily = new FontFamily(“Segoe WP SemiBold”) to set the font family or you will get Segoe Regular

Saving as PNG

Next up is saving the tile. The preferred format to use is PNG that will support lossless transparent andalpha blended images, just what we want. Unfortunately, saving to PNG isn’t supported out of the box. There are a number of libraries available, for example ImageTools, or the additional extension methods forWritabelBitmapEx. But with live tiles, you often want to do the update in a background agent, the encoder needs to be as small as possible. Try to keep from adding libraries. I found PNGWriter from ToolStack to be compact and it doesn’t rely on any external libraries. A small drawback may be that it doesn’t support compression but for this purpose I don’t see it as a big limitation.

With the code files in place I could easily save the image and then update the tile to use as a background image instead of the original icon. The following code block will do that for you:

A couple of things regarding saving tile images

  • If you want to do the saving in a background agent avoid using large image libraries
  • The image has to be saved in /shared/shellcontent to be available for the tile
  • When specifying the URI add isostore:/ so that the Tile knows where to read from

Smoothing it out

The result is almost the desired, all the things ended up in the right places. But there is a strange shadow, if you look close (or check the zoomed in picture) you can see a dark border where it should have been alpha transparencies:

limeorangeTheShadow

Some give up here and instead use a background from the current theme color and save it as JPG. As soon as the user change the color theme it will get ugly. For me, this is not good enough and I needed a complete solution.

The problem is with the internal representation of each pixels. Normally you would think it’s a 32bit value with 8bit for each color (RGB) and an 8bit alpha channel – ARGB32. However, to speed up composition you there is something called alpha pre-multiplication. Go ahead and read the article, it gives you a good explanation. Anyway, this is why we get the dark line effect. If you look close you can actually read about it in the MSDN documentation, it’s down there in the remarks. Don’t see it? Let me show you:

Untitled-3

I found a good snippet of code that will help out with the algorithm from the article and remove the pre-multiplication from your bitmap:

Running this just before saving the PNG will give us the end result we want. Now we have a smooth and transparent live tile for our application.

lime_doneorange_doneNoShadow

Look, no strange colors!

Final thoughts

  • The Alpha Pre-multiplication will still affect the values a little, but it will be good enough
  • Too small letters or thin lines will let the accent color bleed especially in purple avoid those
  • If you do a lot of image handling it’s not the most effective code but for most tile updates it will do

Also, I have added a sample project for you to look into that does all the above on the main tile.

基于TROPOMI高光谱遥感仪器获取的大气成分观测资料,本研究聚焦于大气污染物一氧化氮(NO₂)的空间分布与浓度定量反演问题。NO₂作为影响空气质量的关键指标,其精确监测对环境保护与大气科学研究具有显著价值。当前,利用卫星遥感数据结合先进算法实现NO₂浓度的高精度反演已成为该领域的重要研究方向。 本研究构建了一套以深度学习为核心的技术框架,整合了来自TROPOMI仪器的光谱辐射信息、观测几何参数以及辅助气象数据,形成多维度特征数据集。该数据集充分融合了不同来源的观测信息,为深入解析大气中NO₂的时空变化规律提供了数据基础,有助于提升反演模型的准确性与环境预测的可靠性。 在模型架构方面,项目设计了一种多分支神经网络,用于分别处理光谱特征与气象特征等多模态数据。各分支通过独立学习提取代表性特征,并在深层网络中进行特征融合,从而综合利用不同数据的互补信息,显著提高了NO₂浓度反演的整体精度。这种多源信息融合策略有效增强了模型对复杂大气环境的表征能力。 研究过程涵盖了系统的数据处理流程。前期预处理包括辐射定标、噪声抑制及数据标准化等步骤,以保障输入特征的质量与一致性;后期处理则涉及模型输出的物理量转换与结果验证,确保反演结果符合实际大气浓度范围,提升数据的实用价值。 此外,本研究进一步对不同功能区域(如城市建成区、工业带、郊区及自然背景区)的NO₂浓度分布进行了对比分析,揭示了人类活动与污染物空间格局的关联性。相关结论可为区域环境规划、污染管控政策的制定提供科学依据,助力大气环境治理与公共健康保护。 综上所述,本研究通过融合TROPOMI高光谱数据与多模态特征深度学习技术,发展了一套高效、准确的大气NO₂浓度遥感反演方法,不仅提升了卫星大气监测的技术水平,也为环境管理与决策支持提供了重要的技术工具。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值