• 大小: 404.05 KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2024-08-26
  • 语言: C#
  • 标签: c#  GDI  鼠标绘图  

资源简介

c# Winform 鼠标任意绘图 并将缩回图形以png形式保存的本地 背景为透明色

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;

namespace WindowsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }


        private int preX preY;
        private bool isDraw = false;
        private Bitmap bitmap bm;
        private Graphics gB;
        public Bitmap newImage;
        private void button1_Click(object sender EventArgs e)
        {
            minx = minx - 5;
            miny = miny - 5;
            maxx = maxx + 5;
            maxy = maxy + 5;

            // 目标区域
            Rectangle destRect = new Rectangle(0 0 maxx-minx maxy-miny);
            // 源图区域
            Rectangle srcRect = new Rectangle(minx miny maxx - minx maxy - miny);

            // 新建Graphics对象
            newImage = new Bitmap(maxx - minx maxy - miny);
            Graphics g = Graphics.FromImage(newImage);

            // 绘图平滑程序
            //g.SmoothingMode = SmoothingMode.HighQuality;

            // 图片输出质量
            //g.CompositingQuality = CompositingQuality.HighQuality;

            // 输出到newImage对象
            g.DrawImage(BackgroundImage destRect srcRect GraphicsUnit.Pixel);

            // 释放绘图对象
            g.Dispose();
       
            newImage.Save(“D:\\aaa.png“System.Drawing.Imaging.ImageFormat.Png);

             
        }

        private void button2_Click(object sender EventArgs e)
        {
            this.Close();
        }

        private void Form2_Load(object sender EventArgs e)
        {
            Size size = SystemInformation.PrimaryMonitorMaximizedWindowSize;
            bitmap = new Bitmap(size.Width size.Height);
            gB = Graphics.FromImage(bitmap);
            Color bckColor = this.BackColor;
            gB.Clear(bckColor);
        }

        private void RefreshBackground()
        {
            Size sz = this.Size;
            Rectangle rt = new Rectangle(0 0 sz.Width sz.Height);
            bm = bitmap.Clone(rt bitmap.PixelFormat);
            bm.MakeTransparent(Color.Transparent);
            BackgroundImage = bm;
        }

        private void Form2_Paint(object sender PaintEventArgs e)
        {

        }

        private int minx = 0 miny = 0 maxx = 0 maxy = 0;
        private void Form2_MouseUp(object sender MouseEventArgs e)
        {
            if (e.X <= minx) { minx = e.X; }
            if (e.Y <= miny) { miny = e.Y; }
            if (e.X >= maxx) { maxx = e.X; }
            if (e.Y >= maxy) { maxy = e.Y; }
            //append_file(“d:\\mis_err.txt“ minx.ToString() + “;“ + miny.ToString() + “;“ + maxx.ToString() + “;“ + maxy.ToString() + “;“  +“\r\n“);
            RefreshBackground();
            isDraw = false;
        }

  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     目录          0  2009-03-16 10:26  GDI

     目录          0  2009-03-16 10:29  GDI\WindowsApplication1

     目录          0  2009-03-16 10:28  GDI\WindowsApplication1\bin

     目录          0  2009-03-16 10:26  GDI\WindowsApplication1\bin\Debug

     文件     102392  2007-05-08 11:54  GDI\WindowsApplication1\bin\Debug\dsoframer.ocx

     文件    1048576  2007-11-26 11:21  GDI\WindowsApplication1\bin\Debug\Interop.Excel.dll

     文件     155648  2007-06-22 10:39  GDI\WindowsApplication1\bin\Debug\Interop.Office.dll

     文件      57344  2009-03-11 13:34  GDI\WindowsApplication1\bin\Debug\Interop.VBIDE.dll

     文件     585728  2007-06-22 10:39  GDI\WindowsApplication1\bin\Debug\Interop.Word.dll

     文件      24576  2009-03-16 10:29  GDI\WindowsApplication1\bin\Debug\WindowsApplication1.exe

     文件      38400  2009-03-16 10:29  GDI\WindowsApplication1\bin\Debug\WindowsApplication1.pdb

     文件       5632  2005-11-11 22:25  GDI\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe

     文件      20480  2005-10-10 16:00  GDI\WindowsApplication1\bin\Debug\WinWordControl.dll

     文件       4604  2009-03-16 10:29  GDI\WindowsApplication1\Form2.cs

     文件       3242  2009-03-16 10:29  GDI\WindowsApplication1\Form2.Designer.cs

     文件       5814  2009-03-16 10:29  GDI\WindowsApplication1\Form2.resx

     目录          0  2009-03-16 10:26  GDI\WindowsApplication1\obj

     目录          0  2009-03-16 10:29  GDI\WindowsApplication1\obj\Debug

     目录          0  2009-03-16 10:26  GDI\WindowsApplication1\obj\Debug\Refactor

     文件      13241  2009-03-12 15:37  GDI\WindowsApplication1\obj\Debug\ResolveAssemblyReference.cache

     目录          0  2009-03-16 10:26  GDI\WindowsApplication1\obj\Debug\TempPE

     文件        900  2009-03-16 10:29  GDI\WindowsApplication1\obj\Debug\WindowsApplication1.csproj.GenerateResource.Cache

     文件        902  2009-03-11 13:34  GDI\WindowsApplication1\obj\Debug\WindowsApplication1.csproj.ResolveComReference.cache

     文件      24576  2009-03-16 10:29  GDI\WindowsApplication1\obj\Debug\WindowsApplication1.exe

     文件        180  2009-03-16 10:29  GDI\WindowsApplication1\obj\Debug\WindowsApplication1.Form2.resources

     文件      38400  2009-03-16 10:29  GDI\WindowsApplication1\obj\Debug\WindowsApplication1.pdb

     文件        180  2009-03-11 13:34  GDI\WindowsApplication1\obj\Debug\WindowsApplication1.Properties.Resources.resources

     文件       2221  2009-03-16 10:29  GDI\WindowsApplication1\obj\WindowsApplication1.csproj.FileListAbsolute.txt

     文件        478  2009-03-16 10:28  GDI\WindowsApplication1\Program.cs

     目录          0  2009-03-16 10:26  GDI\WindowsApplication1\Properties

............此处省略11个文件信息

评论

共有 条评论