ソースを参照

图片分割工具类

yuzhengyang 8 年 前
コミット
d3a39a2097

BIN
Fork.Net/Test/Y.Test/Images/IconGroup/icongroup_01.png


BIN
Fork.Net/Test/Y.Test/Images/Temp/temp_01.png


BIN
Fork.Net/Test/Y.Test/Images/Temp/temp_02.png


BIN
Fork.Net/Test/Y.Test/Images/Temp/temp_03.png


+ 40 - 0
Fork.Net/Test/Y.Test/Properties/Resources.Designer.cs

@@ -63,11 +63,51 @@ namespace Y.Test.Properties {
         /// <summary>
         ///   查找 System.Drawing.Bitmap 类型的本地化资源。
         /// </summary>
+        internal static System.Drawing.Bitmap icongroup_01 {
+            get {
+                object obj = ResourceManager.GetObject("icongroup_01", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
+        /// </summary>
         internal static System.Drawing.Bitmap Rainbow {
             get {
                 object obj = ResourceManager.GetObject("Rainbow", resourceCulture);
                 return ((System.Drawing.Bitmap)(obj));
             }
         }
+        
+        /// <summary>
+        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
+        /// </summary>
+        internal static System.Drawing.Bitmap temp_01 {
+            get {
+                object obj = ResourceManager.GetObject("temp_01", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
+        /// </summary>
+        internal static System.Drawing.Bitmap temp_02 {
+            get {
+                object obj = ResourceManager.GetObject("temp_02", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
+        /// <summary>
+        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
+        /// </summary>
+        internal static System.Drawing.Bitmap temp_03 {
+            get {
+                object obj = ResourceManager.GetObject("temp_03", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
     }
 }

+ 12 - 0
Fork.Net/Test/Y.Test/Properties/Resources.resx

@@ -118,7 +118,19 @@
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <data name="icongroup_01" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Images\IconGroup\icongroup_01.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
   <data name="Rainbow" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Images\BackgroundImages\Rainbow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
+  <data name="temp_01" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Images\Temp\temp_01.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="temp_02" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Images\Temp\temp_02.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="temp_03" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Images\Temp\temp_03.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
 </root>

+ 13 - 0
Fork.Net/Test/Y.Test/Views/MainForm.Designer.cs

@@ -32,6 +32,7 @@
             this.TestComputerInfoForm = new System.Windows.Forms.Button();
             this.TestUpdateForm = new System.Windows.Forms.Button();
             this.TestPackForm = new System.Windows.Forms.Button();
+            this.TestIconGroupForm = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // ChineseCalendarForm
@@ -74,11 +75,22 @@
             this.TestPackForm.UseVisualStyleBackColor = true;
             this.TestPackForm.Click += new System.EventHandler(this.TestPackForm_Click);
             // 
+            // TestIconGroupForm
+            // 
+            this.TestIconGroupForm.Location = new System.Drawing.Point(70, 322);
+            this.TestIconGroupForm.Name = "TestIconGroupForm";
+            this.TestIconGroupForm.Size = new System.Drawing.Size(262, 23);
+            this.TestIconGroupForm.TabIndex = 4;
+            this.TestIconGroupForm.Text = "TestIconGroupForm";
+            this.TestIconGroupForm.UseVisualStyleBackColor = true;
+            this.TestIconGroupForm.Click += new System.EventHandler(this.TestIconGroupForm_Click);
+            // 
             // MainForm
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(564, 427);
+            this.Controls.Add(this.TestIconGroupForm);
             this.Controls.Add(this.TestPackForm);
             this.Controls.Add(this.TestUpdateForm);
             this.Controls.Add(this.TestComputerInfoForm);
@@ -95,5 +107,6 @@
         private System.Windows.Forms.Button TestComputerInfoForm;
         private System.Windows.Forms.Button TestUpdateForm;
         private System.Windows.Forms.Button TestPackForm;
+        private System.Windows.Forms.Button TestIconGroupForm;
     }
 }

+ 5 - 0
Fork.Net/Test/Y.Test/Views/MainForm.cs

@@ -36,5 +36,10 @@ namespace Y.Test.Views
         {
             R.Forms.GetUnique<TestPackForm>().Show();
         }
+
+        private void TestIconGroupForm_Click(object sender, EventArgs e)
+        {
+            R.Forms.GetUnique<TestIconGroupForm>().Show();
+        }
     }
 }

+ 90 - 0
Fork.Net/Test/Y.Test/Views/TestIconGroupForm.Designer.cs

@@ -0,0 +1,90 @@
+namespace Y.Test.Views
+{
+    partial class TestIconGroupForm
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.pictureBox3 = new System.Windows.Forms.PictureBox();
+            this.pictureBox2 = new System.Windows.Forms.PictureBox();
+            this.pictureBox1 = new System.Windows.Forms.PictureBox();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // pictureBox3
+            // 
+            this.pictureBox3.Image = global::Y.Test.Properties.Resources.temp_03;
+            this.pictureBox3.Location = new System.Drawing.Point(12, 177);
+            this.pictureBox3.Name = "pictureBox3";
+            this.pictureBox3.Size = new System.Drawing.Size(77, 59);
+            this.pictureBox3.TabIndex = 2;
+            this.pictureBox3.TabStop = false;
+            // 
+            // pictureBox2
+            // 
+            this.pictureBox2.Image = global::Y.Test.Properties.Resources.temp_02;
+            this.pictureBox2.Location = new System.Drawing.Point(12, 97);
+            this.pictureBox2.Name = "pictureBox2";
+            this.pictureBox2.Size = new System.Drawing.Size(77, 59);
+            this.pictureBox2.TabIndex = 1;
+            this.pictureBox2.TabStop = false;
+            // 
+            // pictureBox1
+            // 
+            this.pictureBox1.Image = global::Y.Test.Properties.Resources.temp_01;
+            this.pictureBox1.Location = new System.Drawing.Point(12, 12);
+            this.pictureBox1.Name = "pictureBox1";
+            this.pictureBox1.Size = new System.Drawing.Size(77, 59);
+            this.pictureBox1.TabIndex = 0;
+            this.pictureBox1.TabStop = false;
+            // 
+            // TestIconGroupForm
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(284, 261);
+            this.Controls.Add(this.pictureBox3);
+            this.Controls.Add(this.pictureBox2);
+            this.Controls.Add(this.pictureBox1);
+            this.Name = "TestIconGroupForm";
+            this.Text = "TestIconGroupForm";
+            this.Load += new System.EventHandler(this.TestIconGroupForm_Load);
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.PictureBox pictureBox1;
+        private System.Windows.Forms.PictureBox pictureBox2;
+        private System.Windows.Forms.PictureBox pictureBox3;
+    }
+}

+ 28 - 0
Fork.Net/Test/Y.Test/Views/TestIconGroupForm.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using Y.Test.Properties;
+using Y.Utils.IOUtils.ImageUtils;
+
+namespace Y.Test.Views
+{
+    public partial class TestIconGroupForm : Form
+    {
+        public TestIconGroupForm()
+        {
+            InitializeComponent();
+        }
+
+        private void TestIconGroupForm_Load(object sender, EventArgs e)
+        {
+            //pictureBox1.Image = ImageSpliter.Get(Resources.icongroup_01, 50, 50, 1, 1);
+            //pictureBox2.Image = ImageSpliter.Get(Resources.icongroup_01, 50, 50, 2, 1);
+            //pictureBox3.Image = ImageSpliter.Get(Resources.icongroup_01, 50, 50, 3, 1);
+        }
+    }
+}

+ 120 - 0
Fork.Net/Test/Y.Test/Views/TestIconGroupForm.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 13 - 0
Fork.Net/Test/Y.Test/Y.Test.csproj

@@ -112,6 +112,12 @@
     <Compile Include="Views\TestComputerInfoForm.Designer.cs">
       <DependentUpon>TestComputerInfoForm.cs</DependentUpon>
     </Compile>
+    <Compile Include="Views\TestIconGroupForm.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Views\TestIconGroupForm.Designer.cs">
+      <DependentUpon>TestIconGroupForm.cs</DependentUpon>
+    </Compile>
     <Compile Include="Views\TestInputForm.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -170,6 +176,9 @@
     <EmbeddedResource Include="Views\TestComputerInfoForm.resx">
       <DependentUpon>TestComputerInfoForm.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="Views\TestIconGroupForm.resx">
+      <DependentUpon>TestIconGroupForm.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Views\TestInputForm.resx">
       <DependentUpon>TestInputForm.cs</DependentUpon>
     </EmbeddedResource>
@@ -225,6 +234,10 @@
     </BootstrapperPackage>
   </ItemGroup>
   <ItemGroup>
+    <Content Include="Images\IconGroup\icongroup_01.png" />
+    <Content Include="Images\Temp\temp_01.png" />
+    <Content Include="Images\Temp\temp_02.png" />
+    <Content Include="Images\Temp\temp_03.png" />
     <None Include="FodyWeavers.xml" />
     <Content Include="Images\BackgroundImages\Rainbow.png" />
   </ItemGroup>

+ 69 - 0
Fork.Net/Y.Utils/IOUtils/ImageUtils/ImageSpliter.cs

@@ -0,0 +1,69 @@
+//************************************************************************
+//      https://github.com/yuzhengyang
+//      author:     yuzhengyang
+//      date:       2017.9.1 - 2017.9.1
+//      desc:       图片分块工具
+//      Copyright (c) yuzhengyang. All rights reserved.
+//************************************************************************
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+
+namespace Y.Utils.IOUtils.ImageUtils
+{
+    public class ImageSpliter
+    {
+        private int Width = 0;
+        private int Height = 0;
+        private Image Image;
+        public ImageSpliter(string file, int width, int height)
+        {
+            Image = Image.FromFile(file);
+            Width = width;
+            Height = height;
+        }
+        public ImageSpliter(Image src, int width, int height)
+        {
+            Image = src;
+            Width = width;
+            Height = height;
+        }
+        public Bitmap Get(int x, int y)
+        {
+            if (Image != null && Image.Width >= x * Width && Image.Height >= y * Height)
+            {
+                //创建新图位图   
+                Bitmap bitmap = new Bitmap(Width, Height);
+                //创建作图区域   
+                using (Graphics graphic = Graphics.FromImage(bitmap))
+                {
+                    //截取原图相应区域写入作图区   
+                    graphic.DrawImage(Image, 0, 0, new Rectangle((x - 1) * Width, (y - 1) * Height, Width, Height), GraphicsUnit.Point);
+                }
+            }
+            return null;
+        }
+        public static Bitmap Get(Image img, int height, int width, int x, int y)
+        {
+            try
+            {
+                if (img != null && img.Width >= x * width && img.Height >= y * height)
+                {
+                    //创建新图位图   
+                    Bitmap rs = new Bitmap(width, height);
+                    //创建作图区域   
+                    Graphics graphic = Graphics.FromImage(rs);
+                    //截取原图相应区域写入作图区   
+                    graphic.DrawImage(img, 0, 0, new Rectangle((x - 1) * width, (y - 1) * height, width, height), GraphicsUnit.Pixel);
+                    graphic.Dispose();
+                    img.Dispose();
+                    return rs;
+                }
+            }
+            catch { }
+            return null;
+        }
+    }
+}

+ 1 - 0
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -54,6 +54,7 @@
     <Compile Include="AppUtils\AppLaunchTool.cs" />
     <Compile Include="AppUtils\AppUnique.cs" />
     <Compile Include="DataUtils\DateTimeUtils\DateTool.cs" />
+    <Compile Include="IOUtils\ImageUtils\ImageSpliter.cs" />
     <Compile Include="UpdateUtils\AppUpdateInfo.cs" />
     <Compile Include="UpdateUtils\AppUpdateTool.cs" />
     <Compile Include="DataUtils\RandomUtils\RandomTool.cs" />