質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

0回答

1448閲覧

撮影したカメラ画像のテクスチャをUnity間で共有する

shin067

総合スコア5

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

1クリップ

投稿2019/11/25 07:14

iPhoneのカメラで撮影した画像をPC上のUnityに送信して表示したいと思っています.

現在Photonを使用して,無線で実装したいと考えているのですが,
iPhoneにビルドしたアプリからカメラを起動し撮影した画像をPhotonを使ってPCに送信し貼り付けようとしています.

以下のサイトを参考に,テクスチャを送信することはできました.
https://nabla-tech-lab.hatenablog.com/entry/2019/05/15/180000

また,また,別のサイトを参考にiOSアプリからの映像の取得,スクリーンショットをテクスチャとして貼り付けるところまではできています.(https://loumo.jp/wp/archive/20150414000004/)

下記のコードからWebカム画像を映し,上のサイトのようにそのテクスチャをDistributableWhiteBoardというオブジェクトに貼ろうとしているのですが,下の画像のようなエラーがでます.

TextureをTexture2Dに変換しているつもりなのですが,エラーを見る限りcastがうまくいっていないようです.

知識の少ない状態での質問で申し訳ないですが,ご存知の方対処法を教えていただきたいです.
また,別の手段でも構いませんので,やろうとしていることを実装できるような方法があれば教えてください.
よろしくお願いします.

C# Webカム映像取得部

1using UnityEngine; 2using System.Collections; 3public class WebCamTex : MonoBehaviour 4{ 5 public int Width = 1920; 6 public int Height = 1080; 7 public int FPS = 30; 8 public WebCamTexture webcamTexture; 9 public Color32[] color32; 10 11 void Start() 12 { 13 WebCamDevice[] devices = WebCamTexture.devices; 14 webcamTexture = new WebCamTexture(devices[0].name, Width, Height, FPS); 15 GetComponent<Renderer>().material.mainTexture = webcamTexture; 16 webcamTexture.Play(); 17 } 18 19 void Update() 20 { 21 if (Input.GetKeyDown(KeyCode.Space) || Input.touchCount > 0) 22 { 23 color32 = webcamTexture.GetPixels32(); 24 Texture2D texture = new Texture2D(webcamTexture.width, webcamTexture.height); 25 GameObject.Find("DistributableWhiteBoard").GetComponent<Renderer>().material.mainTexture = texture; 26 27 texture.SetPixels32(color32); 28 29 texture.Apply(); 30 } 31 } 32} 33

C#

1using UnityEngine; 2using Photon.Pun; 3using Photon.Realtime; 4using ExitGames.Client.Photon; 5using UniRx; 6 7namespace TextureSharing 8{ 9 public class TextureBroadcastComponent : MonoBehaviourPunCallbacks, IOnEventCallback 10 { 11 [SerializeField] 12 int messagePerSecond = 100; // 100 Messages / Second 13 14 int bytePerMessage = 1000; // 1KBytes / Message 15 16 Texture2D texture; // ★ Readable texture ★ 17 18 bool isReceiving; 19 byte[] receiveBuffer; 20 int totalDataSize; 21 int currentReceivedDataSize; 22 int receivedMessageCount; 23 24 void Start() 25 { 26 texture = (Texture2D)GetComponent<Renderer>().material.mainTexture; 27 try 28 { 29 texture.GetPixels32(); 30 } 31 catch(UnityException e) 32 { 33 Debug.LogError("!! This texture is not readable !!"); 34 } 35 } 36 37 #region sender methods 38 39 public void BroadcastTexture() 40 { 41 byte[] rawTextureData = texture.EncodeToPNG(); 42 43 int width = texture.width; 44 int height = texture.height; 45 int dataSize = rawTextureData.Length; 46 int viewId = this.photonView.ViewID; 47 48 Debug.Log("*************************"); 49 Debug.Log(" BroadcastTexture"); 50 Debug.Log(" Texture size: " + width + "x" + height + " = " + width*height + "px"); 51 Debug.Log(" RawTextureData: " + rawTextureData.Length + "bytes"); 52 Debug.Log("*************************"); 53 54 StreamTextureDataToOtherClients(rawTextureData, width, height, dataSize, viewId); 55 } 56 57以下略
![イメージ説明](1a399dcba3da30463832ed9062fbf213.png)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問