如何从ID2D1Bitmap保存bmp文件 [英] How to save bmp file from ID2D1Bitmap

查看:348
本文介绍了如何从ID2D1Bitmap保存bmp文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Kinect从实时运行的视频中创建bmp文件.我正在开发一个应用程序,该应用程序将在其中运行实时视频以放置图像.我使用的IDE是Visual Studio Professional2010.我正在使用Win32在C ++中开发代码.
.我想将视频与叠加的图像一起保存.现在,我使用ID2D1Bitmap以叠加方式显示位图.但是我必须从具有重叠图像的视频中检索字节*数据.我正在尝试创建一个bmp文件,该文件从ID2D1Bitmap中检索byte *数据.但是直接转换无法检索字节*数据.

I am trying to create the bmp file from the live running video using Kinect. I am developing an application which is running the live video on top of that to place an image. The IDE which I am used is Visual Studio Professional 2010. The code I am developing in C++ using win32.
. I want to save the video along with the overlayed image. Now I am using ID2D1Bitmap for displaying the bitmap in overlayed manner. But I have to retrieve the byte* data from the video with overlayed image. I am trying to create a bmp file which retrieve the byte* data from the ID2D1Bitmap. But the direct conversion does not possible to retrieve the byte* data.

            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可以检索byte *内容.因此,请帮助我解决以下疑问,并提供宝贵的指导意见:

But Now I want to combine the both bitmaps and to get the byte* data of that. Is it possible to convert those bitmaps into byte*? Is it any direct conversion available to get the byte* data from ID2D1Bitmap???. And also I am tried to convert the ID2D1Bitmap to IWICBitmap. Because with using IWICBitmap->Lock can retrieve the byte* content. So please help me to the following doubts and give the valuable guidance:

1.ID2D1Bitmap转换为字节* ?.

1.Conversion of ID2D1Bitmap to byte*?.

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

2.How to convert ID2D1Bitmap to IWICBitmap?.

先谢谢您了:)

此致

Vvk.

推荐答案

我在C#中这样做如下.我们编写的代码从帧中捕获字节数组,创建一个Image类型,从下面的函数转换为Bitmap类型,然后另存为压缩的jpeg,以便以后保存在文件系统中:

I did this in C# as follows. The code we wrote captures the byte array from the frame, creates an Image type, converts to a Bitmap type from the function below, then saves as a compressed jpeg for later saving on the filesystem:

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 ++中的功能相同.希望这会有所帮助.

I do not have this in C++, but if you are coding in .NET 4.0, there should be equivalent functions that will do the same as the above in C++. Hope this helps.

这篇关于如何从ID2D1Bitmap保存bmp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆