资源简介

C#桌面多显示器截图,模仿WIN系统截图工具,支持自定义截图路径及截图大小

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace SnippingTool
{
    public static class ImageHelper
    {
        public static Image resize(this Image img int heigth int width bool keepAspectRatio = false bool getCenter = false)
        {
            int newheigth = heigth;
           
            // Prevent using images internal thumbnail
            img.RotateFlip(RotateFlipType.Rotate180FlipNone);
            img.RotateFlip(RotateFlipType.Rotate180FlipNone);

            if (keepAspectRatio || getCenter)
            {
                int bmpY = 0;
                double resize = (double)img.Width / (double)width;//get the resize vector
                if (getCenter)
                {
                    bmpY = (int)((img.Height - (heigth * resize)) / 2);// gives the Y value of the part that will be cut off to show only the part in the center
                    Rectangle section = new Rectangle(new Point(0 bmpY) new Size(img.Width (int)(heigth * resize)));// create the section to cut of the original image
                                                                                                                                 //System.Console.WriteLine(“the section that will be cut off: “ + section.Size.ToString() + “ the Y value is minimized by: “ + bmpY);
                    Bitmap orImg = new Bitmap((Bitmap)img);//for the correct effect convert image to bitmap.
                    img.Dispose();//clear the original image
                    using (Bitmap tempImg = new Bitmap(section.Width section.Height))
                    {
                        Graphics cutImg = Graphics.FromImage(tempImg);//              set the file to save the new image to.
                        cutImg.DrawImage(orImg 0 0 section GraphicsUnit.Pixel);// cut the image and save it to tempImg
                        img = tempImg;//save the tempImg as img for resizing later
                        orImg.Dispose();
                        cutImg.Dispose();
                        return img.GetThumbnailImage(width heigth null IntPtr.Zero);
                    }
                }
                else newheigth = (int)(img.Height / resize);//  set the new heigth of the current image
            }//return the image resized to the given heigth and width

            return img.GetThumbnailImage(width newheigth null IntPtr.Zero);
        }
    }
}

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

     文件       2508  2020-09-05 09:38  SnippingTool\ImageHelper.cs

     文件       1399  2020-09-05 09:45  SnippingTool\INIHelper.cs

     文件       4851  2020-09-05 11:08  SnippingTool\MainForm.cs

     文件       9989  2020-09-05 10:56  SnippingTool\MainForm.Designer.cs

     文件     145397  2020-09-05 10:56  SnippingTool\MainForm.resx

     文件        208  2020-09-05 08:01  SnippingTool\obj\Debug\.NETframeworkVersion=v4.0.AssemblyAttributes.cs

     文件       1119  2020-09-05 08:08  SnippingTool\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7018  2020-09-05 09:34  SnippingTool\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件         42  2020-09-05 10:00  SnippingTool\obj\Debug\SnippingTool.csproj.CoreCompileInputs.cache

     文件       1373  2020-09-05 10:00  SnippingTool\obj\Debug\SnippingTool.csproj.FileListAbsolute.txt

     文件       1139  2020-09-05 10:51  SnippingTool\obj\Debug\SnippingTool.csproj.GenerateResource.cache

     文件     183296  2020-09-05 10:52  SnippingTool\obj\Debug\SnippingTool.exe

     文件      93196  2020-09-05 10:51  SnippingTool\obj\Debug\SnippingTool.MainForm.resources

     文件        180  2020-09-05 10:31  SnippingTool\obj\Debug\SnippingTool.OptionForm.resources

     文件      56832  2020-09-05 10:52  SnippingTool\obj\Debug\SnippingTool.pdb

     文件        180  2020-09-05 10:00  SnippingTool\obj\Debug\SnippingTool.Properties.Resources.resources

     文件        180  2020-09-05 10:00  SnippingTool\obj\Debug\SnippingTool.SnipForm.resources

     文件       3584  2020-09-05 08:19  SnippingTool\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        208  2021-01-14 15:05  SnippingTool\obj\Release\.NETframeworkVersion=v4.0.AssemblyAttributes.cs

     文件       6865  2020-09-05 09:44  SnippingTool\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache

     文件         42  2020-09-05 11:08  SnippingTool\obj\Release\SnippingTool.csproj.CoreCompileInputs.cache

     文件       1674  2021-01-14 15:05  SnippingTool\obj\Release\SnippingTool.csproj.FileListAbsolute.txt

     文件       1139  2020-09-05 11:08  SnippingTool\obj\Release\SnippingTool.csproj.GenerateResource.cache

     文件        424  2021-01-14 15:05  SnippingTool\obj\Release\SnippingTool.csprojAssemblyReference.cache

     文件     182272  2021-01-14 15:05  SnippingTool\obj\Release\SnippingTool.exe

     文件      93193  2021-01-14 15:05  SnippingTool\obj\Release\SnippingTool.MainForm.resources

     文件        180  2021-01-14 15:05  SnippingTool\obj\Release\SnippingTool.OptionForm.resources

     文件      58880  2021-01-14 15:05  SnippingTool\obj\Release\SnippingTool.pdb

     文件        180  2021-01-14 15:05  SnippingTool\obj\Release\SnippingTool.Properties.Resources.resources

     文件        180  2021-01-14 15:05  SnippingTool\obj\Release\SnippingTool.SnipForm.resources

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

评论

共有 条评论