Question by
johannesneff · Nov 23, 2020 at 11:55 AM ·
pixelgetpixelsrgb2dtexture
Get RGB Values from Picture as values
Hello,
I want to get the color values from all the pixels in my texture to use these values as coordinates in 3D - I already get the specific color from the picture to use it for my object but how do I read the values for this color?
Code so far:
using System.Drawing;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RgbColorSpace : MonoBehaviour
{
public Texture2D tex;
private Sprite mySprite;
private SpriteRenderer sr;
public Texture2D heightmap;
public float height = 1;
void Start()
{
Color[] pixels = heightmap.GetPixels(0,0,heightmap.width, heightmap.height);
//sr = gameObject.AddComponent<SpriteRenderer>() as SpriteRenderer;
//UnityEngine.Debug.Log("colorvalue: ");
for (int x = 0; x < heightmap.width; x++){
for(int y = 0; y < heightmap.height; y++){
Color color = pixels[(x * heightmap.width) + y];
GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
obj.transform.position = new Vector3(x,color.grayscale * height,y);
obj.GetComponent<UnityEngine.Renderer>().material.color = color;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Windowed Unity program. Getting Color from Desktop. 0 Answers
Turning every color in an image to many GameObjects ? 0 Answers
How Do I Get Pixel Color That Includes The SpriteRenderer Color Change? 0 Answers
Capture Mouse position color of pixel from current frame of Movie Texture 0 Answers
How to make pixel pictures animation? 0 Answers