Tag: system.drawing

如何在C#中用鼠标选择PictureBox.Image上的区域

我只是想在我的picturebox.image上做一个选择,但这比一些有点烦人的情况变得更糟。 我想到了主要图片框上的另一个图片框,但它对我来说似乎很懒散。 我需要知道是否有一种方法可以在picturebox.image上创建一个选择区域(它将是半透明的蓝色区域),我将用鼠标绘制它并且它不应该改变我正在处理的图像。 样品: // Start Rectangle // private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { // Determine the initial rectangle coordinates… RectStartPoint = e.Location; Invalidate(); } // Draw Rectangle // private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button != MouseButtons.Left) return; Point tempEndPoint = e.Location; Rect = new Rectangle( Math.Min(RectStartPoint.X, tempEndPoint.X), Math.Min(RectStartPoint.Y, tempEndPoint.Y), Math.Abs(RectStartPoint.X […]

执行2个位图的重叠检测

我有一个自定义的图片框控件,允许在主图像上单独拖动2位图,从而允许用户选择2位图的位置。 对于第一个位图 Point src = e.Location; PointF ratio = new PointF((float)src.X / ClientSize.Width, (float)src.Y / ClientSize.Height); LaunchOrigin.textratio = ratio; Point origin = new Point((int)(backupbit1.Width * ratio.X), (int)(backupbit1.Height * ratio.Y)); LaunchOrigin.textorigin = origin; point.X = src.X – origin.X; point.Y = src.Y – origin.Y; 对于第二个位图 Point src = e.Location; PointF ratio = new PointF((float)src.X / Width, (float)src.Y […]

我怎样才能清楚地使用DrawString?

我需要使用DrawString方法使用Graphics类绘制一个字符串。 但是图像有一些黑色像素,而不是确切的颜色。 我怎样才能清楚地画出来? public Image Ciz() { Color renk = Color.FromArgb(255, 133, 199); Bitmap result = new Bitmap(KutuBoyutu.Genislik, KutuBoyutu.Yukseklik); result.SetResolution(100, 100); Graphics g = Graphics.FromImage(result); g.SmoothingMode = SmoothingMode.HighQuality; Brush drawBrush = new SolidBrush(renk); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; Rectangle rect1 = new Rectangle(0, 0, result.Width, result.Height); Font font = […]

无法添加System.Drawing.dll引用

好的,所以我在过去的4个小时内遇到了这个bug,我不知道该怎么做.. 我正在使用Visual Studio Community 2017,我打开了Consol App(.net core)项目。 我也在使用Windows 8.1操作系统。 我想使用System.Drawing命名空间中的Image并且它一直给我错误:“找不到类型或命名空间名称’Image’(你是否缺少using指令或程序集引用?)” 我从https://www.dllme.com/dll/files/system_drawing_dll.html (到桌面)下载了System.Drawing.dll,然后右键单击右侧项目 – > add-> Reference ..-> Browse ..-> System.Drawing.dll->好的,然后我在项目依赖项 – > Assemblies-> System.Drawing项目中(在解决方案资源管理器中)看到,所以我猜它的工作正常吗?! 我仍然得到相同的错误,不能使用System.Drawing命名空间,任何建议? using System; using System.Net.Sockets; using System.Drawing; namespace client2 { class Program { static void Main(string[] args) { try { //read image Image image = new Image(“C:\\image\\amir.jpg”); } } } }

在图像上绘制文本

我之前从未使用过绘画,我有一点问题。 我似乎无法使此代码的输出工作。 该文件正在保存,但它没有在文本上绘图。 任何人都可以看到我可能做错了什么? 编辑:一个愚蠢的错误 – 图像的背景是白色的(刷子颜色是!)。 然而,正如我所料,文本并未居中。 任何想法为什么SO? 🙂 编辑:图片如下。 谢谢 Bitmap myBitmap = new Bitmap(@”C:\Users\Scott\desktop\blank.bmp”); Graphics g = Graphics.FromImage(myBitmap); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.DrawString(“My\nText”, new Font(“Tahoma”, 20), Brushes.White, new PointF(0, 0)); StringFormat strFormat = new StringFormat(); strFormat.Alignment = StringAlignment.Center; strFormat.LineAlignment = StringAlignment.Center; g.DrawString(“My\nText”, new Font(“Tahoma”, 20), Brushes.White, new RectangleF(0, 0, 500, 500), strFormat); myBitmap.Save(@”C:\Users\Scott\desktop\blank1.bmp”);

wpf – 我可以在wpf中使用System.Drawing吗?

我将图像保存在数据库中。 ..但如何从数据库中检索该图像..当我尝试使用system.drawing ..它显示错误..一些ppl说我不能在wpf中使用system.drwa ..甚至不是dll文件.. 我的代码是 private void btnShow_Click(object sender, RoutedEventArgs e) { DataTable dt2 = reqBll.SelectImage().Tables[0]; byte[] data = (byte[])dt2.Rows[0][1]; MemoryStream strm = new MemoryStream(); strm.Write(data, 0, data.Length); strm.Position = 0; System.Drawing.Image img = System.Drawing.Image.FromStream(strm); BitmapImage bi = new BitmapImage(); bi.BeginInit(); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); bi.StreamSource = ms; bi.EndInit(); ImgBox.Source […]

Make + y UP,Move Origin C#System.Drawing.Graphics

我希望原点位于我窗口的中心。 ______________ | ^ | | | | | Ø—–> | | | | ____________ | .NET希望它位于左上角。 _____________> | | | | | | | | V ____________ | 点网和我正在努力相处.. 有没有人知道如何在C#中使用Graphics对象? Graphics.TranslateTransform不会这样做,因为它会使坐标翻转过来。 结合这个Graphics.ScaleTransform(1,-1)并不令人满意,因为这会使文本显示为颠倒。

如何缩放在矩形中绘制的填充样式?

我正在使用.Net绘图来绘制图表。 它本质上是一个堆积条形图。 我遇到的问题是我想减少阴影样式中的线条数量,这样就可以将其缩小以使其更清晰。 我环顾四周,但没有遇到任何可以帮助我的事情。 我绘制一个矩形,然后用一个舱口盖填充它,但由于图像尺寸,影院填充变得不那么清晰。 谢谢你的任何建议。 hatchStyles和brush类型存储在db中,我使用辅助函数来返回它们。 所以我绘制矩形,在获得画笔后,我填充矩形。 基本上我想扩大舱口填充,如果可以的话。 g.DrawRectangle(gridpen, startX, startY, BOREHOLE_RECT_WIDTH, layerRectHeight); brush = GetBoreholeBrush(l.SoilTypeMatrixLevel1Id.PrimaryBrushType, l.SoilTypeMatrixLevel1Id.PrimaryFillStyle, l.SoilTypeMatrixLevel1Id.PrimaryColour); g.FillRectangle(brush, startX, startY, BOREHOLE_RECT_WIDTH, layerRectHeight); 和getBrush函数; 画笔类型,阴影样式和颜色存储在db中并用于创建返回的画笔: //=================================== private Brush GetBoreholeBrush(string BrushType, string HatchStyle, string Colour) //=================================== { //Decide on what brush type has been chosen. Brush brush; if (BrushType.ToLower() == BrushTypes.HatchBrush.ToString().ToLower()) { brush = new […]

如何判断两个多边形是否相交?

想象一下,我有4个点的坐标,形成一个多边形。 这些点在C#中使用PointF表示。 如果我有2个多边形(使用8个点),我怎么知道它们是否相交? Rectangle类有一个名为IntersectsWith的方法,但我找不到类似于GraphicsPath或Region的东西。 任何建议将不胜感激。 MOSH

如何在实例化字体时设置多个FontStyles?

在查看System.Drawing.Font类的构造函数时,有一个参数可以传入System.Drawing.FontStyle枚举中定义的FontStyles之一。 即。 粗斜体正常下划线 并且在实例化对象中有Bold,Italic,Underline等布尔属性,但它们是只读的。 如果我想将我的字体定义为具有Bold和Underline等多种样式,该怎么办? 我怎样才能做到这一点?