Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net StrechBlt不起作用_.net_Windows_Winapi_Api - Fatal编程技术网

.net StrechBlt不起作用

.net StrechBlt不起作用,.net,windows,winapi,api,.net,Windows,Winapi,Api,矩形被画出来。。但是位图不是。。。我已经设置了picturebox1.Image=bitmap,这样位图就不会是空的。。。知道我做错了什么吗? 我在compact框架中。我不确定“this.Handle”是什么,但它可能不是DC的句柄。我怀疑您在每次创建笔和图形对象时都在泄漏资源。(垃圾收集器最终会释放它,但让这些句柄留在周围不是一个好主意)。在任何情况下,您都可以使用图形对象本身来执行图像blit,而不是重击StretchBlt protected override void OnPaint(

矩形被画出来。。但是位图不是。。。我已经设置了
picturebox1.Image=bitmap
,这样位图就不会是空的。。。知道我做错了什么吗? 我在compact框架中。

我不确定“this.Handle”是什么,但它可能不是DC的句柄。我怀疑您在每次创建笔和图形对象时都在泄漏资源。(垃圾收集器最终会释放它,但让这些句柄留在周围不是一个好主意)。在任何情况下,您都可以使用图形对象本身来执行图像blit,而不是重击StretchBlt

protected override void OnPaint(PaintEventArgs e)
{
      Win32Helper.StretchBlt(this.Handle, 0, 0, 200, 300,bitmap.GetHbitmap(), 0, 0, bitmap.Width, bitmap.Height, Win32Helper.TernaryRasterOperations.SRCCOPY);
      this.CreateGraphics().DrawRectangle(new Pen(Color.Black), 0, 0, 100, 100);           

    base.OnPaint(e);
}

我没有用HDC。。DrawImage与API性能没有显著的性能差异如果使用窗口句柄的DC而不是PaintEventArgs中的DC,性能可能会略有提高。原因是绑定到图形对象的HDC是“剪裁”不需要更新的区域。但这可能重要,也可能不重要,这取决于你的应用程序在绘制程序中的频率和要求。
  protected override void OnPaint(PaintEventArgs e)
  {
      System.Drawing.Graphics g = e.Graphics; // or call your CreateGraphics function
      Pen p = new Pen(Color.Black);

      g.DrawImage(bitmap, 0, 0, 200, 300);
      g.DrawRectangle(p, 0, 0, 100, 100);           

      // cleanup
      p.Dispose();
      // g.Dispose(); Call g.dispose if you allocated it and it didn't come from the PaintEventArgs parameter

      base.OnPaint(e);
  }