首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WriteableBitmapEx.DrawRectangle厚度?

WriteableBitmapEx.DrawRectangle厚度?
EN

Stack Overflow用户
提问于 2013-01-27 10:52:14
回答 3查看 2.9K关注 0票数 4

如何更改使用WriteableBitmapEx.DrawRectangle扩展方法绘制的矩形轮廓的厚度/权重?我用来绘制矩形的代码是:

代码语言:javascript
运行
复制
WriteableBitmap wbmp = new WriteableBitmap(bmp);
wbmp.DrawRectangle(0, 0, 480, 360, Colors.DarkGray);

使用此代码,以1px绘制的矩形的厚度。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-01-27 16:51:20

WritableBitmapEx.Add Thickness param for shapes解决方法

代码语言:javascript
运行
复制
//Original points for line
int x1 = (int)pts[0].X;
int y1 = (int)pts[0].Y;
int x2 = (int)pts[1].X;
int y2 = (int)pts[1].Y;

//Parallel line code from http://stackoverflow.com/questions/2825412/draw-a-parallel-line var L = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
var offsetPixels = 4;//Line "thickness"
// This is the second line will be parallel to the first
int x1p = (int)(x1 + offsetPixels * (y2 - y1) / L);
int x2p = (int)(x2 + offsetPixels * (y2 - y1) / L);
int y1p = (int)(y1 + offsetPixels * (x1 - x2) / L);
int y2p = (int)(y2 + offsetPixels * (x1 - x2) / L);

//writeableBmp.DrawLine(x1, y1, x2, y2, Colors.Red);
//writeableBmp.DrawLine(x1p, y1p, x2p, y2p, Colors.Blue);
//Create closed filled polygon for "thick line"
writeableBmp.FillPolygon(new int[] { x1, y1, x2, y2, x2p, y2p, x1p, y1p, x1, y1 }, Colors.Red);
票数 3
EN

Stack Overflow用户

发布于 2014-01-27 12:30:49

这里有一个很好的变通方法,使用来自‘Rectangle’的不太为人所知的'inflate‘方法:

代码语言:javascript
运行
复制
int pen_thickness = 5;

Rectangle original_rect = new Rect(0, 0, 480, 360); // using the poster's original values

for(int i = 0; i < pen_thickness; i++)
{
    Rectangle bigger_rect = Rectangle.Inflate(original_rect, i, i);
    wbmp.DrawRectangle(Pens.DarkGray, bigger_rect);
}

这将创建一个从最初查找的矩形展开的矩形。也可以进行快速修改,使厚度向内扩展一半(充气时为负值),向外扩展一半(充气时为正值)。

票数 0
EN

Stack Overflow用户

发布于 2017-02-13 12:24:38

创建了以下...适用于WriteableBitmapEx

代码语言:javascript
运行
复制
private static void DrawRectangle(WriteableBitmap bitmap, 
    int left, int top, int width, int height, Color color, int thinkness)
{
    var x1 = left;
    var y1 = top;
    var x2 = left + width;
    var y2 = top + height;

    bitmap.DrawRectangle(x1, y1, x2, y2, color);

    for (var i = 0; i < thinkness; i++)
    {
        bitmap.DrawRectangle(x1--, y1--, x2++, y2++, color);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14543961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档