How do i read a byte array as a multi dimensional array in C#?How do I calculate someone's age in C#?How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?Creating a byte array from a streamHow do you convert a byte array to a hexadecimal string, and vice versa?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do you read from stdin?How to read a file line-by-line into a list?Unity: Convert PNG Texture2D to byte[] array and back. Then display
Can I bring back Planetary Romance as a genre?
I might have messed up in the 'Future Work' section of my thesis
Examples where existence is harder than evaluation
What dice to use in a game that revolves around triangles?
Can the president of the United States be guilty of insider trading?
How can it be that ssh somename works, while nslookup somename does not?
How long can fsck take on a 30 TB volume?
How can Sam Wilson fulfill his future role?
How is Arya still alive?
Are on’yomi words loanwords?
Publishing an article in a journal without a related degree
Was there a contingency plan in place if Little Boy failed to detonate?
TeX Gyre Pagella Math Integral sign much too small
Why are thrust reversers not used to slow down to taxi speeds?
"Estrontium" on poster
What are these round pads on the bottom of a PCB?
How can I test a shell script in a "safe environment" to avoid harm to my computer?
Has everyone forgotten about wildfire?
How did Captain Marvel know where to find these characters?
Passport stamps art, can it be done?
Rusty Chain and back cassette – Replace or Repair?
How likely are Coriolis-effect-based quirks to develop in starship crew members?
Not taking the bishop with the knight, why?
How come mathematicians published in Annals of Eugenics?
How do i read a byte array as a multi dimensional array in C#?
How do I calculate someone's age in C#?How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?Creating a byte array from a streamHow do you convert a byte array to a hexadecimal string, and vice versa?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do you read from stdin?How to read a file line-by-line into a list?Unity: Convert PNG Texture2D to byte[] array and back. Then display
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to use Python to send images to Unity C# where I want to display the images overlayed on the current display (for every frame).
I am currently using zmq to receive a byte array of a PNG image from python into Unity.
The image is in the form of a numpy array of shape 256x256x4. Using the function np.tobytes
, the length of the message is 2097152 which is larger than (256x256x4)
Once the message is sent to Unity, I am attempting to get a colour array from the byte array to use Texture2D.readPixels32()
using the following code snippet.
var colorArray = new Color32[message.Length/4];
for(var i = 0; i < message.Length; i+=4)
var color = new Color32(message[i + 0], message[i + 1], message[i + 2], message[i + 3]);
colorArray[i/4] = color;
Texture2D tex2new=new Texture2D(Screen.width,Screen.height);
print (Screen.height + " " + Screen.width + " " + colorArray.Length);
tex2new.SetPixels32(colorArray);
The error is SetPixels32
called with invalid number of pixels in the arrayUnityEngine.Texture2D:SetPixels32(Color32[])
How do I read the byte array into a texture?
Is there a better way to display the byte array once the game is played in Unity in real-time?
c# python sockets unity3d textures
add a comment |
I am trying to use Python to send images to Unity C# where I want to display the images overlayed on the current display (for every frame).
I am currently using zmq to receive a byte array of a PNG image from python into Unity.
The image is in the form of a numpy array of shape 256x256x4. Using the function np.tobytes
, the length of the message is 2097152 which is larger than (256x256x4)
Once the message is sent to Unity, I am attempting to get a colour array from the byte array to use Texture2D.readPixels32()
using the following code snippet.
var colorArray = new Color32[message.Length/4];
for(var i = 0; i < message.Length; i+=4)
var color = new Color32(message[i + 0], message[i + 1], message[i + 2], message[i + 3]);
colorArray[i/4] = color;
Texture2D tex2new=new Texture2D(Screen.width,Screen.height);
print (Screen.height + " " + Screen.width + " " + colorArray.Length);
tex2new.SetPixels32(colorArray);
The error is SetPixels32
called with invalid number of pixels in the arrayUnityEngine.Texture2D:SetPixels32(Color32[])
How do I read the byte array into a texture?
Is there a better way to display the byte array once the game is played in Unity in real-time?
c# python sockets unity3d textures
how do you read the png image in python? and could you show the result of print
– Frenchy
Mar 23 at 11:29
If you want to convert a 1d into a 2darray- cant test this right now but ive made similar things like this: // to get the index of and x and y coord int index = x + (y * w); or y + (x * w) // // to get the x and y of an index int x = index % w; int y = Round((index / w) - 1); // im no sure about this right now !? where w is the x and y length of the 2d array. That works if the 2darray has the same x and y length. Im not sure if that is what you need.
– user11220832
Mar 23 at 13:40
add a comment |
I am trying to use Python to send images to Unity C# where I want to display the images overlayed on the current display (for every frame).
I am currently using zmq to receive a byte array of a PNG image from python into Unity.
The image is in the form of a numpy array of shape 256x256x4. Using the function np.tobytes
, the length of the message is 2097152 which is larger than (256x256x4)
Once the message is sent to Unity, I am attempting to get a colour array from the byte array to use Texture2D.readPixels32()
using the following code snippet.
var colorArray = new Color32[message.Length/4];
for(var i = 0; i < message.Length; i+=4)
var color = new Color32(message[i + 0], message[i + 1], message[i + 2], message[i + 3]);
colorArray[i/4] = color;
Texture2D tex2new=new Texture2D(Screen.width,Screen.height);
print (Screen.height + " " + Screen.width + " " + colorArray.Length);
tex2new.SetPixels32(colorArray);
The error is SetPixels32
called with invalid number of pixels in the arrayUnityEngine.Texture2D:SetPixels32(Color32[])
How do I read the byte array into a texture?
Is there a better way to display the byte array once the game is played in Unity in real-time?
c# python sockets unity3d textures
I am trying to use Python to send images to Unity C# where I want to display the images overlayed on the current display (for every frame).
I am currently using zmq to receive a byte array of a PNG image from python into Unity.
The image is in the form of a numpy array of shape 256x256x4. Using the function np.tobytes
, the length of the message is 2097152 which is larger than (256x256x4)
Once the message is sent to Unity, I am attempting to get a colour array from the byte array to use Texture2D.readPixels32()
using the following code snippet.
var colorArray = new Color32[message.Length/4];
for(var i = 0; i < message.Length; i+=4)
var color = new Color32(message[i + 0], message[i + 1], message[i + 2], message[i + 3]);
colorArray[i/4] = color;
Texture2D tex2new=new Texture2D(Screen.width,Screen.height);
print (Screen.height + " " + Screen.width + " " + colorArray.Length);
tex2new.SetPixels32(colorArray);
The error is SetPixels32
called with invalid number of pixels in the arrayUnityEngine.Texture2D:SetPixels32(Color32[])
How do I read the byte array into a texture?
Is there a better way to display the byte array once the game is played in Unity in real-time?
c# python sockets unity3d textures
c# python sockets unity3d textures
edited Mar 23 at 10:38
ingvar
2,0751718
2,0751718
asked Mar 23 at 8:58
YellowMuffinsAndSprinklesYellowMuffinsAndSprinkles
1
1
how do you read the png image in python? and could you show the result of print
– Frenchy
Mar 23 at 11:29
If you want to convert a 1d into a 2darray- cant test this right now but ive made similar things like this: // to get the index of and x and y coord int index = x + (y * w); or y + (x * w) // // to get the x and y of an index int x = index % w; int y = Round((index / w) - 1); // im no sure about this right now !? where w is the x and y length of the 2d array. That works if the 2darray has the same x and y length. Im not sure if that is what you need.
– user11220832
Mar 23 at 13:40
add a comment |
how do you read the png image in python? and could you show the result of print
– Frenchy
Mar 23 at 11:29
If you want to convert a 1d into a 2darray- cant test this right now but ive made similar things like this: // to get the index of and x and y coord int index = x + (y * w); or y + (x * w) // // to get the x and y of an index int x = index % w; int y = Round((index / w) - 1); // im no sure about this right now !? where w is the x and y length of the 2d array. That works if the 2darray has the same x and y length. Im not sure if that is what you need.
– user11220832
Mar 23 at 13:40
how do you read the png image in python? and could you show the result of print
– Frenchy
Mar 23 at 11:29
how do you read the png image in python? and could you show the result of print
– Frenchy
Mar 23 at 11:29
If you want to convert a 1d into a 2darray- cant test this right now but ive made similar things like this: // to get the index of and x and y coord int index = x + (y * w); or y + (x * w) // // to get the x and y of an index int x = index % w; int y = Round((index / w) - 1); // im no sure about this right now !? where w is the x and y length of the 2d array. That works if the 2darray has the same x and y length. Im not sure if that is what you need.
– user11220832
Mar 23 at 13:40
If you want to convert a 1d into a 2darray- cant test this right now but ive made similar things like this: // to get the index of and x and y coord int index = x + (y * w); or y + (x * w) // // to get the x and y of an index int x = index % w; int y = Round((index / w) - 1); // im no sure about this right now !? where w is the x and y length of the 2d array. That works if the 2darray has the same x and y length. Im not sure if that is what you need.
– user11220832
Mar 23 at 13:40
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312149%2fhow-do-i-read-a-byte-array-as-a-multi-dimensional-array-in-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312149%2fhow-do-i-read-a-byte-array-as-a-multi-dimensional-array-in-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
how do you read the png image in python? and could you show the result of print
– Frenchy
Mar 23 at 11:29
If you want to convert a 1d into a 2darray- cant test this right now but ive made similar things like this: // to get the index of and x and y coord int index = x + (y * w); or y + (x * w) // // to get the x and y of an index int x = index % w; int y = Round((index / w) - 1); // im no sure about this right now !? where w is the x and y length of the 2d array. That works if the 2darray has the same x and y length. Im not sure if that is what you need.
– user11220832
Mar 23 at 13:40