public static Bitmap[] LoadGIFFrames(string gifFile, int requiredFrameCount) { Image image = Image.FromFile(gifFile); FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]); int frameCount = image.GetFrameCount(dimension); Bitmap[] bitmapArray = new Bitmap[requiredFrameCount]; for (int frameIndex = 0; frameIndex < frameCount && frameIndex < requiredFrameCount; ++frameIndex) { image.SelectActiveFrame(dimension, frameIndex); bitmapArray[frameIndex] = new Bitmap(image.Size.Width, image.Size.Height); Graphics.FromImage((Image)bitmapArray[frameIndex]).DrawImage(image, new Point(0, 0)); Bitmap bitmap = new Bitmap(32, 32, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage((Image)bitmap)) graphics.DrawImage((Image)bitmapArray[frameIndex], new Rectangle(0, 0, 32, 32)); bitmapArray[frameIndex] = bitmap; bitmapArray[frameIndex] = ImageHandler.ConvertTo256Colour(bitmapArray[frameIndex]); } for (int index = 0; frameCount + index < requiredFrameCount; ++index) { bitmapArray[frameCount + index] = bitmapArray[index]; } return(bitmapArray); }
private void RipTextureCI( ref List <TextureData> TextureDataList, ref List <TextureData> TextureDataAlphaList, ref List <TextureSetting> TextureSettingsList, ref List <TextureSetting> TextureSettingsAlphaList) { string str = ""; try { this.texturePalSize = new List <int>(); this.isAlpha = new bool[this.textureFiles.Length]; for (int index = 0; index < this.textureFiles.Length; ++index) { this.isAlpha[index] = false; if (this.textureFiles[index] != "" && this.textureFiles[index] != null) { str = this.dir + this.textureFiles[index]; Bitmap image = new Bitmap(this.dir + this.textureFiles[index]); ImageHandler.CorrectSize(ref image); int width = image.Width; int height = image.Height; List <Color> uniqueColors = ImageHandler.GetUniqueColors(ref image); bool alpha = false; if (uniqueColors.Count <= 22 || width * height >= 4096) { if (uniqueColors.Count > 16) { image = ImageHandler.ConvertTo16Colour(image); } TextureData textureData = new TextureData(ImageHandler.ConvertImageToCI4(image, ref alpha), ImageHandler.ConvertImageToRGBA8888(image), image.Width, image.Height); if (alpha) { TextureDataAlphaList.Add(textureData); TextureSetting textureSetting = new TextureSetting(textureData.width, textureData.height, 0, 0, TextureDataAlphaList.Count <TextureData>() - 1); textureSetting.name = this.textureNames[index]; textureSetting.setRatio(0.5f, 0.5f); textureSetting.palSize = 16; textureSetting.ISALPHA = true; textureSetting.cull_back = true; TextureSettingsAlphaList.Add(textureSetting); } else { TextureDataList.Add(textureData); TextureSetting textureSetting = new TextureSetting(textureData.width, textureData.height, 0, 0, TextureDataList.Count <TextureData>() - 1); textureSetting.name = this.textureNames[index]; textureSetting.setRatio(0.5f, 0.5f); textureSetting.palSize = 16; textureSetting.cull_back = true; TextureSettingsList.Add(textureSetting); } this.texturePalSize.Add(16); } else if (width * height < 4096) { this.texturePalSize.Add(256); if (uniqueColors.Count > 256) { image = ImageHandler.ConvertTo256Colour(image); } TextureData textureData = new TextureData(ImageHandler.ConvertImageToCI8(image, ref alpha, false), ImageHandler.ConvertImageToRGBA8888(image), image.Width, image.Height); if (alpha) { TextureDataAlphaList.Add(textureData); TextureSetting textureSetting = new TextureSetting(textureData.width, textureData.height, 0, 0, TextureDataAlphaList.Count <TextureData>() - 1); textureSetting.name = this.textureNames[index]; textureSetting.setRatio(0.5f, 0.5f); textureSetting.palSize = 256; textureSetting.ISALPHA = true; textureSetting.cull_back = true; TextureSettingsAlphaList.Add(textureSetting); } else { TextureDataList.Add(textureData); TextureSetting textureSetting = new TextureSetting(textureData.width, textureData.height, 0, 0, TextureDataList.Count <TextureData>() - 1); textureSetting.name = this.textureNames[index]; textureSetting.setRatio(0.5f, 0.5f); textureSetting.palSize = 256; textureSetting.cull_back = true; TextureSettingsList.Add(textureSetting); } } } else { TextureDataList.Add(new TextureData()); TextureSetting textureSetting = new TextureSetting(0, 0, 0, 0, -1); textureSetting.name = this.textureNames[index]; textureSetting.setRatio(0.5f, 0.5f); textureSetting.cull_back = true; TextureSettingsList.Add(textureSetting); this.texturePalSize.Add(0); } } } catch (Exception ex) { int num = (int)MessageBox.Show("An error occured while converting texture " + str + ", please check all files are present and try again."); } }