Tag: 图形

只调用一个Paint事件

我的问题是我有8个图片盒,其中只有一个是一次调用他们的绘图方法。 我的代码有点太大,所以我尽量把它缩小到受影响的部分。 我最好的猜测是,它不是我的代码中的错误,而是对绘制事件如何工作的误解。 我有一个inheritance自PictureBox的类,而不是Picturebox。 唯一的变化是构造函数 using System.Drawing; using System.Windows.Forms; public class DrawingSurface : PictureBox { public DrawingSurface(Rectangle bounds) : base() { base.Dock = DockStyle.Fill; base.SizeMode = PictureBoxSizeMode.Zoom; //I set the size and bounds which is probably redundant because //I was trying random things to fix the problem base.Size = new Size(bounds.Width, bounds.Height); base.Bounds = bounds; […]

在计算2D空间中两点之间的对角线交点时如何确定+/-符号?

这是另一个问题的分支,与Keith Randall对问题的回答有关。 请快速查看图像,看看下面的function是做什么的。 简而言之,如果x2 != x1和y2 != y1则2D网格上的任何两个点都将具有两个对角交点。 我实现了以下function,但无法弄清楚如何确定从哪个单元中减去delta以及添加到哪个单元。 因此,对于某些坐标,结果是准确的,而对于其他坐标,它们是相反的。 // This class is the same as [Point] except // it uses BigInteger instead of Int32 types. public class Cell { System.Numerics.BigInteger X = 0; System.Numerics.BigInteger Y = 0; } public List GetIntersections (Cell c1, Cell c2) { List cells = new List(); System.Numerics.BigInteger delta […]

ASP.NET Core中的服务器端图形

我最近将ASP.NET MVC应用程序从ASP.NET升级到ASP.NET Core。 在我的控制器操作中,我有一段依赖System.Drawing创建个人资料图片的代码 using (FileStream stream = new FileStream(HttpContext.Server.MapPath($”~/Content/UserFiles/{AuthenticatedUser.Id.ToString()}.jpg”), FileMode.OpenOrCreate)) { Image image = Image.FromStream(model.DisplayPicture.InputStream); image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); } 图像数据作为Base64编码图像发布到服务器 data:image/png;base64,…. 由于.NET Core中没有System.Drawing ,是否还有其他库可以实现这一目标?

在.NET中组合多个PNG8图像的最简单方法

我试图将一堆8位PNG图像组合成一个C#中较大的PNG图像。 奇怪的是,这似乎特别困难。 由于Graphics不支持索引颜色,你不能使用它,所以我尝试构建一个非索引的Bitmap(使用Graphics)并将其转换为索引颜色位图。 转换很好,但我无法弄清楚如何设置输出图像的调色板。 它默认为一些预定义的调色板,与我正在寻找的内容几乎没有关系。 所以: 有没有办法控制位图调色板? 或者是否有另一种方法(例如System.Windows.Media.Imaging.WriteableBitmap)可以支持这个? Re:WriteableBitmap:我似乎无法在网上找到任何关于如何在这种情况下组合PNG的例子,或者即使尝试它也没有任何意义。

DPI图形屏幕分辨率像素WinForm PrintPageEventArgs

对于运行我的应用程序的任何显示器,Dpi点如何与像素相关? int points; Screen primary; public Form1() { InitializeComponent(); points = -1; primary = null; } void OnPaint(object sender, PaintEventArgs e) { if (points < 0) { points = (int)(e.Graphics.DpiX / 72.0F); // There are 72 points per inch } if (primary == null) { primary = Screen.PrimaryScreen; Console.WriteLine(primary.WorkingArea.Height); Console.WriteLine(primary.WorkingArea.Width); Console.WriteLine(primary.BitsPerPixel); } } 我现在拥有我需要的所有信息吗? 我可以使用上面的任何信息来了解1200像素的长度吗?

如何生成/计算十二面体的顶点?

如何在算法上生成十二面体的顶点? 我希望四面体的质心在(0, 0, 0) 。

突出显示剪切工具之类的效果

我正在创建一个类似于Windows 7剪切工具的新剪切工具。 但是我不能让突出效果同样有效。 例如,剪切工具高亮显示如下:(突出显示在白色背景上非常明亮,看起来它没有透明度 我的剪切工具突出显示如下: 我确定使用的颜色是相同的(255,255,0),alpha通道为110.如果我降低透明度,那么它只会覆盖下面的文本。 我的剪辑是在白色的顶部应用透明度,因为窗口剪切工具似乎更好地融合了它。 我在这做错了什么? 我用于突出显示注释的代码是: using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Sicon.Snipper.Annotations { /// /// Highlight Annotation /// public class HighlightAnnotation : BaseAnnotation { #region Members protected Rectangle _selection = Rectangle.Empty; protected const int _transparancyAlpha = 110; private Brush _brush; #endregion Members #region Properties […]

c#如何使用图形路径制作平滑的弧形区域

我正在尝试用圆边制作标签控件。 这是我在inheritance自Label的myclass中的OnPaint()重写方法中的代码。 protected override void OnPaint(PaintEventArgs e) { e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle, GradientColor1, GradientColor2, 90); e.Graphics.FillRectangle(brush, new Rectangle(new Point(0, 0), new Size(this.Width, this.Height))); using (GraphicsPath gp = new GraphicsPath()) { gp.AddArc(new Rectangle(new Point(0, 0), new Size(this.Height, this.Height)), 90, 180); gp.AddLine(new Point(this.Height / […]

面板上的画线没有显示出来

我有一个名为panel1的Panel,我正在尝试使用以下代码在我的panel1上画一条线: Graphics g = panel1.CreateGraphics(); var p = new Pen(Color.Black, 3); var point1 = new Point(234,118); var point2 = new Point(293,228); g.DrawLine(p, point1, point2); 但没有任何东西出现。 有任何想法吗? 这是一个Windows窗体。

使用graphics.DrawImage进行非平滑的Upscaling

我正在网格中绘制一些图像。 图像保存为16x16px pngs。 但是,我后来决定将网格的大小增加到32x32px。 当我使用以下代码时: graphics.DrawImage(image, Xdraw, Ydraw, 32, 32); 其中image是从png加载的Image,而Xdraw和Ydraw是在上面某处决定的左上角。 图像稍微模糊,因为.DrawImage使用双三次(或其他平滑函数)来放大图像。 我希望它关闭平滑,所以我可以保留硬边。 这可能吗?