Skip to main content
edited title
Link
Tetrad
  • 30.1k
  • 12
  • 95
  • 143

Unity3D Trying to extract file icons and use as a sprite texture problem

added image for desired output
Source Link
Xeon
  • 308
  • 1
  • 9

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

enter image description here

this is what I should get if I navigate to the notepad++ folder (eg : "C:\Program Files(x86)\Notepad++\")

enter image description here

this is my settings for the texture (supposedly, later being replaced with the extracted icons) enter image description here

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[]));
}

I'm trying to extract file icons from folders (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.

enter image description here

this is my settings for the texture (supposedly, later being replaced with the extracted icons) enter image description here

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[]));
}

I'm trying to extract file icons from the 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

enter image description here

this is what I should get if I navigate to the notepad++ folder (eg : "C:\Program Files(x86)\Notepad++\")

enter image description here

this is my settings for the texture (supposedly, later being replaced with the extracted icons) enter image description here

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[]));
}
Source Link
Xeon
  • 308
  • 1
  • 9

Unity3D sprite texture problem

I'm trying to extract file icons from folders (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.

enter image description here

this is my settings for the texture (supposedly, later being replaced with the extracted icons) enter image description here

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[]));
}