RcSepp
06-25-2006, 01:59 AM
Hi everyone
Is there anyway to speed this code up:
Dim bmp As Bitmap = New Bitmap(pic.Width, pic.Height)
For i As Integer = 0 To SkinBytes_count Step 2
Dim r As Byte = Convert.ToInt16((Convert.ToString(GetSkinByte(i + 1), 2).PadLeft(8, "0"c) & Convert.ToString(GetSkinByte(i), 2).PadLeft(8, "0"c)).Substring(0, 5), 2) * 255 / 31
Dim g As Byte = Convert.ToInt16((Convert.ToString(GetSkinByte(i + 1), 2).PadLeft(8, "0"c) & Convert.ToString(GetSkinByte(i), 2).PadLeft(8, "0"c)).Substring(5, 6), 2) * 255 / 63
Dim b As Byte = Convert.ToInt16((Convert.ToString(GetSkinByte(i + 1), 2).PadLeft(8, "0"c) & Convert.ToString(GetSkinByte(i), 2).PadLeft(8, "0"c)).Substring(11, 5), 2) * 255 / 31
bmp.SetPixel(i / 2 Mod pic.Width, Int(i / 2 / pic.Width), Color.FromArgb(255, r, g, b))
Next
pic.Image = bmp
What it does:
Get data from the array GetSkinByte()
Two Bytes are used for every pixel
The colorformat is 565 so in binary: the first 5 bits are red, the second 6 bits are green and the last 5 are blue
The code is working correctly but it's far to slow.
Any ideas are welcome.
Is there anyway to speed this code up:
Dim bmp As Bitmap = New Bitmap(pic.Width, pic.Height)
For i As Integer = 0 To SkinBytes_count Step 2
Dim r As Byte = Convert.ToInt16((Convert.ToString(GetSkinByte(i + 1), 2).PadLeft(8, "0"c) & Convert.ToString(GetSkinByte(i), 2).PadLeft(8, "0"c)).Substring(0, 5), 2) * 255 / 31
Dim g As Byte = Convert.ToInt16((Convert.ToString(GetSkinByte(i + 1), 2).PadLeft(8, "0"c) & Convert.ToString(GetSkinByte(i), 2).PadLeft(8, "0"c)).Substring(5, 6), 2) * 255 / 63
Dim b As Byte = Convert.ToInt16((Convert.ToString(GetSkinByte(i + 1), 2).PadLeft(8, "0"c) & Convert.ToString(GetSkinByte(i), 2).PadLeft(8, "0"c)).Substring(11, 5), 2) * 255 / 31
bmp.SetPixel(i / 2 Mod pic.Width, Int(i / 2 / pic.Width), Color.FromArgb(255, r, g, b))
Next
pic.Image = bmp
What it does:
Get data from the array GetSkinByte()
Two Bytes are used for every pixel
The colorformat is 565 so in binary: the first 5 bits are red, the second 6 bits are green and the last 5 are blue
The code is working correctly but it's far to slow.
Any ideas are welcome.