SaveToFile() public method

Save the contents of the image to a file
public SaveToFile ( string filename ) : bool
filename string Path of the file to save (overwritten if already exist)
return bool
示例#1
0
        public static void execute() // executes the pipeline
        {
            if (win == null) return;

            Graphics.frame_index++;

            render_target = win;

            win.Clear(familiarize_color(back_color));

            Statistics.sprites_drawn = 0;
            Statistics.sprites_discarded = 0;

            Pipeline.execute();

            win.Display();

            if (screenshot_signal)
            {
                bool found = false; int ctr = 0; string path = "";
                while (!found)
                {
                    path = XF.Application.root_path +  "screenshot" + ctr + ".png";
                    found = !System.IO.File.Exists(path);
                    ctr++;
                }

                SFML.Graphics.Image screenshot = new SFML.Graphics.Image(screen_w, screen_h);
                screenshot.CopyScreen(win) ;
                screenshot.SaveToFile(path);

                screenshot_signal = false;
            }

        } 
示例#2
0
        private void btnSplit_Click(object sender, EventArgs e)
        {
            if (Resource != null)
            {
                btnSplit.Visible = false;

                if (!Directory.Exists(txtOutputPath.Text))
                {
                    Directory.CreateDirectory(txtOutputPath.Text);
                }

                var srcExt = txtFile.Text.Substring(
                    txtFile.Text.LastIndexOf(".") + 1);
                var srcName = txtFile.Text.Substring(
                    txtFile.Text.LastIndexOf(Path.DirectorySeparatorChar) + 1).Replace("." + srcExt, string.Empty);

                var cols   = ((int)numericX.Value >= 1) ? (int)numericX.Value : 1;
                var rows   = ((int)numericY.Value >= 1) ? (int)numericY.Value : 1;
                var width  = (int)Resource.Image.Size.X / cols;
                var height = (int)Resource.Image.Size.Y / rows;

                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < cols; c++)
                    {
                        var destName = txtOutputFormat.Text.Replace(
                            "%f", srcName).Replace(
                            "%ext", srcExt).Replace(
                            "%r", r.ToString()).Replace(
                            "%c", c.ToString()).Replace(
                            "%t", ((r * cols) + c).ToString());

                        Image image = new Image((uint)width, (uint)height);
                        image.Copy(Resource.Image, 0, 0, new IntRect(c * width, r * height, width, height));

                        image.SaveToFile(txtOutputPath.Text + destName);
                        image?.Dispose();
                        image = null;

                        Application.DoEvents();
                    }
                }

                btnSplit.Visible = true;
            }

            txtFile.Focus();
        }
示例#3
0
 static void SaveTextureToTempFile(Image texture)
 {
     var f = new TempFile();
     texture.SaveToFile(f.FilePath);
 }
示例#4
0
        static void Main(string[] args)
        {
            var palette = new Image("palette.png");
            palVec = new Vector3f[256];

            for (uint x = 0; x < palVec.Length; x++)
            {
                palVec[x] = (Vector3f)palette.GetPixel(x, 0);
            }

            var image = new Image("test.png");
            var imgVec = new Vector3f[image.Size.X, image.Size.Y];
            var imgRes = new byte[image.Size.X, image.Size.Y];

            for (uint y = 0; y < image.Size.Y; y++)
            {
                for (uint x = 0; x < image.Size.X; x++)
                {
                    imgVec[x, y] = (Vector3f)image.GetPixel(x, y);
                }
            }

            for (uint y = 0; y < image.Size.Y; y++)
            {
                for (uint x = 0; x < image.Size.X; x++)
                {
                    if (x == 0 || y == 0 || x == image.Size.X - 1 || y == image.Size.Y - 1)
                    {
                        imgRes[x, y] = FindClosestColor(imgVec[x, y]);
                        continue;
                    }

                    var oldPix = imgVec[x, y];
                    var newCol = FindClosestColor(oldPix);
                    var newPix = palVec[newCol];
                    var error = oldPix - newPix;

                    imgRes[x, y] = newCol;

                    imgVec[x + 1, y + 0] += error * (7.0f / 16.0f);
                    imgVec[x - 1, y + 1] += error * (3.0f / 16.0f);
                    imgVec[x + 0, y + 1] += error * (5.0f / 16.0f);
                    imgVec[x + 1, y + 1] += error * (1.0f / 16.0f);
                }
            }

            for (uint y = 0; y < image.Size.Y; y++)
            {
                for (uint x = 0; x < image.Size.X; x++)
                {
                    image.SetPixel(x, y, (Color)palVec[imgRes[x, y]]);
                }
            }

            image.SaveToFile("out.png");

            var o = File.OpenWrite("out.pic");
            for (uint y = 0; y < image.Size.Y; y++)
            {
                for (uint x = 0; x < image.Size.X; x++)
                {
                    o.WriteByte(imgRes[x, y]);
                }
            }
            o.Dispose();
        }