# Trying to extract file icons and use as a sprite texture

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

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;
{
Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(directory);
Bitmap bmp = icon.ToBitmap();
}

public static byte[] ImageToByte(Bitmap img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}

• Can you post on what they are meant to look like? – Ahkam Nihardeen Jan 9 '15 at 1:34
• I have updated the question – Xeon Jan 9 '15 at 4:52

As far as I know, for accessing bitmap's pixel data, you should use LockBits() function:

https://msdn.microsoft.com/en-us/library/5ey6h79d(v=vs.110).aspx

Something like this:

var bitmapData = scaledBitmap.LockBits(...);
var length = bitmapData.Stride * bitmapData.Height;
byte[] bytes = new byte[length];