如何在c#中运行Ricoh Theta预览?

问题描述 投票:0回答:1

我正在开发一个需要Ricoh Theta 实时预览的应用程序。理光 Theta 的医生什么也没说。我发现了一个在 javascript 中运行它的请求,但到目前为止还没有在 c# 中运行它。

首先,我使用 camera._getLivePreview 发送了 http 请求,它正在工作(至少我没有错误):

var url = requests("commands/execute");
        request = WebRequest.Create(url);
        request.ContentType = "application/json";
        request.Method = "POST";

        using (var streamWriter = new StreamWriter(request.GetRequestStream()))
        {
            string json = "{\"name\":\"camera._getLivePreview\"," +
                          "\"parameters\":{\"sessionId\":\"" + sid + "\"}}";

            streamWriter.Write(json);
            streamWriter.Flush();
            streamWriter.Close();
        }

然后我尝试使用我在here找到的解决方案来打印响应中以字节为单位给出的图像:

        var response = request.GetResponse().GetResponseStream();

        BinaryReader reader = new BinaryReader(new BufferedStream(response), new System.Text.ASCIIEncoding());

        List<byte> imageBytes = new List<byte>();
        bool isLoadStart = false; 
        byte oldByte = 0; 
        while (true)
        {
            byte byteData = reader.ReadByte();

            if (!isLoadStart)
            {
                if (oldByte == 0xFF)
                {
                    // First binary image
                    imageBytes.Add(0xFF);
                }
                if (byteData == 0xD8)
                {
                    // Second binary image
                    imageBytes.Add(0xD8);

                    // I took the head of the image up to the end binary
                    isLoadStart = true;
                }
            }
            else
            {
                // Put the image binaries into an array
                imageBytes.Add(byteData);

                // if the byte was the end byte
                // 0xFF -> 0xD9 case、end byte
                if (oldByte == 0xFF && byteData == 0xD9)
                {
                    // As this is the end byte
                    // we'll generate the image from the data and can create the texture
                    // imageBytes are used to reflect the texture
                    // imageBytes are left empty
                    // the loop returns the binary image head
                    isLoadStart = false;
                }
            }
          oldByte = byteData;
          byteArrayToImage(imageBytes.ToArray());
        }

    }

由于它没有打印任何内容,我尝试创建一种将 imageurl 发送到图像 src 的方法(使用在here找到的代码):

public void byteArrayToImage(byte[] byteArrayIn)
        {
            string imreBase64Data = Convert.ToBase64String(byteArrayIn);
            string imgDataURL = string.Format("data:image/png;base64,{0}", imreBase64Data);
            imgPreview.Source = imgDataURL;
        }

图像的XAML

<Image Source="" 
               x:Name="imgPreview"/>

如何让它发挥作用?

编辑1:基本上,我认为这里真正的问题是“如何从字节数组打印图像?”

编辑2:我发现布局只有在第一个调用的方法结束后才会更新,并且通过包显示带有url的流会更容易

c# xamarin.forms camera byte theta360
1个回答
0
投票

我基本上做的方式是一个html,每次图像完成时,它都会运行脚本来更新图像,仍然可能很慢,但它比每次更新图像要好,因为它需要清除xamarin和.net maui然后重新喷漆

© www.soinside.com 2019 - 2024. All rights reserved.