Tag: graphics

如何在WPF中绘制窗口(最佳实践)?

我正在尝试编写一个类似于交互式游戏的小应用程序,我需要有一个Draw方法,它将在屏幕上绘制,但无法弄清楚如何构建WPF方法。 如果这是Winforms ,我可以使用: public void Draw (Graphics g) { } 但是对于WPF Window ,我应该在xaml中拥有什么(目前只有一个Grid ),这个Draw方法应该作为参数接收什么? 首先,我想这样做才能让它工作,然后我可以考虑如何使它更多WPF等。但现在我更感兴趣的是让它工作。

CreateGraphics和Paint事件的Graphics对象有什么区别?

有人可以解释作为pevent.Graphics传递的Graphics对象与通过调用this.CreateGraphics()返回的对象之间的区别吗?

在图片框中绘制列车时,c#中的内存不足exception

我正在尝试创建一个显示图片picturebox在线列车的应用程序 因此,要实现这一点,我创建一个worker thread来获得在线列车位置。所以我定义了线程,你可以在这里看到: private Thread workerThread = null; private delegate void UpdateListBoxDelegate(); private UpdateListBoxDelegate UpdateListBox = null; 在Form_load我称之为: UpdateListBox = new UpdateListBoxDelegate(this.UpdateStatus); // Initialise and start worker thread workerThread = new Thread(new ThreadStart(this.GetOnlineTrain)); workerThread.Start(); 我委托处理的方法是: private void UpdateStatus() { foreach (TimeTable onlineTrain in OnlineTrainList.ToList()) { if (lstSensorLeft.Count != 0 || lstSensorRight.Count != 0) { pictureBoxonlineTrain.Image […]

在图片框中绘制颜色?

在C#我有一个图片框。 我想画4种颜色。 默认为白色,红色,绿色,蓝色。 如何在这个picbox中绘制这四种颜色? 或者我应该有4个picbox? 在这种情况下,我如何设置rgb颜色?

Graphics.DrawString以printdocument宽度为中心

我试图将一个字符串放在printdocument上。 我用图像完成了以下操作并且它可以工作,但似乎对字符串不起作用。 这是我用来居中图像的代码 e.Graphics.DrawImage(logo, (e.MarginBounds.Width / 2) – (logo.Width / 2), height); 我试图居中的文本是从TabControl中的Tab提供的 using (var sf = new StringFormat()) { height = logo.Height + 15; sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; e.Graphics.DrawString(tabData.Text, new Font(this.Font.Name, 10), new SolidBrush(tabData.ForeColor), (e.MarginBounds.Width / 2) – (txtData.Width / 2), height, sf); } 我也在下面尝试过并使用string_size.Width / 2代替txtData.Width SizeF string_size = e.Graphics.MeasureString(tabData.Text, tabData.Font); […]

如何在滚动较大的缩小图片时防止图形卡顿

我有一个很大的tiff图片(5.9 Mb,13k X 16k reolution),用户可以将其加载到一个可滚动的面板中,然后他可以放大/缩小,滚动和标记点,区域等。 对于可滚动的双缓冲面板我正在使用鲍勃鲍威尔的真棒ZoomPicBox的修改该面板仅显示当前视图中的部分图片。 缩小时滚动图像时出现断断续续的情况(即使interpolationMode设置为低) 有什么可以做的(最好没有硬件加速)? 面板的绘画事件: protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if (_image == null) { base.OnPaintBackground(e); return; } //scale System.Drawing.Drawing2D.Matrix ScaleMat = new System.Drawing.Drawing2D.Matrix(_zoom, 0, 0, _zoom, 0, 0); //move to position of scrollbas ScaleMat.Translate(this.AutoScrollPosition.X / (_zoom), this.AutoScrollPosition.Y / (_zoom)); e.Graphics.Transform = ScaleMat; e.Graphics.InterpolationMode = _interpolationMode; e.Graphics.DrawImage(_image, new Rectangle(0, 0, […]

C#:是否有必要在自定义控件中处理图形元素?

我创建了一个自定义控件,覆盖了它的paint事件。 当我尝试处理我创建的图形时,它们就会从屏幕上消失。 我不需要在自定义控件中使用dispose吗? 编辑:我已经包含了一个代码片段。 为什么我不能处理从PaintEventArgs创建的dc图形对象? 我需要处理它吗? class canvas : Control { PointF mouseDown; float newX; float newY; float zoomFactor = 1F; Graphics _dc; public canvas() { this.DoubleBuffered = true; mouseDown = new PointF(0F, 0F); this.Paint += new PaintEventHandler(ctrl_Paint); } private void ctrl_Paint(object sender, PaintEventArgs e) { Graphics dc = e.Graphics; _dc = dc; dc.SmoothingMode = […]

在.net控件上绘制文本,背景为负色 – 混合

我想在其中心绘制一个百分比的进度条,但我希望文本 背景具有负 (对比)颜色。 因此,在ProgressBar的填充部分上方的文本部分将是白色的,而未填充部分的部分将是白色的。 我可以简单地通过“作弊”来做到这一点 首先绘制文本的黑色部分 绘制进度矩形(它将覆盖要隐藏的部分) 仅在进度矩形上绘制白色文本(剪切它) 在这个应用程序中,两次绘制文本的性能影响可以忽略不计,但是我感兴趣的是,如果有一些简单的方法只用两个步骤(比如让进度条以某种方式反转已绘制的文本)进行混合 。

如何使drawLine更顺畅?

我使用以下代码绘制线条: Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Black,3); g.DrawLine(p,…); // … 为什么直线是锯齿形的,根本不是直的和光滑的。 我怎么能让它变得平直和顺畅?

模拟时钟 – 在标签上绘制时钟臂

我正在使用WinForms创建一个时钟。 问题是时钟指针在我的面板/标签下面。 我试图在我的面板/标签上画手,但我没有成功。 我也尝试将我的面板/标签移到后面,将手移到前面,但也不能正常工作。 我也尝试过像panel_digital_Timer.Parent = pictureBox1制作透明面板的东西。 如何在我的面板/标签前移动时钟指针? public partial class Form1 : Form { private Bitmap bmp; private int angle = 0; private int counter_Time; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { pictureBox1.Paint += PictureBox1_Paint; bmp = Properties.Resources.Clock_Arm; //pictureBoxOverlay.BackColor = Color.Transparent; //// Change parent for overlay PictureBox… pictureBoxOverlay.Parent = […]