Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

Color[][] is not storing color. Object reference not set to an instance of an object.

$
0
0
Hello, I am trying to reverse an image of a texture2D. I have tried many different attempts at this problem to no avail (including, but not limited to: Reverse() of arraylist, mixing jagged arrays, and looping through individual pixels). Here is a snippet of code for the reverse function. void ReverseImageX(Texture2D image) { //Get the array ready Color[][] newColorArrayWidth = new Color[image.height][]; //Deconstruct the picture and get every pixel for(int i = 0; i < image.height; i++) { //Get the width of the picture for(int j = image.width - 1; j >= 0; j--) { newColorArrayWidth[i][j] = image.GetPixel(j, i); //Error here: NullReferenceException: Object reference not set to an instance of an object } } //Reconstruct the picture reveresed in the X-axis for(int i = 0; i < image.height; i++) { //use the width of the picture to reconstruct the image for(int j = 0; j > image.width; j++) { //Reconstruct image.SetPixel(j, i, newColorArrayWidth[i][j]); } } } I am also trying to not only reverse the image horizontally, but also vertically. But I assume that it is just messing with the for loops to get that desired effect. The error is happening on line 364 (in this case it is: "newColorArrayWidth[i][j] = image.GetPixel(j, i);") and is not storing the color in the multidimensional array. I know this function is working by reciving the image through the parameter and going through the loop conditions, but stops at that line.

Viewing all articles
Browse latest Browse all 184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>