安卓系统的手机好不好用呢?
安卓系统的手机好不好用?
最满意答案
您可以尝试使用CombinedGeometry组合2个几何(每次)。 它具有
GeometryCombineMode
允许您指定一些逻辑组合。 在这种情况下,您需要的是GeometryCombineMode.Xor
。 将切除 Rect和Ellipse(cirlce)的交点。 以下是演示它的简单代码:DrawingVisual dv = new DrawingVisual(); using (var dc = dv.RenderOpen()) { var rect = new Rect(0, 0, 300, 200); var cb = new CombinedGeometry(GeometryCombineMode.Xor, new RectangleGeometry(rect), new EllipseGeometry(new Point(150, 100), 50, 50)); dc.DrawGeometry(Brushes.Blue, null, cb); }
我希望你知道如何渲染
DrawingVisual
。 您可以使用一些RenderTargetBitmap
将其捕获到某种BitmapSource中,然后您可以通过多种方式显示此位图。这是截图:
黑色区域表示颜色是透明的。
如果你想剪出一些复杂的图像(如绘制的文字或图像)。 您可以将
CombinedGeometry
转换为某种OpacityMask
(Brush
类型)。 我们可以把它变成DrawingBrush
,这个画笔可以用作OpacityMask
,可以传递给DrawingContext.PushOpacityMask
方法:DrawingVisual dv = new DrawingVisual(); using (var dc = dv.RenderOpen()) { var rect = new Rect(0, 0, 300, 200); var cb = new CombinedGeometry(GeometryCombineMode.Xor, new RectangleGeometry(rect), new EllipseGeometry(new Point(150, 100), 50, 50)); var mask = new DrawingBrush(new GeometryDrawing(Brushes.Blue, null, cb)); dc.PushOpacityMask(mask); dc.DrawImage(someImage, rect); dc.DrawText(new FormattedText("Windows Presentation Foundation", System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface("Lucida Bright"), 30, Brushes.Red){ MaxTextWidth = rect.Width, MaxTextHeight = rect.Height, TextAlignment = TextAlignment.Center }, new Point()); }
请注意,
rect
应该具有整个图形的大小。 然后定位孔和其他绘制的东西将是你想要的精确。最后,
DrawingVisual
还有一个名为Clip
的有用属性,它是一个Geometry
。 因此,您可以准备一些CombinedGeometry
并将其分配给DrawingVisual.Clip
属性。假设您已经拥有了
DrawingVisual
(包含一些绘制的内容,包括文本,图像......)。 以下代码将通过它打孔 ://prepare the geometry, which can be considered as the puncher. var rect = new Rect(0, 0, 300, 200); var cb = new CombinedGeometry(GeometryCombineMode.Xor, new RectangleGeometry(rect), new EllipseGeometry(new Point(150, 100), 50, 50)); //punch the DrawingVisual yourDrawingVisual.Clip = cb;
You can try using CombinedGeometry to combine 2 geometries (each time). It has
GeometryCombineMode
allowing you to specify some logic combination. In this case what you need isGeometryCombineMode.Xor
. The intersection of the Rect and the Ellipse (cirlce) will be cut out. Here is the simple code demonstrating it:DrawingVisual dv = new DrawingVisual(); using (var dc = dv.RenderOpen()) { var rect = new Rect(0, 0, 300, 200); var cb = new CombinedGeometry(GeometryCombineMode.Xor, new RectangleGeometry(rect), new EllipseGeometry(new Point(150, 100), 50, 50)); dc.DrawGeometry(Brushes.Blue, null, cb); }
I hope you know how to render the
DrawingVisual
. You can use someRenderTargetBitmap
to capture it into some kind of BitmapSource and then you have many ways to show this bitmap.Here is the screenshot:
The Black region means the color is transparent.
In case you want to cut out some complex image (such as drawn text or image). You can turn the
CombinedGeometry
into some kind ofOpacityMask
(type ofBrush
). We can turn it into aDrawingBrush
and this brush can be used asOpacityMask
which can be passed intoDrawingContext.PushOpacityMask
method:DrawingVisual dv = new DrawingVisual(); using (var dc = dv.RenderOpen()) { var rect = new Rect(0, 0, 300, 200); var cb = new CombinedGeometry(GeometryCombineMode.Xor, new RectangleGeometry(rect), new EllipseGeometry(new Point(150, 100), 50, 50)); var mask = new DrawingBrush(new GeometryDrawing(Brushes.Blue, null, cb)); dc.PushOpacityMask(mask); dc.DrawImage(someImage, rect); dc.DrawText(new FormattedText("Windows Presentation Foundation", System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface("Lucida Bright"), 30, Brushes.Red){ MaxTextWidth = rect.Width, MaxTextHeight = rect.Height, TextAlignment = TextAlignment.Center }, new Point()); }
Note that the
rect
should have the size of your whole drawing. Then positioning the hole and other drawn stuff will be exact as what you want.Finally the
DrawingVisual
also has a useful property calledClip
which is aGeometry
. So you can prepare someCombinedGeometry
and assign it toDrawingVisual.Clip
property.Suppose you already have your
DrawingVisual
(with some drawn stuff including text, images, ...). The following code will punch a hole through it://prepare the geometry, which can be considered as the puncher. var rect = new Rect(0, 0, 300, 200); var cb = new CombinedGeometry(GeometryCombineMode.Xor, new RectangleGeometry(rect), new EllipseGeometry(new Point(150, 100), 50, 50)); //punch the DrawingVisual yourDrawingVisual.Clip = cb;
相关问答
更多-
您可以尝试使用CombinedGeometry组合2个几何(每次)。 它具有GeometryCombineMode允许您指定一些逻辑组合。 在这种情况下,您需要的是GeometryCombineMode.Xor 。 将切除 Rect和Ellipse(cirlce)的交点。 以下是演示它的简单代码: DrawingVisual dv = new DrawingVisual(); using (var dc = dv.RenderOpen()) { var rect ...
-
UIKit绘图是线程安全的:你如何获得图形上下文?(UIKit drawing is thread safe: how do you get a graphics context?)[2023-08-15]
基于一些经验和基于各种文档的经验,我相信UIGraphicsPushContext()的文档是不正确的。 我相信UIGraphicsPushContext()实际上是线程安全的。 QA1637说明了这一点:“从iOS 4.0开始,在UIKit中绘制图形上下文是线程安全的,包括访问和操作当前图形堆栈 ,绘制图像和字符串以及使用颜色和辅助线程的字体对象“。 (强调我的) 我承认,假设线程安全与文档相矛盾始终是一个冒险的主张。 但我相信这是一个文档错误。 我打开了rdar:// 11161530来跟踪它。 请欺骗 ... -
那么这是一个很大的问题。 一个潜在的主要原因是验证你确切地绘制了你所需要的东西(而不是整个图像),并且将不变的位图从那些在多个层次上主动变异的区域/区域划分出来。 Well, this is a big question. One potential lead would be to verify that you draw exactly what you need (not the whole image all the time), and to divide the invariant bitmap ...
-
刷子无法正常工作,因为当您调用clearImage()时,您将context.fillStyle更改为white,还有context.moveTo(e.offsetX, e.offsetY); 这是不必要的。 看看那个重现https://jsfiddle.net/yr1ezp4x/2/ 那里你会有更多的工作。 在鼠标事件触发的内部函数中,您必须检查鼠标是否在画布上。 Brush doesn't work properly cause when you call clearImage() you are ch ...
-
你的方法是正确的。 你只是错过了一个小细节。 PDF和postscript文件通常是打印的。 打印文档需要一个边距(打印机需要抓住纸张的边缘)。 (current-ps-setup)用于纸张尺寸,边距大小和缩放。 将缩放比例设置为1并将边距大小设置为0将为您提供预期的结果。 #lang racket (require racket/draw) ;;; Begin our drawing (define w 200) (define h 200) (define setup (new ps-setup%) ...
-
单击按钮 b1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub dv.clear(); // call clear method using in your custom view } }); ...
-
无论好坏,我都使用图层: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); if (first) { // Wait for the first call to get a valid context first = NO; // Then create a CGContextRef (offlineContext ...
-
如何清除CGContextRef?(How to clear a CGContextRef?)[2021-07-03]
我假设drawingPath是一个CGPath ...你清除那个CGPath? 这可能是你的问题的原因 在清除路径的行动中,做: CGPathRelease(drawingPath); drawingPath = CGPathCreateMutable(); [self setNeedsDisplay]; 并做你通常做的正常绘图。 如果路径为空,则不会绘制任何内容 im assuming drawingPath is a CGPath ... are you clearing that CGPath? t ... -
在当前上下文中绘制弧(Drawing arc in current context)[2023-07-19]
iOS的“ 绘图和打印指南 ”中的“坐标系统和iOS绘图”中对此进行了解释: iOS的每个绘图框架都基于当前图形上下文建立默认坐标系。 在iOS中,有两种主要类型的坐标系: 左上方原点坐标系(ULO),其中绘制操作的原点位于绘图区域的左上角,正值向下和向右延伸。 UIKit和Core Animation框架使用的默认坐标系是基于ULO的。 左下原点坐标系(LLO),其中绘图操作的原点位于绘图区域的左下角,正值向上和向右延伸。 Core Graphics框架使用的默认坐标系是基于LLO的。 正角度(如M_PI ... -
你不需要preserveDrawingBuffer: true来调用readPixels 。 您需要的是在退出当前事件之前调用readPixels 。 规范说如果你调用任何影响画布的函数(gl.clear,gl.drawXXX),浏览器将在下一次复合操作后清除画布。 当复合操作发生时,由浏览器决定。 可能是在它处理了几个鼠标事件或键盘事件或点击事件之后。 订单未定义。 定义的是,在当前事件退出之前不会这样做 render read const gl = document.querySelector("ca ...