我正在尝试在 c# 中使用 Win2D 在圆圈内绘制缩放图像,但我没有这样做。
我的尝试是例如:
CanvasBitmap image;
bool resourcesLoaded = false;
public Other() {
this.InitializeComponent();
}
void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args) {
if( resourcesLoaded ) {
var halfWidth = sender.ActualWidth / 2;
var halfHeight = sender.ActualHeight / 2;
double displayScaling = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0;
double pixelWidth = halfWidth * displayScaling;
double pixelHeight = halfHeight * displayScaling;
var scaleEffect = new ScaleEffect() {
Source = image,
Scale = new Vector2() {
X = ( float ) ( pixelHeight / image.Size.Height ),
Y = ( float ) ( pixelHeight / image.Size.Height ),
}
};
var blurEffect = new GaussianBlurEffect() {
Source = scaleEffect,
BlurAmount = 5f
};
args.DrawingSession.FillCircle( new System.Numerics.Vector2() { X = ( float ) halfWidth, Y = (float) halfHeight },
(float) halfHeight/2,
new CanvasImageBrush( sender, blurEffect ) {
SourceRectangle = new Rect(0,0, scaleEffect.GetBounds(sender).Width, scaleEffect.GetBounds( sender ).Height)
} );
}
}
private void canvasControl_CreateResources(CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args) {
args.TrackAsyncAction( CreateResources( sender ).AsAsyncAction() );
}
private async Task CreateResources(CanvasControl sender) {
image = await CanvasBitmap.LoadAsync( canvasControl, new Uri( "ms-appx:///Imgs/test.jpg" ) );
resourcesLoaded = true;
sender.Invalidate();
}
发生的情况是图像似乎是在窗口的 X=0 和 Y=0 位置绘制的(画布使用所有窗口),所以我的圆圈在窗口的中间,然后只有一点图像被绘制我希望我的图像被放置在圆的中心。
所以问题是: - 我的规模是否正确完成?为什么要除以 96?我可以从系统中读取这个吗?- 是否可以只模糊图像的边缘?- 我怎样才能在圆圈的中心绘制我的图像?
谢谢