【问题标题】:Create IntPtr for specified image data为指定的图像数据创建 IntPtr
【发布时间】:2011-11-12 00:09:19
【问题描述】:

(我什至不知道如何正确地问这个问题,对不起。我的图像处理能力基本上不存在。)

我在库中有一个函数(即来自 CL.NUI 的 bool CLNUIDevice.GetCameraColorFrameRGB32(...) 来读取 Kinect 数据),我必须将 IntPtr data 作为参数传递。生成的图像数据将在此 data 中结束。

我想对这些数据进行一些图像处理并将其显示在屏幕上(我猜是PictureBox)。

当我传递一个设置为IntPtr.Zero 的变量时,它保持0。据我了解,我必须正确初始化data。我的图像是 640x480 像素,从示例来看它应该有 PixelFormat.Format32bppPArgb

如何为似乎每像素 32 位的 640x480 像素位图初始化 IntPtr

【问题讨论】:

    标签: c# winforms image-processing


    【解决方案1】:

    使用您的宽度/高度/bpp 和通过构造函数传入的图像数据指针创建一个新的Bitmap 对象。

    然后,您可以选择任何方式显示该位图。

    【讨论】:

      【解决方案2】:
              var bmp = new Bitmap(640, 480, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
              System.Drawing.Imaging.BitmapData bd = null;
              try {
                  bd = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
                  var pointer = bd.Scan0;
                  // Make the call, passing *pointer*
                  //...
              }
              finally {
                  if (bd != null) bmp.UnlockBits(bd);
              }
              // Do something with <bmp>
              //...
      

      【讨论】:

        【解决方案3】:

        我希望这个链接能帮助你Using WritePixels when using a writeable bitmap from a intptr to create a bitmap

        您可以根据您的要求更改它...

        【讨论】:

          猜你喜欢
          • 2014-08-16
          • 1970-01-01
          • 2017-08-26
          • 1970-01-01
          • 2020-12-02
          • 2022-11-05
          • 2014-02-07
          • 2014-11-06
          • 1970-01-01
          相关资源
          最近更新 更多