Exemplo n.º 1
0
        internal static Bitmap GetImg(Clim bclim)
        {
            if (bclim.FileFormat == 7 && BitConverter.ToUInt16(bclim.Data, 0) == 2)                 // XY7
            {
                return(Bclim.GetIMG_XY7(bclim));
            }
            if (bclim.FileFormat == 10 || bclim.FileFormat == 11)               // Use ETC1 to get image instead.
            {
                return(Bclim.GetIMG_ETC(bclim));
            }
            // New Image
            int w    = Bclim.Nlpo2(Bclim.Gcm(bclim.Width, 8));
            int h    = Bclim.Nlpo2(Bclim.Gcm(bclim.Height, 8));
            int f    = bclim.FileFormat;
            int area = w * h;

            if (f == 9 && area > bclim.Data.Length / 4)
            {
                w = Bclim.Gcm(bclim.Width, 8);
                h = Bclim.Gcm(bclim.Height, 8);
            }
            // Build Image
            return(Bclim.GetImg(w, h, bclim.Data, f));
        }
Exemplo n.º 2
0
        internal static Image MakeBmp(string path, bool autosave = false, bool crop = true)
        {
            Clim bclim = Bclim.Analyze(path);

            if (bclim.Magic != 0x4D494C43)
            {
                return(null);
            }

            // Interpret data.
            int f = bclim.FileFormat;

            if (f > 13)
            {
                return(null);
            }

            Bitmap img;

            if (f == 7 && BitConverter.ToUInt16(bclim.Data, 0) == 2)
            {
                // PKM XY Format 7 (Color Palette)
                img = Bclim.GetIMG_XY7(bclim);
            }
            else if (f == 10 || f == 11)
            {
                img = Bclim.GetIMG_ETC(bclim);
            }
            else
            {
                img = Bclim.GetImg(bclim);
            }

            if (img == null)
            {
                return(null);
            }
            Rectangle cropRect = new Rectangle(0, 0, bclim.Width, bclim.Height);
            Bitmap    cropBmp  = new Bitmap(cropRect.Width, cropRect.Height);

            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(cropBmp))
            {
                g.DrawImage(img,
                            new Rectangle(0, 0, cropBmp.Width, cropBmp.Height),
                            cropRect,
                            GraphicsUnit.Pixel);
            }
            if (!autosave)
            {
                return(!crop
                                                   ? img
                                                   : cropBmp);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                //error will throw from here
                cropBmp.Save(ms, ImageFormat.Png);
                byte[] data = ms.ToArray();
                File.WriteAllBytes(bclim.FilePath + "\\" + bclim.FileName + ".png", data);
            }
            return(!crop
                                           ? img
                                           : cropBmp);
        }