コード例 #1
0
 public Bitmap LoadImage(DevIL.ImageImporter ImImport, MemoryStream mStream, int width = 128, int height = 128)
 {
     try
     {
         Bitmap img2 = null;
         using (DevIL.Image IconImg = ImImport.LoadImageFromStream(mStream))
         {
             IconImg.Bind();
             using (var img = new Bitmap(IconImg.Width, IconImg.Height, PixelFormat.Format32bppArgb))
             {
                 Rectangle  rect = new Rectangle(0, 0, IconImg.Width, IconImg.Height);
                 BitmapData data = img.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                 DevIL.Unmanaged.IL.CopyPixels(0, 0, 0, IconImg.Width, IconImg.Height, 1, DevIL.DataFormat.BGRA, DevIL.DataType.UnsignedByte, data.Scan0);
                 img.UnlockBits(data);
                 img2 = (Bitmap)img.Clone();
             }
         }
         return(img2);
     }
     catch
     {
         return(new Bitmap(width, height));
     }
 }
コード例 #2
0
        public bool saveImage(string fileName)
        {
            try
            {
                string txtFile    = fileName.Replace(".dds", ".txt");
                string txtFilepng = fileName.Replace(".dds", ".png");
                try
                {
                    File.Delete(fileName);
                }

                catch { }
                GeneralIcon[] array = currentIcons.Values.ToArray();
                StringBuilder sb    = new StringBuilder();
                sb.AppendLine(w.ToString());
                sb.AppendLine(h.ToString());
                int rrow = array.Length / cols;
                sb.AppendLine(rrow.ToString());
                sb.AppendLine(cols.ToString());
                int imageWidth = w * cols;
                using (Bitmap img = new Bitmap(imageWidth, imageWidth, PixelFormat.Format32bppArgb))
                {
                    using (Graphics graphics = Graphics.FromImage(img))
                    {
                        int x, y = 0;

                        for (int i = 0; i < array.Length; i++)
                        {
                            GeneralIcon icon = array[i];
                            y = i / cols;
                            x = i - y * cols;
                            x = x * w;
                            y = y * h;
                            graphics.DrawImage(icon.icon, x, y);
                            sb.AppendLine(icon.name);
                        }
                    }
                    using (DevIL.ImageImporter ImImport = new DevIL.ImageImporter())
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                            using (DevIL.Image IconImg = ImImport.LoadImageFromStream(new MemoryStream(ms.ToArray())))
                            {
                                IconImg.Bind();
                                ImageExporter exporter = new ImageExporter();
                                exporter.SaveImage(IconImg, ImageType.Dds, fileName);
                            }
                        }
                    }

                    File.WriteAllText(txtFile, sb.ToString(), Encoding.GetEncoding("GBK"));
                }
                Remake();
                return(true);
            }
            catch
            {
                return(false);
            }
        }