Xaml Windows 8应用商店中的模糊效果?
对于Windows 8应用商店应用程序,如何在XAML中向UI元素(如Xaml Windows 8应用商店中的模糊效果?,xaml,windows-8,microsoft-metro,Xaml,Windows 8,Microsoft Metro,对于Windows 8应用商店应用程序,如何在XAML中向UI元素(如堆栈面板或矩形)添加模糊效果 我在想WPF中的BlurEffect。任何解决方案都应该适合动画,或者至少每秒更新多次。您可以使用库来模糊和写入图像 它可能看起来像这样: // Blit a bitmap using the additive blend mode at P1(10, 10) writeableBmp.Blit(new Point(10, 10), bitmap, sourceRect, Colors.White
堆栈面板
或矩形
)添加模糊效果
我在想WPF中的BlurEffect
。任何解决方案都应该适合动画,或者至少每秒更新多次。您可以使用库来模糊和写入图像
它可能看起来像这样:
// Blit a bitmap using the additive blend mode at P1(10, 10)
writeableBmp.Blit(new Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);
或者,您可以编写自己的代码(或使用其他人编写的代码),类似于:
如果我没有
位图
,这是否有效?全屏以60 fps的速度运行这台机器的性能如何?哦。。。你想给什么东西做动画?我建议使用DirectX。使用控件可能无法获得所需的性能。看,我可能会动画它,是的,但希望它将是如此简单,它可以做到不诉诸DirectX,因为这将需要比我们熟悉的多得多的工作。要设置动画,你需要做的就是覆盖模糊和未模糊的图像,然后慢慢淡入淡出。我不会在模糊和未模糊之间设置动画。被模糊的形状将会改变。
private static Bitmap Blur(Bitmap image, Rectangle rectangle, Int32 blurSize)
{
Bitmap blurred = new Bitmap(image.Width, image.Height);
// make an exact copy of the bitmap provided
using(Graphics graphics = Graphics.FromImage(blurred))
graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height),
new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
// look at every pixel in the blur rectangle
for (Int32 xx = rectangle.X; xx < rectangle.X + rectangle.Width; xx++)
{
for (Int32 yy = rectangle.Y; yy < rectangle.Y + rectangle.Height; yy++)
{
Int32 avgR = 0, avgG = 0, avgB = 0;
Int32 blurPixelCount = 0;
// average the color of the red, green and blue for each pixel in the
// blur size while making sure you don't go outside the image bounds
for (Int32 x = xx; (x < xx + blurSize && x < image.Width); x++)
{
for (Int32 y = yy; (y < yy + blurSize && y < image.Height); y++)
{
Color pixel = blurred.GetPixel(x, y);
avgR += pixel.R;
avgG += pixel.G;
avgB += pixel.B;
blurPixelCount++;
}
}
avgR = avgR / blurPixelCount;
avgG = avgG / blurPixelCount;
avgB = avgB / blurPixelCount;
// now that we know the average for the blur size, set each pixel to that color
for (Int32 x = xx; x < xx + blurSize && x < image.Width && x < rectangle.Width; x++)
for (Int32 y = yy; y < yy + blurSize && y < image.Height && y < rectangle.Height; y++)
blurred.SetPixel(x, y, Color.FromArgb(avgR, avgG, avgB));
}
}
return blurred;
}
BitmapImage iSrc
var array = new int[iSrc.PixelWidth * iSrc.PixelHeight]
var rect = new Int32Rect(0, 0, iSrc.PixelWidth, iSrc.PixelHeight)
iSrc.CopyPixels(rect, array, iSrc.PixelWidth * 4, 0)