我试图在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?我可以从系统中读到这个吗? - 是否可以仅模糊图像的边缘? - 我如何在圆圈的中心绘制我的图像?
由于