【问题标题】:Convert pixel data to Bitmap int array- WP8 - C#将像素数据转换为位图 int 数组-WP8-C#
【发布时间】:2013-04-02 17:18:20
【问题描述】:

我想制作一个使用相机的应用程序,从中获取帧,将其转换并放在屏幕上。我从微软找到了一个教程,它通过转换为灰度来做到这一点,但我真的不需要那个。相反,我需要像 8b 位图那样的 int 数组,这样我的转换功能才能正常工作。所以主要问题是如何将该像素数据数组转换为位图数组,然后将其转回以便我可以显示它屏幕?另一种解决方案是直接从相机获取位图 int 数组,但我该怎么做呢?

我需要处理以下代码:

    void PumpARGBFrames()
    {
        // Create capture buffer.
        Width = (int)cam.PreviewResolution.Width;
        Height = (int)cam.PreviewResolution.Height;
        int[] ARGBPx = new int[Width * Height];

        try
        {
            PhotoCamera phCam = (PhotoCamera)cam;

            while (pumpARGBFrames)
            {
                pauseFramesEvent.WaitOne();

                phCam.GetPreviewBufferArgb32(ARGBPx);

                //here i need to do the conversion back and forward

                pauseFramesEvent.Reset();
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    ARGBPx.CopyTo(wb.Pixels, 0);
                    wb.Invalidate();

                    pauseFramesEvent.Set();
                });
            }

        }
        catch (Exception e)
        {
            this.Dispatcher.BeginInvoke(delegate()
            {
                // Display error message.
                txtDebug.Text = e.Message;
            });
        }
    }

所以,事实上我不需要位图,而是需要一个 int 数组作为 8b 位图的来源。 我从微软那里得到的教程是here。 谢谢。

【问题讨论】:

    标签: c# bitmap camera windows-phone-8


    【解决方案1】:

    尝试类似:

    Bitmap bmp = new Bitmap(Width, Height);
    
    for (int i = 0; i < ARGBPx.Length; ++i)
    {
        bmp.SetPixel(
            i % Width,
            i / Width,
            /* something to create a Color object from the pixel int value */
    }
    

    【讨论】:

    • WP8开发好像不支持Bitmap.Only BitmapImage,但是我不能像你说的那样使用。
    • 在这种情况下,您可能只需将其转换为二维数组并像那样对其进行操作,而不是位图。
    【解决方案2】:

    好吧,我意识到像素数据数组实际上是一个颜色数组,它们是 32b 格式的。所以我只需要将 32b 颜色转换为 8b 颜色,并没有我想象的那么难。

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-17
      • 1970-01-01
      • 2015-07-07
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多