我正在我的应用程序中生成一个图块,当它显示背景图像时,它用作图块的基础已失去透明度(因此它没有拾取主题颜色。
背景图片上有一个图标并且是透明的 - 当我用它作为标准瓷砖(即没有用它生成图像)时,它很好,透明度都很好..
但是当我将它用作背景图像并在其上添加我自己的容器时,它不透明,背景显示为黑色。
相关代码如下:
// [...]
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;
}
对于我设置ImageBrush的不透明度似乎没有任何区别。
如果我使用的是纯色比色透明层,那么一切都很好。不知何故,png的创建正在失去透明度。
任何想法?