• 大小: 687KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-01
  • 语言: C#
  • 标签: 图片颜色  

资源简介

分析图片颜色分布所占比例,利用rgb函数获取图片的所有像素,进行计算。

资源截图

代码片段和文件信息

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 System.Collections;
using System.Runtime.InteropServices;
using System.Diagnostics;


namespace ColorStatistics
{
    public partial class FrmTest : Form
    {
        public FrmTest()
        {
            InitializeComponent();
        }

        List MC;
        int PixelAmount = 0;

        private void CmdOpen_Click(object sender EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.FilterIndex = 4;
            openFileDialog.RestoreDirectory = true;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Thumb.Image =  (Bitmap)Bitmap.FromFile(openFileDialog.FileName);
              
            }
        }
        public static Color IntToColor(int color)
        {
            int R = color & 255;
            int G = (color & 65280) / 256;
            int B = (color & 16711680) / 65536;
            return Color.FromArgb(255 R G B);
        }

        private void PicR_Click(object sender EventArgs e)
        {

        }

        private void PicR_Paint(object sender PaintEventArgs e)
        {
            if (MC != null)
            {
                e.Graphics.Clear(PicR.BackColor);
                Font font = new Font(“宋体“ 9f);
                SolidBrush B = new SolidBrush(Color.Black);
                e.Graphics.DrawString(“      颜色        “ font B new PointF(0 0));
                e.Graphics.DrawString(“     百分比      “ font B new PointF(120 0));
                e.Graphics.DrawString(“数量“ font B new PointF(250 0));
                B.Dispose();
                for (int i = 0; i < MC.Count; i++)
                {
                    B = new SolidBrush(IntToColor(MC[i].Color));
                    e.Graphics.FillRectangle(B new Rectangle(0 (i + 1) * 20 100 15));
                    e.Graphics.DrawString(((double)MC[i].Amount / PixelAmount).ToString() font B new PointF(120 (i + 1) * 20 + 3));
                    e.Graphics.DrawString(MC[i].Amount.ToString() font B new PointF(250 (i + 1) * 20 + 3));
                    B.Dispose();
                }
                font.Dispose();
            }
        }

        private void CmdDeal_Click(object sender EventArgs e)
        {
           
            if (Thumb.Image !=null ) 
            {
                Stopwatch Sw = new Stopwatch();
                Sw.Start();
                MC = Statistics.PrincipalColorAnalysis((Bitmap)Thumb.ImageSliderColorAmount.Value SliderDelta.Value);
                Sw.Stop();
                LblStatus.Text   = “计算主成分用时: “  +Sw.ElapsedMilliseconds.ToString() + “ 毫秒“;
                PixelAmount = Thumb.Image.Width * Thumb.Image.Height;
     

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

     文件      11600  2013-06-20 21:07  ColorStatistics\bin\Debug\ColorStatistics.vshost.exe

     文件        490  2010-03-17 22:39  ColorStatistics\bin\Debug\ColorStatistics.vshost.exe.manifest

     文件     773120  2013-06-23 10:23  ColorStatistics\bin\Release\ColorStatistics.exe

     文件      32256  2013-06-23 10:23  ColorStatistics\bin\Release\ColorStatistics.pdb

     文件      11600  2013-07-11 14:27  ColorStatistics\bin\Release\ColorStatistics.vshost.exe

     文件        490  2010-03-17 22:39  ColorStatistics\bin\Release\ColorStatistics.vshost.exe.manifest

     文件       5893  2013-06-23 10:22  ColorStatistics\ColorStatistics.csproj

     文件        478  2013-06-23 10:22  ColorStatistics\ColorStatistics.csproj.user

     文件       3547  2013-07-11 14:38  ColorStatistics\FrmTest.cs

     文件       9414  2013-06-23 10:23  ColorStatistics\FrmTest.Designer.cs

     文件     546895  2013-06-23 10:23  ColorStatistics\FrmTest.resx

     文件       6262  2013-06-20 21:11  ColorStatistics\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1067  2013-07-11 14:27  ColorStatistics\obj\x86\Release\ColorStatistics.csproj.FileListAbsolute.txt

     文件     773120  2013-06-23 10:23  ColorStatistics\obj\x86\Release\ColorStatistics.exe

     文件     361084  2013-06-23 10:23  ColorStatistics\obj\x86\Release\ColorStatistics.FrmTest.resources

     文件      32256  2013-06-23 10:23  ColorStatistics\obj\x86\Release\ColorStatistics.pdb

     文件      37013  2013-06-23 10:22  ColorStatistics\obj\x86\Release\ColorStatistics.Properties.Resources.resources

     文件       4440  2013-06-21 16:23  ColorStatistics\obj\x86\Release\DesignTimeResolveAssemblyReferences.cache

     文件       6646  2013-07-11 14:14  ColorStatistics\obj\x86\Release\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1092  2013-06-23 10:23  ColorStatistics\obj\x86\Release\GenerateResource.read.1.tlog

     文件       1498  2013-06-23 10:23  ColorStatistics\obj\x86\Release\GenerateResource.write.1.tlog

     文件       7897  2013-06-21 16:37  ColorStatistics\obj\x86\Release\ResolveAssemblyReference.cache

     文件       5120  2013-06-23 10:18  ColorStatistics\obj\x86\Release\TempPE\Properties.Resources.Designer.cs.dll

     文件       1406  2013-06-23 10:21  ColorStatistics\PanelTime.ico

     文件        498  2013-06-23 09:27  ColorStatistics\Program.cs

     文件       1362  2013-06-20 21:07  ColorStatistics\Properties\AssemblyInfo.cs

     文件       3212  2013-06-23 10:18  ColorStatistics\Properties\Resources.Designer.cs

     文件       6291  2013-06-23 10:18  ColorStatistics\Properties\Resources.resx

     文件       1100  2013-06-20 21:07  ColorStatistics\Properties\Settings.Designer.cs

     文件        249  2013-06-20 21:07  ColorStatistics\Properties\Settings.settings

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

评论

共有 条评论

相关资源