我正在尝试在 Silverlight 中用某种颜色覆盖 WriteableBitmap。我有一个黑白基本图像,我用它来为新的合成图像创建较小的 WriteableBitmap 图像,并且我想在将其添加到之前用某种颜色覆盖源图像剪切的黑色或白色部分合成图像。
我现在正在做的是:
var cutOut = new WriteableBitmap(8, 14);
/*
cut out the image here
*/
cutOut.Render(sourceImage, transform); // sourceImage is the base image
cutOutImage.Source = cutOut; // cutOutImage is an Image element in XAML
compositeImage.Render(cutOutImage, transform2); // compositeImage is the final WriteableBitmap that is shown on screen
我尝试了 http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/ 并使用来自的扩展方法hxxp://writeablebitmapex.codeplex.com/,但在将其渲染到compositeImage之前,我似乎无法在cutOut图像上获得颜色叠加。
有谁知道有一个好的方法来做到这一点?
提前致谢。
I'm trying to overlay a WriteableBitmap with a certain color in Silverlight. I have a black and white base image, which I'm using to create smaller WriteableBitmap images for a new composite image and I want to overlay either the black or white part of the source image cut-out with a certain color before adding it to the composite image.
What I'm doing now is:
var cutOut = new WriteableBitmap(8, 14);
/*
cut out the image here
*/
cutOut.Render(sourceImage, transform); // sourceImage is the base image
cutOutImage.Source = cutOut; // cutOutImage is an Image element in XAML
compositeImage.Render(cutOutImage, transform2); // compositeImage is the final WriteableBitmap that is shown on screen
I tried the methods on http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/ and using the extension methods from hxxp://writeablebitmapex.codeplex.com/, but I cannot seem to get a color overlay on the cutOut image before rendering it to the compositeImage.
Does anyone know of a good method to do this?
Thanks in advance.
发布评论
评论(1)
只是一个快速猜测,但是您在执行 WriteableBitmap.Render(...) 之后尝试过使用 WriteableBitmap.Invalidate() 吗?
除此之外,您可能想尝试将图像渲染到临时 WriteableBitmap,然后使用 WriteableBitmap.Pixels 将该临时图像复制到新位图上。在该新位图上,您应该能够执行图像操作。
干杯,亚历克斯
just a quick guess, but have you tried playing around with WriteableBitmap.Invalidate() after doing WriteableBitmap.Render(...)?
Apart from that, you might want to try rendering your image to a temporary WriteableBitmap and then copy that temporary one onto a new bitmap using WriteableBitmap.Pixels. On that new bitmap, you should be able to perform image manipulations.
Cheers, Alex