2013-02-06 54 views
0

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

  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转换为byte * ?.

2.如何将ID2D1Bitmap转换为IWICBitmap ?.

感谢提前:)

问候,

VVK。

+0

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

回答

0

我在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.0中,应该有相当的功能,将做相同以上C++。希望这可以帮助。