2013-02-06 96 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++。希望這可以幫助。