gpt4 book ai didi

c# - 如何在绘图上下文工具上显示阴影

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:05 25 4
gpt4 key购买 nike

实际上我正在使用 drawingContext.DrawRectangle 方法在 Canvas 上绘制矩形。我想在矩形上添加阴影效果..

drawingContext.DrawRectangle(new SolidColorBrush(graphicsObjectFillColor),
new Pen(new SolidColorBrush(ObjectColor), ActualLineWidth),
Rectangle);

或者我正在使用它来添加阴影..

 DropShadowEffect effect = new DropShadowEffect();
effect = new DropShadowEffect { Color = Colors.Black, Direction = -45, Opacity = 0.5, ShadowDepth = 4};
this.Effect = effect;

阴影正在显示,但添加了在图像上绘制所有工具的时间,shodow 没有显示我正在使用

                    DrawingVisual vs = new DrawingVisual();
DrawingContext dc = vs.RenderOpen();

// Draw image
dc.DrawImage(image.Source, rect);

double scale = width / image.Source.Width;

// Keep old existing actual scale and set new actual scale.
double oldActualScale = drawingCanvas.ActualScale;

drawingCanvas.ActualScale = oldActualScale;

// Remove clip in the canvas - we set our own clip.
drawingCanvas.RemoveClip();

// Prepare drawing context to draw graphics
rect = new Rect(left, top, width, height);
dc.PushClip(new RectangleGeometry(rect));

double horizontalScale = Math.Abs((positionDrawingCanvas.X) - (positionImage.X));
double verticalScale = Math.Abs((positionDrawingCanvas.Y) - (positionImage.Y));

double difX = 0.0;
double difY = 0.0;
//if (horizontalScale != 0 && verticalScale != 0)
//{
// //horizontalScale = Math.Abs((positionDrawingCanvas.X + Math.Abs((positionImage.X / sliderScale.Value - positionImage.X))) - (positionImage.X));
// //verticalScale = Math.Abs((positionDrawingCanvas.Y + Math.Abs((positionImage.Y / sliderScale.Value - positionImage.Y))) - (positionImage.Y));
// difX = (positionImage.X - positionImage.X / sliderScale.Value);
// difY = (positionImage.Y - positionImage.Y / sliderScale.Value);
//}

dc.PushTransform(new TranslateTransform(difX + left - horizontalScale, difY+top - verticalScale));
dc.PushTransform(new ScaleTransform(1, 1));

// Ask canvas to draw overlays
drawingCanvas.Draw(dc);

// Restore old actual scale.
drawingCanvas.ActualScale = oldActualScale;

// Restore clip
drawingCanvas.RefreshClip();

dc.Pop();
dc.Pop();
dc.Pop();

dc.Close();
width = (Utilityhelper.GetDIPIndependentHorizontal(rect.Width));
height = (Utilityhelper.GetDIPIndependentVertical(rect.Height));

bmp = new RenderTargetBitmap((int)width, (int)(height), Utilityhelper.graphics.DpiX, Utilityhelper.graphics.DpiY, PixelFormats.Default);
//bmp = new RenderTargetBitmap((int)(scale * (rect.Width)), (int)(scale * (rect.Height)), scale * 96, scale * 96, PixelFormats.Default);
bmp.Render(vs);
sliderScale.Value = oldScale;
//imageBackground.Stretch = Stretch.Uniform;
//drawingCanvas.Width = (Utilityhelper.GetDIPDependentHorizontal(drawingCanvas.Width));
//drawingCanvas.Height = (Utilityhelper.GetDIPDependentVertical(drawingCanvas.Height));
return bmp;

最佳答案

你只需要改变你的渲染方法

RenderTargetBitmap bmp = new RenderTargetBitmap((int)width, (int)(height), DpiX, DpiY, PixelFormats.Default);
BitmapSource source = null;

if (bmp != null)
{
bmp.Render(image);
bmp.Render(drawingCanvas);
source = bmp;
}

关于c# - 如何在绘图上下文工具上显示阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26710579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com