Visual studio 2010 如何从ID2D1Bitmap保存bmp文件

Visual studio 2010 如何从ID2D1Bitmap保存bmp文件,visual-studio-2010,directx,kinect,direct2d,kinect-sdk,Visual Studio 2010,Directx,Kinect,Direct2d,Kinect Sdk,我正在尝试使用Kinect从实时运行的视频创建bmp文件。我正在开发一个应用程序,在上面运行实时视频来放置图像。我使用的IDE是Visual Studio Professional 2010。我用C++开发的代码,使用win32.bR> . 我想将视频与叠加图像一起保存。现在我使用ID2D1Bitmap以叠加方式显示位图。但我必须从覆盖图像的视频中检索字节*数据。我试图创建一个bmp文件,从ID2D1Bitmap中检索字节*数据。但是直接转换无法检索字节*数据 m_pd2

我正在尝试使用Kinect从实时运行的视频创建bmp文件。我正在开发一个应用程序,在上面运行实时视频来放置图像。我使用的IDE是Visual Studio Professional 2010。我用C++开发的代码,使用win32.bR> . 我想将视频与叠加图像一起保存。现在我使用ID2D1Bitmap以叠加方式显示位图。但我必须从覆盖图像的视频中检索字节*数据。我试图创建一个bmp文件,从ID2D1Bitmap中检索字节*数据。但是直接转换无法检索字节*数据

            m_pd2d1RenderTarget->DrawBitmap(m_pd2d1Bitmap_Image,D2D1::Rect(120,140, 120+Height,140+Width));
            m_pd2d1RenderTarget->DrawBitmap(m_pd2d1Bitmap_Video);

  I copied the data to the ID2D1Bitmap using the function called,
           m_pd2d1RenderTarget->CopyFromMemory(NULL,pvideo_Data,video_Info.bmWidthBytes); m_pd2d1RenderTarget->CopyFromMemory(NULL, pBitmap_Data,Bitmap_Info.bmWidthBytes);
但是现在我想结合这两个位图,并得到它的字节*数据。是否可以将这些位图转换为字节*?从ID2D1Bitmap获取字节*数据是否有任何直接转换???。我还尝试将ID2D1Bitmap转换为IWICBitmap。因为使用IWICBitmap->Lock可以检索字节*内容。因此,请帮助我解决以下疑问,并提供有价值的指导:

1.将ID2D1Bitmap转换为字节*

2.如何将ID2D1Bitmap转换为IWICBitmap

提前感谢:)

问候,

Vvk.

我在C#中这样做了,如下所示。我们编写的代码从帧中捕获字节数组,创建图像类型,从下面的函数转换为位图类型,然后保存为压缩jpeg,以便稍后保存到文件系统中:

using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
                {
                    if (depthFrame == null) return;
                    byte[] pixels = GenerateColoredBytes(depthFrame, first);

                    int stride = depthFrame.Width * 4;
                    depthImage.Source = BitmapSource.Create(depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride);

                    Bitmap btmap = GetBitmap((BitmapSource)depthImage.Source);

                    // Encoder parameter for image quality
                    long quality = 100000;
                    EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
                    // Jpeg image codec
                    ImageCodecInfo jpegCodec = getEncoderInfo("image/jpeg");
                    EncoderParameters encoderParams = new EncoderParameters(1);
                    encoderParams.Param[0] = qualityParam;

                    var stream = new MemoryStream(); // Create MemoryStream
                    btmap.Save(stream, jpegCodec, encoderParams); //(stream, ImageFormat.Jpeg); // Save Bitmap as .jpeg in MemoryStream                    

                    depthPath = "_UserTrialImages/" + UsernameInput.username + "/Date-" + DateTime.Now.ToString("MM.dd.yyyy");
                    gamePath = depthPath + "/Game-" + gameNumber;
                    trajectoryPath = gamePath + "/Trajectory-" + trajectoryNumber;     // one trajectory per super bubble appearance

                    string depthFile = "image" + ind[5] + ind[4] + ind[3] + ind[2] + ind[1] + ind[0] + ".jpg";
                    string pathFile = trajectoryPath + '/' + depthFile;

                    imageNumberCounter();
                    newImg.pathFile = pathFile;
                    newImg.stream = stream;

                    // saves depth images in list
                    listOfImages.Add(newImg);
                }
它调用此函数:

Bitmap GetBitmap(BitmapSource source)
{
    Bitmap bmp = new Bitmap(source.PixelWidth, source.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

    BitmapData data = bmp.LockBits(
      new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size),
      ImageLockMode.WriteOnly,
      System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

    source.CopyPixels(
      Int32Rect.Empty,
      data.Scan0,
      data.Height * data.Stride,
      data.Stride);

    bmp.UnlockBits(data);

    return bmp;
}

<>我在C++中没有这个,但是如果你在.NET 4中编码,应该有与C++中相同的函数。希望这有帮助。

如果我提供的答案适合您的需要,请接受,或者留下评论以澄清是否需要进一步的帮助。