- Home /
Question by
cchpackers1 · Jun 07, 2019 at 06:51 PM ·
texturematerialtexture2dimage
Set image as material
I am trying to grab an image from a file and set already made materials as that image. byte[] img = GetImageAsByteArray("C:/Users/A7V2XZZ/Pictures/3M/package.jpg"); Texture2D text = new Texture2D(128,128); text.LoadRawTextureData(img); Debug.Log(text); material2.SetTexture("_MainTex", textz);
}
// Update is called once per frame
void Update()
{
}
static byte[] GetImageAsByteArray(string imageFilePath)
{
// Open a read-only file stream for the specified file.
using (FileStream fileStream =
new FileStream(imageFilePath, FileMode.Open, FileAccess.Read))
{
// Read the file's contents into a byte array.
BinaryReader binaryReader = new BinaryReader(fileStream);
return binaryReader.ReadBytes((int)fileStream.Length);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Material not updating on Image 2 Answers
Scaling / Resizing an Image (Texture2D) 6 Answers
Repeating Material texture 0 Answers
dynamic images for textures ar runtime 2 Answers
How do you crop a Texture2d 1 Answer