Tag: drawimage

WinForms上的DrawImage()函数无法正常工作

当我尝试使用以下方法将此位图绘制为2像素宽时,我创建了一个1像素宽和256像素高的BitMap: public void DrawImage(Image image,RectangleF rect) 由于每个位图列之间有白色细条纹,因此未正确绘制位图。 请参阅下面的简单代码 private void Form1_Paint(object sender, PaintEventArgs e) { Graphics gr = e.Graphics; Bitmap bitmap = new Bitmap(1, 256); for (int y = 0; y < 256; y++) { bitmap.SetPixel(0, y, Color.Red); } RectangleF rectf = new RectangleF(); for (int x = 0; x < 500; x++) { float […]

如何在C#后面的代码中显示PictureBox

我知道我的问题听起来很基本,但我搜遍了整个地方,什么都没找到……这是我的代码: public MainWindow() { InitializeComponent(); Map newMap = new Map(); newMap.setMapStrategy(new SmallMapStrategy()); newMap.createMap(); System.Windows.Forms.PictureBox pictureBox1 = new System.Windows.Forms.PictureBox(); pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(newMap.grid[3].afficher); } 这是一个function: public override void afficher(object sender, PaintEventArgs e) { e.Graphics.DrawImage(squareImage, pos_x, pos_y, 50, 50); } squareImage是与Drawing.Image对应的属性。 pos_x和pos_y是自定义int32属性。 我想要的是在运行我的应用程序时看到图像…

G.drawimage绘制的大小不正确

我正在创建一个包含文件中较小图像的大位图。 这些图像的大小都是250像素,但其中一个变小,另一个大于250像素。 我只是使用基本的g.drawimage方法,所以我不知道我做错了什么。 string[] imagePaths = Directory.GetFiles(@”C:\Users\admin\Desktop\Images”); ArrayList images = new ArrayList(); foreach (var item in imagePaths) images.Add(new Bitmap(item, true)); Bitmap list = new Bitmap(840, 1188); Graphics g = Graphics.FromImage(list); int size = 0; for (int i = 0; i < images.Count; i++) { g.DrawImage((Bitmap)images[i], new Point(10, (i + 1) * 10 + size)); Bitmap […]

如何提高GDI的DrawImage(Unscaled)的性能?

在我的用户控件的绘制处理程序中,我遍历一组预定义的Bitmap对象,并将它们绘制到客户区: C#版本: private void Control_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; foreach (BitmapObj bmpObj in _bitmapObjCollection) { g.DrawImageUnscaled(bmpObj.Bitmap, bmpObj.Location); } } VB.NET版本: Private Sub Control_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint Dim g As Graphics = e.Graphics For Each bmpObj As BitmapObj In _bitmapObjCollection g.DrawImageUnscaled(bmpObj.Bitmap, bmpObj.Location) Next End Sub 代码工作正常但是当十几个对象添加到集合时开始陷入困境。 […]

使用Graphics.DrawImage()以透明度/ Alpha通道绘制图像

我正在复制一张图片。 (我的实际代码是调整图像大小,但这与我的问题无关。)我的代码看起来像这样。 Image src = … using (Image dest = new Bitmap(width, height)) { Graphics graph = Graphics.FromImage(dest); graph.InterpolationMode = InterpolationMode.HighQualityBicubic; graph.DrawImage(src, 0, 0, width, height); dest.Save(filename, saveFormat); } 除非从具有透明度(例如GIF)或Alpha通道(例如PNG)的图像加载src否则这似乎很有效。 如何让DrawImage()将透明度/ alpha通道传输到新图像,然后在保存文件时保留它们?