Esempio n. 1
0
        public static byte[] ConvertImageToRGBA5551(Bitmap image)
        {
            int width  = image.Width;
            int height = image.Height;

            byte[] numArray = new byte[width * height * 2];
            int    index    = 0;
            bool   alpha    = false;

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    Color  pixel    = image.GetPixel(x, y);
                    byte[] rgbA5551 = ImageHandler.RGBA8888ToRGBA5551(new byte[4]
                    {
                        pixel.R,
                        pixel.G,
                        pixel.B,
                        pixel.A
                    }, ref alpha);
                    numArray[index]     = rgbA5551[0];
                    numArray[index + 1] = rgbA5551[1];
                    index += 2;
                }
            }
            return(numArray);
        }
Esempio n. 2
0
        public static byte[] ConvertImageToCI8(Bitmap image, ref bool alpha, bool frame = false)
        {
            int width  = image.Width;
            int height = image.Height;

            int[] numArray1 = new int[width * height];
            int   index1    = 0;

            Color[] colorArray = new Color[width * height];
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    colorArray[index1] = image.GetPixel(x, y);
                    ++index1;
                }
            }
            List <Color> colorList = new List <Color>();

            for (int index2 = 0; index2 < colorArray.Length; ++index2)
            {
                if (!colorList.Contains(colorArray[index2]))
                {
                    colorList.Add(colorArray[index2]);
                }
            }
            byte[] numArray2 = new byte[colorList.Count * 4];
            int    index3    = 0;

            for (int index2 = 0; index2 < colorList.Count; ++index2)
            {
                Color color = colorList[index2];
                numArray2[index3]     = color.R;
                numArray2[index3 + 1] = color.G;
                numArray2[index3 + 2] = color.B;
                numArray2[index3 + 3] = color.A;
                index3 += 4;
            }
            int[] numArray3 = new int[width * height];
            int   index4    = 0;

            foreach (Color color in colorArray)
            {
                int num = colorList.IndexOf(color);
                if (num == -1)
                {
                    num = 0;
                }
                numArray3[index4] = num;
                ++index4;
            }
            byte[] numArray4 = new byte[512 + numArray3.Length];
            int    index5    = 0;

            for (int index2 = 0; index2 < numArray2.Length; index2 += 4)
            {
                byte[] rgbA5551 = ImageHandler.RGBA8888ToRGBA5551(new byte[4]
                {
                    numArray2[index2],
                    numArray2[index2 + 1],
                    numArray2[index2 + 2],
                    numArray2[index2 + 3]
                }, ref alpha);
                numArray4[index5]     = rgbA5551[0];
                numArray4[index5 + 1] = rgbA5551[1];
                index5 += 2;
            }
            int index6 = 512;

            if (frame)
            {
                numArray4[index6]     = (byte)0;
                numArray4[index6 + 1] = (byte)0;
                numArray4[index6 + 2] = (byte)0;
                numArray4[index6 + 3] = (byte)0;
                numArray4[index6 + 4] = (byte)0;
                numArray4[index6 + 5] = (byte)width;
                numArray4[index6 + 6] = (byte)0;
                numArray4[index6 + 7] = (byte)height;
                index6 = 520;
            }
            for (int index2 = 0; index2 < numArray3.Length; ++index2)
            {
                numArray4[index6] = (byte)numArray3[index2];
                ++index6;
            }
            return(numArray4);
        }