制作一个用于分配的随机艺术生成器。我们应该随机弹出正方形,但我不知道如何绘制正方形。这就是我到目前为止所拥有的
function drawSquare(canvas, context, color){
var x= Math.floor(Math.random()*canvas.width);
var y= Math.floor(Math.random()*canvas.height);
context.beginPath();
context.fillStyle = color;
context.fillRect (x,y, canvas.width, canvas.height)
}
Run Code Online (Sandbox Code Playgroud) 我一直试图在C#中绘制一个带有透明孔和渐变边缘的环(厚度环),但收效甚微.有没有人对如何做到这一点有任何建议?
这是一个很好的Blend Utility
这是最终结果 - 感谢BlueMonkMN
Rectangle GetSquareRec(double radius, int x, int y)
{
double r = radius;
double side = Math.Sqrt(Math.Pow(r, 2) / 2);
Rectangle rec = new Rectangle(x - ((int)side), y - ((int)side), (int)(side * 2) + x, (int)(side * 2) + y);
return rec;
}
void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics gTarget = e.Graphics;
gTarget.SmoothingMode = SmoothingMode.AntiAlias;
GraphicsPath pTemp = new GraphicsPath();
Rectangle r = GetSquareRec(200, 225, 225);
pTemp.AddEllipse(r);
pTemp.AddEllipse(GetSquareRec(50, 225, 225));
Color[] …Run Code Online (Sandbox Code Playgroud) GDK库的确切功能是什么?Cairo如何适应?它们是竞争技术还是互补技术?他们中的一个是否以任何方式依赖另一个?
我想绘制一个带有图形框架(Qt)的二叉树,如下所示:
9
/ \
1 10
/ \ \
0 5 11
/ / \
-1 2 6
Run Code Online (Sandbox Code Playgroud)
但是我为每个节点设置X和Y都有问题,你是否知道设置和固定位置?(我只有每个节点的高度和左 - 儿童和右儿童)
我在某个地方为自定义组合框找到了一些代码,用圆角绘制,渐变背景和投影.我认为它看起来很不错,所以我调整它以使用标签控件做同样的事情.
奇怪的是,当我将其中一个控件放到表单设计器上时,默认属性被设置并且它绘制得很好 - 我在表单上放了多个副本,它们都很好.
但是,当我尝试在运行时添加几个控件时,实际上只绘制了第一个版本.其他人最终只是空白的白盒子.
我真的不知道该怎么做.
标签代码如下(抱歉 - 很长!)
public class LabelEx : Label
{
private System.Drawing.Color _BorderColor = Color.FromArgb(141, 178, 227);
private float _BorderWidth = 1;
private System.Drawing.Color _BackgroundColor = Color.White;
private System.Drawing.Color _BackgroundColorGradient = Color.FromArgb(227, 235, 246);
private ControlGradientMode _BackgroundGradientMode = ControlGradientMode.Vertical;
private int _CornerRadius = 5;
private RoundedControlCorners _Corners = RoundedControlCorners.All;
private int _DropShadowThickness = 3;
private bool _DropShadowVisible = true;
private System.Drawing.Color _ShadowColor = Color.FromArgb(50, Color.Black);
private ControlStyles _LabelStyle = ControlStyles.Extended;
public enum ControlStyles
{
Standard, …Run Code Online (Sandbox Code Playgroud) 我有一个特定的目标:画一个路网.所以我有一些点(x,y),我想连接它们(使用drawLine函数).因为他们的数量(大约2-3百万)我需要在另一个线程中做,所以有一个问题我应该怎么做?我有一个特殊的绘图区域 - QLabel.我试图通过主线程中的QPixmap来做到这一切都很好,但当我尝试通过另一个线程中的信号/插槽来做它没有图像出现:(
实际上,当我将坐标转换为GUI坐标时,它们变为小数,因此我不知道如何绘制它们,因为drawLine函数具有整数参数:(int x1,int y1,int x2,int y2).
这就是我创建另一个线程的方式(我只需要运行一个函数,所以这是我认为最好的方法)
QtConcurrent::run(this,&MainWindow::parseXML)
希望你会帮助我,因为我会变得疯狂%)
PS我读过多线程绘图不支持QPixmap.所以现在我不知道该怎么做.
QPainter can be used in a thread to paint onto QImage, QPrinter, and QPicture paint devices. Painting onto QPixmaps and QWidgets is not supported. On Mac OS X the automatic progress dialog will not be displayed if you are printing from outside the GUI thread.