Win2D 投影效果 ShadowEffect
标签:create class fill -- asc namespace command gen offsetx
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using Microsoft.Graphics.Canvas.UI.Xaml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Shapes;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace Win2DDemo
{
///
/// An empty page that can be used on its own or navigated to within a Frame.
///
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
CanvasBitmap bitmap;
void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
//CanvasBitmap bitmap =await CanvasBitmap.LoadAsync(sender, @"Assets\LockScreenLogo.scale-200.png");
//实例化阴影特效
ShadowEffect shadowEffect = new ShadowEffect
{
Source = bitmap,
BlurAmount = 60.0f,
ShadowColor = Colors.Black,
};
//实例化变换特效
Transform2DEffect transform2DEffect = new Transform2DEffect
{
Source = shadowEffect,
TransformMatrix = Matrix3x2.CreateTranslation(new Vector2(10, 10)),
};
//实例化透明特效
OpacityEffect opacityEffect = new OpacityEffect
{
Source = transform2DEffect,
Opacity = 0.82f,
};
//实例化结合特效
CompositeEffect effect2 = new CompositeEffect
{
Sources ={
opacityEffect ,
bitmap,
}
};
args.DrawingSession.DrawImage(effect2, new Vector2(111,111));
//CanvasCommandList cl = new CanvasCommandList(sender);
//using (CanvasDrawingSession clds = cl.CreateDrawingSession())
//{
// clds.FillRectangle(new Rect(100, 100, 100, 100), Colors.White);
// clds.DrawImage(bitmap, new Rect(10, 10, 100, 100));
//}
//ShadowEffect effect = new ShadowEffect()
//{
// Source = cl,
// BlurAmount = 0.5f,
// //ShadowColor = Colors.Black,
//};
//args.DrawingSession.DrawImage(effect);
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
{ //Microsoft.Toolkit.Uwp.UI.Controls.DropShadowPanel
if (this.canvasControl != null)
{
this.canvasControl.RemoveFromVisualTree();
this.canvasControl = null;
}
}
private void CanvasControl_CreateResources(CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
{
Task task = this.CreateResourcesAsync(sender);
IAsyncAction action = task.AsAsyncAction();
args.TrackAsyncAction(action);
}
private async Task CreateResourcesAsync(CanvasControl sender)
{
bitmap = await CanvasBitmap.LoadAsync(sender, "Assets/1.png");
}
}
}
另外Microsoft.Toolkit.Uwp.UI.Controls 里 的 DropShadowPanel 也行,但是不好用感觉。
Win2D 投影效果 ShadowEffect
标签:create class fill -- asc namespace command gen offsetx
原文地址:https://www.cnblogs.com/wgscd/p/14637927.html
评论