Tag: gdi +

在没有WPF的扩展Glass Frame中绘制TextBox

我试图在我的表格的扩展玻璃框架上绘制一个TextBox。 我不会描述这种技术,它是众所周知的。 以下是那些没有听说过的人的例子: http : //www.danielmoth.com/Blog/Vista-Glass-In-C.aspx 问题是,绘制这个玻璃框架是很复杂的。 由于黑色被认为是0-alpha颜色,因此任何黑色都会消失。 显然有一些方法可以解决这个问题:绘制复杂的GDI +形状不受此alpha-ness的影响。 例如,此代码可用于在玻璃上绘制标签(注意:使用GraphicsPath代替DrawString以解决可怕的ClearType问题): public class GlassLabel : Control { public GlassLabel() { this.BackColor = Color.Black; } protected override void OnPaint(PaintEventArgs e) { GraphicsPath font = new GraphicsPath(); font.AddString( this.Text, this.Font.FontFamily, (int)this.Font.Style, this.Font.Size, Point.Empty, StringFormat.GenericDefault); e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.FillPath(new SolidBrush(this.ForeColor), font); } } 类似地,这种方法可用于在玻璃区域上创建容器。 请注意使用多边形而不是矩形 – 使用矩形时,其黑色部分被视为alpha。 public […]

在listview上绘画会禁用listview项目上的重绘

这是什么原因? 我重写OnPaintBackground并绘制一个字符串。 直到我在构造函数中调用它才会显示: this.SetStyle ( ControlStyles.UserPaint, true ); 但后来我没有在列表视图中看到这些项目。 为什么以及如何解决这个问题? 编辑:代码 protected override void OnPaintBackground ( PaintEventArgs pevent ) { base.OnPaintBackground ( pevent ); // Create string to draw. String drawString = “76”; // Create font and brush. Font drawFont = new Font ( “Arial”, 36 ); SolidBrush drawBrush = new SolidBrush ( Color.Blue ); […]

执行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 […]

使用GDI +调整图像大小

我真的试图从这个代码中获得更多的性能。 它不是一个重用的代码,而是每次上传新图像时使用,每个图像使用4次(100px,200px,500px,700px)。 因此,当处理任何超过2或3个图像时,它会在服务器上稍微繁忙。 此外,我正在试图弄清楚如何正确处理低分辨率的图像。 目前它只是在中途切断它,而不是满足。 示例: Original , large , xLarge public static byte[] ResizeImageFile(byte[] imageFile, int targetSize) { using (System.Drawing.Image oldImage = System.Drawing.Image.FromStream(new MemoryStream(imageFile))) { Size newSize = CalculateDimensions(oldImage.Size, targetSize); using (Bitmap newImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format32bppRgb)) { newImage.SetResolution(oldImage.HorizontalResolution, oldImage.VerticalResolution); using (Graphics canvas = Graphics.FromImage(newImage)) { canvas.SmoothingMode = SmoothingMode.AntiAlias; canvas.InterpolationMode = InterpolationMode.HighQualityBicubic; canvas.PixelOffsetMode […]

最小化屏幕时C#LinearGradientBrush毛刺

我有以下代码在我的winform上创建混合背景: public partial class Aging : Form { protected override void OnPaintBackground(PaintEventArgs e) { using (var brush = new LinearGradientBrush(this.ClientRectangle, Color.Transparent, Color.Transparent, LinearGradientMode.Vertical)) { var blend = new ColorBlend(); blend.Positions = new[] { 0, 3 / 10f, 1 }; blend.Colors = new[] { Color.WhiteSmoke, Color.LightSteelBlue, Color.LightSteelBlue }; brush.InterpolationColors = blend; e.Graphics.FillRectangle(brush, this.ClientRectangle); } } 结果是从LightSteelBlue到WhiteSmoke的颜色背景渐渐消失: […]

有没有办法以编程方式将文本添加到System.Drawing.Image?

我有一个System.Drawing.Image,我用System.Drawing.Graphics DrawImage函数显示。 图像是警车,我想在警车上画一个单位号码。 是否有捷径可寻?

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

我有一个很大的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, […]

绘制有多个孔的多边形?

我正在尝试绘制一个有多个孔的多边形。 我尝试了以下代码,但它无法正常工作。 请指教。 PointF[] mypoly = new PointF[6 + 5 + 5]; mypoly[0] = new PointF(0, 0); mypoly[1] = new PointF(100, 0); mypoly[2] = new PointF(100, 100); mypoly[3] = new PointF(0, 100); mypoly[4] = new PointF(10, 80); mypoly[5] = new PointF(0, 0); mypoly[6] = new PointF(10, 10); mypoly[7] = new PointF(10, 20); mypoly[8] = new […]

如何让我的游戏引擎更快(GDI +,C#)

我目前正在使用GDI在C#中构建2D游戏引擎。 我知道有更好的GDI替代方案,但我对项目的处理也很深入,现在我无法回头。 所以,我目前有一个图形引擎,根据我的相机位置和窗口大小呈现位图的一部分,这给了我很大的性能提升。 大! 但是,我注意到如果我放置一堆游戏对象,在相同的位置,我得到相同的帧速率,如果我将对象放在不同的位置。 那么,也许图形引擎渲染的位图部分不需要渲染? 如果是这种情况我该如何解决? 我相信代码并不是真的需要,但只是为了确保这是我的图形引擎在我的主游戏循环中所做的事情 namespace GameEngine.Graphics { public class GraphicsEngine { private Window window; private View view; private System.Drawing.Graphics frontBuffer; private System.Drawing.Graphics backBuffer; private System.Drawing.Bitmap backBufferBitmap; public GraphicsEngine(Window window, View view) { this.window = window; this.view = view; frontBuffer = window.CreateGraphics(); backBufferBitmap = new Bitmap((int)view.Size.X, (int)view.Size.Y); backBuffer = System.Drawing.Graphics.FromImage(backBufferBitmap); frontBuffer.CompositingMode = […]

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 = […]