Ejemplo n.º 1
0
        public void CommitChanges(Texture currentSkin, bool save)
        {
            using (var grabber = new ColorGrabber(currentSkin, Width, Height))
            {
                grabber.Load();

                if (currentSkin != GLImage)
                {
                    grabber.Texture = GLImage;
                    grabber.Save();
                }

                if (save)
                {
                    var newBitmap = new Bitmap(Width, Height);

                    using (var fp = new FastPixel(newBitmap, true))
                    {
                        for (int y = 0; y < Height; ++y)
                        {
                            for (int x = 0; x < Width; ++x)
                            {
                                ColorPixel c = grabber[x, y];
                                fp.SetPixel(x, y, Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue));
                            }
                        }
                    }

                    newBitmap.Save(File.FullName);
                    newBitmap.Dispose();

                    var md = new Dictionary <string, string>();
                    md.Add("Model", Model.Path);
                    PNGMetadata.WriteMetadata(File.FullName, md);

                    SetImages(true);

                    Dirty = false;
                }
            }
        }
Ejemplo n.º 2
0
        public void Resize(int width, int height, ResizeType type = ResizeType.Scale)
        {
            using (var newBitmap = new Bitmap(width, height))
            {
                using (Graphics g = Graphics.FromImage(newBitmap))
                {
                    g.SmoothingMode     = SmoothingMode.None;
                    g.InterpolationMode = InterpolationMode.NearestNeighbor;
                    g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                    g.Clear(Color.FromArgb(0, 0, 0, 0));

                    using (Image temp = System.Drawing.Image.FromFile(File.FullName))
                    {
                        if (type == ResizeType.Scale)
                        {
                            g.DrawImage(temp, 0, 0, newBitmap.Width, newBitmap.Height);
                        }
                        else
                        {
                            g.DrawImage(temp, 0, 0, temp.Width, temp.Height);
                        }
                    }
                }

                newBitmap.Save(File.FullName);

                var md = new Dictionary <string, string>();
                md.Add("Model", Model.Name);
                PNGMetadata.WriteMetadata(File.FullName, md);
            }

            SetImages();

            Undo.Clear();
            Editor.MainForm.CheckUndo();
        }