【问题标题】:Media Capture - photos taken by phone are dark媒体捕捉 - 手机拍摄的照片很暗
【发布时间】:2016-08-30 02:47:42
【问题描述】:

我正在尝试制作当您点击 livetile 时拍照的应用。不幸的是,智能手机存在一些问题:这个应用程序保存的照片完全是黑色的。我不知道我会做错什么。

事实:

  1. 此 UWP 应用可在 PC 上正常运行,问题仅出现在我的 Lumia 设备上
  2. 正确检测到相机
  3. 这不是livetile的问题:无论我点击livetile还是点击按钮拍照都不起作用
  4. 并非所有照片都是全黑的。当我拍摄窗户(由于阳光而明亮)时,我可以看到它模糊的形状。也许照片是正确拍摄的,但它们不知何故变暗了?

要粘贴的代码太多,所以我决定在 GitHub 上发布整个项目。

[LINK TO GITHUB]

您知道为什么它不起作用吗?这段代码大部分是抄自其中一个教程,所以有问题就很奇怪了。

【问题讨论】:

    标签: c# windows win-universal-app windows-10 windows-10-universal


    【解决方案1】:

    我找到了灵魂:

    初始化MediaCapture后,拍照前,需要创建CaptureElement并开始预览。

    var captureElement = new CaptureElement();
    captureElement.Source = _mediaCapture;
    
    await _mediaCapture.StartPreviewAsync();
    

    Why you need to start previewing

    图片较暗通常是由于缺少视频预览。相机驱动程序使用预览流来运行他们的 3A 算法(自动白平衡/对焦/曝光)。

    Why you need to create Capture Element

    发生此错误 [当您使用不带 CaptureElement 的 StartPreviewAsync 时显示] 因为当前 StartPreviewAsync 需要接收器才能将帧输出到。这可以通过在 xaml 中创建一个捕获元素来显示帧来解决。

    【讨论】:

      【解决方案2】:

      尝试使用这个 sn-p(来自 FingerPaint 应用)在拍摄图像后更改色调或亮度:

          ImageEncodingProperties imageEncodingProps = ImageEncodingProperties.CreateJpeg();
          InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream();
          await _mediaCapture.CapturePhotoToStreamAsync(imageEncodingProps, memoryStream);
      
              BitmapDecoder decoder = await BitmapDecoder.CreateAsync(memoryStream);
              PixelDataProvider pixelProvider = await decoder.GetPixelDataAsync();
              byte[] pixels = pixelProvider.DetachPixelData();
      
              for (int index = 0; index < pixels.Length; index += 4)
              {
                  Color color = Color.FromArgb(pixels[index + 3],
                                               pixels[index + 2],
                                               pixels[index + 1],
                                               pixels[index + 0]);
                  HSL hsl = new HSL(color);
                  hsl = new HSL(hsl.Hue, 1.0, hsl.Lightness);
                  color = hsl.Color;
      
                  pixels[index + 0] = color.B;
                  pixels[index + 1] = color.G;
                  pixels[index + 2] = color.R;
                  pixels[index + 3] = color.A;
              }
      
              WriteableBitmap bitmap = new WriteableBitmap((int)decoder.PixelWidth, 
                                                           (int)decoder.PixelHeight);
              Stream pixelStream = bitmap.PixelBuffer.AsStream();
              await pixelStream.WriteAsync(pixels, 0, pixels.Length);
              bitmap.Invalidate();
      
              image.Source = bitmap;
      

      【讨论】:

      • 谢谢,但我刚刚找到了更简单的解决方案
      猜你喜欢
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多