I'm trying to extract file icons from foldersthe files inside a folder (eg: Program Files), and have them set as my Sprite's texture. I extracted the file icons, converted them to Bitmaps and then to byte array, and call the LoadImage(byte[] byte) function in my Sprite object. But when I test, the textures become the image belows. Any idea how to fix this? I just want to set my sprites texture as the extracted file icon, I'm creating something similar to a file explorer.
this is the result that i get
this is what I should get if I navigate to the notepad++ folder (eg : "C:\Program Files(x86)\Notepad++\")
this is my settings for the texture (supposedly, later being replaced with the extracted icons)
Here's my code
public UnityEngine.UI.Image targetImg;
public void Load(string directory)
{
Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(directory);
Bitmap bmp = icon.ToBitmap();
targetImg.sprite.texture.LoadImage(ImageToByte(bmp));
}
public static byte[] ImageToByte(Bitmap img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}