1
我從我的應用程序中生成一個瓷磚,當它顯示背景圖像時,它使用的瓷磚基礎已經失去了它的透明度(因此它沒有選擇主題顏色Windows電話生成瓷磚 - 似乎不能讓它透明
背景圖片上有一個圖標,並且是透明的 - 當我用它作爲標準的Tile(即不用它生成圖片)時,它的罰款和透明度都很好..
但是,當我用它作爲背景圖像並將其自己的容器添加到它上面時,它的透明背景顯示爲黑色。
相關的代碼如下:
// [...]
var container = new Grid();
if (isWide)
{
container = CreateContainerWide(tileInfo);
}
else
{
container = CreateContainerMedium(tileInfo);
}
// Add the background
container.Background = new ImageBrush
{
ImageSource = background,
Opacity = opacity
};
// Force the container to render itself
container.Arrange(new Rect(0, 0, width, height));
// Write the image to disk and return the filename
return WriteShellTileUIElementToDisk(container, baseFileName);
}
static string WriteShellTileUIElementToDisk(UIElement element, string baseFileName)
{
var wb = new WriteableBitmap(element, null);
// All content must be in this sub-folder of IsoStore
string fileName = SharedImagePath + baseFileName + ImageExtension;
var stream = new IsolatedStorageFileStream(fileName, System.IO.FileMode.Create, Isf);
// Write the JPEG using the standard tile size
// Sometimes the bitmap has (0,0) size and this fails for unknown reasons with an argument exception
if (wb.PixelHeight > 0)
wb.SaveJpeg(stream, wb.PixelWidth, wb.PixelHeight, 0, JpegQuality);
else
{
Debug.WriteLine("Can't write out file because bitmap had 0,0 size; not sure why");
// indicate that there is an issue
fileName = null;
}
stream.Close();
// Return the filename
return fileName;
}
似乎並沒有什麼差別,以什麼我設置了圖像刷到的不透明度。
如果我使用比透明層更純的顏色,那麼它就很好。不知何故,PNG的創建正在失去透明度。
任何想法?
- 感謝
好吧..我正在創建一個JPEG,這不會保存透明度... – Peter 2013-04-09 18:22:26