使用图形进行编辑后保存未编辑位图的代码

时间:2019-07-05 23:36:57

标签: c# graphics bitmap

编辑后不保存更改

我尝试过多种尝试来保存它

protected override void OnPaint(PaintEventArgs e)
    {
        Image img = Image.FromFile("bitmap2.bmp");
        //this.Width = img.Width;
        //this.Height = img.Height;
        var h = img.Height / 2;
        var w = img.Width / 2;
        GraphicsPath path = new GraphicsPath();
        // add a set of points that define the shape
        //the etika logo shape

        path.AddLines(new Point[]
        {
            new Point(175, 150),
            new Point(250, 150),
            new Point(115, 383),
            new Point(40, 383),
            /*new Point(280, 150),
            new Point(265, 150),
            new Point(245, 208),
            new Point(230, 208)*/
        });

        // close the shape
        path.CloseAllFigures();

        path.AddLines(new Point[]
        {
            new Point(280, 150),
            new Point(465, 150),
            new Point(430, 208),
            new Point(245, 208)
        });
        path.CloseAllFigures();

        path.AddLines(new Point[]
        {
            new Point(230, 235),
            new Point(415, 235),
            new Point(380, 295),
            new Point(195, 295)
        });
        path.CloseAllFigures();

        path.AddLines(new Point[]
        {
            new Point(180, 325),
            new Point(365, 325),
            new Point(330, 380),
            new Point(145, 380)
        });
        // set the clop region of the forms graphic object to be the new shape
        e.Graphics.Clip = new Region(path);
        // draw the image cliped to the custom shape
        e.Graphics.DrawImage(img, new Point(placex, placey));

这是无法正常工作的代码领域,并且确实很难修复它             //保存

        if (save == true)
        {
            img.Save(SavePath, ImageFormat.Png);
            save = false;
        }
    }

我希望它可以将图形保存为图像上的裁剪图,但仅保存源图像

0 个答案:

没有答案