惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
博客园 - 司徒正美
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog

博客园 - 浮云的等待

.net反混淆脱壳工具de4dot的使用 使用ILSpy软件反编译.Net应用程序的方法及注意事项 EmguCV使用Stitcher类来拼接图像 从睡姿就可以看出你的性格,据说非常准,快存! 分享几个.NET WinForm开源组件,纪念逐渐远去的WinForm。。。 【转载】关于.NET下开源及商业图像处理(PSD)组件 C#.NET开源项目、机器学习、Power BI C# 开源框架(整理) c#图像处理入门(-bitmap类和图像像素值获取方法) C#图片处理常见方法性能比较 js前段开发工具 医疗时鲜资讯:如何玩转医学影像中心? DICOM医学图像处理:WEB PACS初谈四,PHP DICOM Class 图像处理引擎 ThinkPHP函数详解:I方法 用cas来实现php的单点登陆 看CES 2017上有哪些好玩的物联网设备 MVC系列2-Model MVC系列1-MVC基础 (ASP.NET)
图片处理类 类库--C#
浮云的等待 · 2017-06-10 · via 博客园 - 浮云的等待

调用如下:

  1. Bitmap bitmap = new Bitmap("C:\\Users\\Thinkpad\\Desktop\\aa.jpg");  
  2.            Bitmap[] bit = new Bitmap[13];  
  3.            for (int i = 0; i < 13; i++) {  
  4.                bit[i] = new Bitmap("C:\\Users\\Thinkpad\\Desktop\\aa.jpg");  
  5.            }  
  6.            
  7.            pictureEdit1.Image = ImagePS.DeColor(bit[0]);  
  8.            
  9.            pictureEdit2.Image = ImagePS.DeColor(bit[1], Color.White);  
  10.            
  11.            pictureEdit3.Image = ImagePS.ReImg(bit[2]);  
  12.            
  13.            pictureEdit4.Image = ImagePS.Raised(bit[3]);             
  14.            
  15.            pictureEdit5.Image = ImagePS.Softness(bit[4]);  
  16.            
  17.            pictureEdit6.Image = ImagePS.Definition(bit[5]);  
  18.            
  19.            pictureEdit7.Image = ImagePS.SetColorFilter(bit[6], ImagePS.ColorFilterType.Red);  
  20.            
  21.            pictureEdit8.Image = ImagePS.Contrast(bit[7], 50);  
  22.            
  23.            pictureEdit9.Image = ImagePS.KiResizeImage(bit[8], 100, 100);  
  24.            
  25.            pictureEdit10.Image = ImagePS.LightImage(bit[9], -100);  
  26.            
  27.            pictureEdit11.Image = ImagePS.SetGamma(bit[10],250,100,250);  
  28.            
  29.            pictureEdit12.Image = ImagePS.GetColorImg(Color.Yellow,100,100);  
  1. <strong><span style="font-size:14px;">底层类:</span></strong>  
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Drawing;  
  5. using System.Drawing.Imaging;  
  6. using System.Drawing.Drawing2D;  
  7. using System.Windows.Forms;  
  8.   
  9. namespace Common  
  10. {  
  11.     
  12.     
  13.     
  14.     public class ImagePS  
  15.     {  
  16.         public static Bitmap GetControlBmp(Control ctrl, int offsetX, int offsetY)  
  17.         {  
  18.             Graphics myGraphics = ctrl.CreateGraphics();  
  19.             Rectangle r = ctrl.RectangleToScreen(ctrl.Bounds);  
  20.             Bitmap memoryImage = new Bitmap(r.Width, r.Height, myGraphics);  
  21.             Graphics memoryGraphics = Graphics.FromImage(memoryImage);  
  22.             memoryGraphics.CopyFromScreen(r.X - offsetX, r.Y - offsetY, 0, 0, new Size(r.Width, r.Height));  
  23.             return memoryImage;  
  24.         }  
  25.         
  26.         
  27.         
  28.         public enum ColorFilterType  
  29.         {  
  30.             Red, Green, Blue  
  31.         }  
  32.   
  33.         
  34.         
  35.         
  36.         
  37.         
  38.         public static Bitmap ReImg(Bitmap img)  
  39.         {  
  40.             byte r, g, b;  
  41.             for (int i = 0; i < img.Width; i++)  
  42.             {  
  43.                 for (int j = 0; j < img.Height; j++)  
  44.                 {  
  45.                     r = (byte)(255 - img.GetPixel(i, j).R);  
  46.                     g = (byte)(255 - img.GetPixel(i, j).G);  
  47.                     b = (byte)(255 - img.GetPixel(i, j).B);  
  48.   
  49.                     img.SetPixel(i, j, Color.FromArgb(r, g, b));  
  50.                 }  
  51.             }  
  52.   
  53.             return img;  
  54.         }  
  55.   
  56.         
  57.         
  58.         
  59.         
  60.         
  61.         
  62.         public static Bitmap LightImage(Bitmap bitmap, int light)  
  63.         {  
  64.             light = light > 255 ? 255 : light;  
  65.             light = light < -255 ? -255 : light;  
  66.   
  67.             int w = bitmap.Width;  
  68.             int h = bitmap.Height;  
  69.             int pix = 0;  
  70.             BitmapData data = bitmap.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);  
  71.   
  72.             unsafe  
  73.             {  
  74.                 byte* p = (byte*)data.Scan0;  
  75.                 int offset = data.Stride - w * 3;  
  76.                 for (int i = 0; i < w; i++)  
  77.                 {  
  78.                     for (int j = 0; j < h; j++)  
  79.                     {  
  80.                         for (int x = 0; x < 3; x++)  
  81.                         {  
  82.                             pix = p[x] + light;  
  83.                             if (light < 0)  
  84.                                 p[x] = (byte)Math.Max(0, pix);  
  85.                             if (light > 0)  
  86.                                 p[x] = (byte)Math.Min(255, pix);  
  87.                         }  
  88.                         p += 3;  
  89.                     }  
  90.                     p += offset;  
  91.                 }  
  92.             }  
  93.   
  94.             bitmap.UnlockBits(data);  
  95.             return bitmap;  
  96.         }  
  97.   
  98.         
  99.         
  100.         
  101.         
  102.         
  103.         public static Bitmap DeColor(Bitmap img)  
  104.         {  
  105.             if (img == null)  
  106.                 return img;  
  107.   
  108.             int w = img.Width, h = img.Height;  
  109.             Color oldColor, newColor;  
  110.             int y = 0;  
  111.   
  112.             for (int i = 0; i < w; i++)  
  113.             {  
  114.                 for (int j = 0; j < h; j++)  
  115.                 {  
  116.                     oldColor = img.GetPixel(i, j);  
  117.                     byte r = oldColor.R;  
  118.                     byte g = oldColor.G;  
  119.                     byte b = oldColor.B;  
  120.                     y = (r + g + b) / 3;  
  121.   
  122.                     newColor = Color.FromArgb(y, y, y);  
  123.                     img.SetPixel(i, j, newColor);  
  124.                 }  
  125.             }  
  126.             return img;  
  127.         }  
  128.         
  129.         
  130.         
  131.         
  132.         
  133.         
  134.         public static Bitmap DeColor(Bitmap img, Color c)  
  135.         {  
  136.             int w = img.Width, h = img.Height;  
  137.             Color oldColor;             
  138.             int cha1 = 60;  
  139.             int cha2 = 60;  
  140.   
  141.             for (int i = 0; i < w; i++)  
  142.             {  
  143.                 for (int j = 0; j < h; j++)  
  144.                 {  
  145.                     oldColor = img.GetPixel(i, j);  
  146.                     byte r = oldColor.R;  
  147.                     byte g = oldColor.G;  
  148.                     byte b = oldColor.B;  
  149.   
  150.                     bool bol1 = false, bol2 = false, bol3 = false;  
  151.                     if (r - c.R < cha1 && r - c.R > -cha2)  
  152.                         bol1 = true;  
  153.                     if (g - c.G < cha1 && g - c.G > -cha2)  
  154.                         bol2 = true;  
  155.   
  156.                     if (b - c.B < cha1 && b - c.B > -cha2)  
  157.                         bol3 = true;  
  158.   
  159.                     if (bol1 && bol2 && bol3)  
  160.                     {  
  161.                         
  162.                         
  163.                         img.SetPixel(i, j, Color.Black);  
  164.                     }  
  165.                 }  
  166.             }  
  167.   
  168.             return img;  
  169.         }  
  170.   
  171.         
  172.         
  173.         
  174.         
  175.         
  176.         public static Bitmap Raised(Bitmap img)  
  177.         {  
  178.             Color pix1, pix2;  
  179.   
  180.             for (int x = 0; x < img.Width - 1; x++)  
  181.             {  
  182.                 for (int y = 0; y < img.Height - 1; y++)  
  183.                 {  
  184.                     pix1 = img.GetPixel(x, y);  
  185.                     pix2 = img.GetPixel(x + 1, y + 1);  
  186.   
  187.                     int r = 0, g = 0, b = 0;
  188.                     r = Math.Abs(pix1.R - pix2.R + 100);  
  189.                     g = Math.Abs(pix1.G - pix2.G + 100);  
  190.                     b = Math.Abs(pix1.B - pix2.B + 100);  
  191.   
  192.                     
  193.                     r = Math.Min(255, r);  
  194.                     g = Math.Min(255, g);  
  195.                     b = Math.Min(255, b);  
  196.   
  197.                     r = Math.Max(0, r);  
  198.                     g = Math.Max(0, g);  
  199.                     b = Math.Max(0, b);  
  200.   
  201.                     img.SetPixel(x, y, Color.FromArgb(r, g, b));  
  202.                 }  
  203.             }  
  204.   
  205.             return img;  
  206.         }  
  207.   
  208.         
  209.         
  210.         
  211.         
  212.         
  213.         public static Bitmap Softness(Bitmap img)  
  214.         {  
  215.             Color pixel;  
  216.             int Width = img.Width;  
  217.             int Height = img.Height;  
  218.             int[] Gauss = { 1, 2, 1, 2, 4, 2, 1, 2, 1 };  
  219.   
  220.             for (int x = 1; x < Width - 1; x++)  
  221.             {  
  222.                 for (int y = 1; y < Height - 1; y++)  
  223.                 {  
  224.                     int r = 0, g = 0, b = 0;  
  225.                     int Index = 0;  
  226.                     for (int col = -1; col <= 1; col++)  
  227.                     {  
  228.                         for (int row = -1; row <= 1; row++)  
  229.                         {  
  230.                             pixel = img.GetPixel(x + row, y + col);  
  231.                             r += pixel.R * Gauss[Index];  
  232.                             g += pixel.G * Gauss[Index];  
  233.                             b += pixel.B * Gauss[Index];  
  234.                             Index++;  
  235.                         }  
  236.                     }  
  237.                     r /= 16;  
  238.                     g /= 16;  
  239.                     b /= 16;  
  240.                     
  241.                     r = r > 255 ? 255 : r;  
  242.                     r = r < 0 ? 0 : r;  
  243.                     g = g > 255 ? 255 : g;  
  244.                     g = g < 0 ? 0 : g;  
  245.                     b = b > 255 ? 255 : b;  
  246.                     b = b < 0 ? 0 : b;  
  247.                     img.SetPixel(x - 1, y - 1, Color.FromArgb(r, g, b));  
  248.                 }  
  249.             }  
  250.             return img;  
  251.         }  
  252.   
  253.         
  254.         
  255.         
  256.         
  257.         
  258.         
  259.         public static Bitmap Contrast(Bitmap img, int m)  
  260.         {  
  261.             if (m < -100) m = -100;  
  262.             if (m > 100) m = 100;  
  263.             
  264.             int w = img.Width;  
  265.             int h = img.Height;  
  266.             double pix = 0;  
  267.             BitmapData data = img.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);  
  268.             int offset = data.Stride - 3 * w;  
  269.             double contrast = (100.00 + m) / 100.00;  
  270.             contrast *= contrast;  
  271.   
  272.             unsafe  
  273.             {  
  274.                 byte* p = (byte*)data.Scan0;  
  275.                 for (int i = 0; i < w; i++)  
  276.                 {  
  277.                     for (int j = 0; j < h; j++)  
  278.                     {  
  279.                         for (int y = 0; y < 3; y++)  
  280.                         {  
  281.                             pix = ((p[y] / 255.00 - 0.5) * contrast + 0.5) * 255;  
  282.                             if (pix < 0) pix = 0;  
  283.                             if (pix > 255) pix = 255;  
  284.                             p[y] = (byte)pix;  
  285.                         }  
  286.                         p += 3;  
  287.                     }  
  288.                     p += offset;  
  289.                 }  
  290.             }  
  291.   
  292.             img.UnlockBits(data);  
  293.             return img;  
  294.         }  
  295.   
  296.         
  297.         
  298.         
  299.         
  300.         
  301.         public static Bitmap Definition(Bitmap img)  
  302.         {  
  303.             int w = img.Width;  
  304.             int h = img.Height;  
  305.             Color c;  
  306.             int[] laplacian = { -1, -1, -1, -1, 9, -1, -1, -1, -1 };  
  307.   
  308.             for (int i = 1; i < w - 1; i++)  
  309.             {  
  310.                 for (int j = 1; j < h - 1; j++)  
  311.                 {  
  312.                     int r = 0, g = 0, b = 0;  
  313.                     int index = 0;  
  314.   
  315.                     for (int col = -1; col <= 1; col++)  
  316.                     {  
  317.                         for (int row = -1; row <= 1; row++)  
  318.                         {  
  319.                             c = img.GetPixel(i + row, j + col);  
  320.                             r += c.R * laplacian[index];  
  321.                             g += c.G * laplacian[index];  
  322.                             b += c.B * laplacian[index];  
  323.   
  324.                             index += 1;  
  325.                         }  
  326.                     }  
  327.   
  328.                     r = Math.Max(0, r);  
  329.                     r = Math.Min(255, r);  
  330.                     g = Math.Max(0, g);  
  331.                     g = Math.Min(255, g);  
  332.                     b = Math.Max(0, b);  
  333.                     b = Math.Min(255, b);  
  334.   
  335.                     img.SetPixel(i - 1, j - 1, Color.FromArgb(r, g, b));  
  336.                 }
  337.             }
  338.   
  339.             return img;  
  340.         }  
  341.   
  342.         
  343.         
  344.         
  345.         
  346.         
  347.         public static Bitmap Atomization(Bitmap img)  
  348.         {  
  349.             int w = img.Width;  
  350.             int h = img.Height;  
  351.             Color pix;  
  352.             
  353.             Random ran = new Random();  
  354.   
  355.             for (int x = 0; x < w; x++)  
  356.             {  
  357.                 for (int y = 0; y < h; y++)  
  358.                 {  
  359.                     
  360.                     int dx = x + ran.Next(1234567) % 17;  
  361.                     int dy = y + ran.Next(1234567) % 17;  
  362.                     pix = img.GetPixel(Math.Min(dx, w - 1), Math.Min(dy, h - 1));  
  363.   
  364.                     img.SetPixel(x, y, pix);  
  365.                 }  
  366.             }  
  367.   
  368.             return img;  
  369.         }  
  370.   
  371.         
  372.         
  373.         
  374.         
  375.         
  376.         
  377.         public static Bitmap SetColorFilter(Bitmap img, ColorFilterType cType)  
  378.         {  
  379.             Color c;  
  380.             int r = 0, g = 0, b = 0;  
  381.   
  382.             for (int x = 0; x < img.Width; x++)  
  383.             {  
  384.                 for (int y = 0; y < img.Height; y++)  
  385.                 {  
  386.                     c = img.GetPixel(x, y);  
  387.                     r = c.R;  
  388.                     g = c.G;  
  389.                     b = c.B;  
  390.   
  391.                     if (cType == ColorFilterType.Red)  
  392.                     {  
  393.                         g -= 255;  
  394.                         b -= 255;  
  395.                     }  
  396.                     else if (cType == ColorFilterType.Green)  
  397.                     {  
  398.                         r -= 255;  
  399.                         b -= 255;  
  400.                     }  
  401.                     else  
  402.                     {  
  403.                         r -= 255;  
  404.                         g -= 255;  
  405.                     }  
  406.   
  407.                     
  408.                     r = Math.Max(0, r);  
  409.                     g = Math.Max(0, g);  
  410.                     b = Math.Max(0, b);  
  411.                     r = Math.Min(255, r);  
  412.                     g = Math.Min(255, g);  
  413.                     b = Math.Min(255, b);  
  414.   
  415.                     img.SetPixel(x, y, Color.FromArgb(r, g, b));  
  416.                 }  
  417.             }  
  418.   
  419.             return img;  
  420.         }  
  421.   
  422.         
  423.         
  424.         
  425.         
  426.         
  427.         
  428.         
  429.         
  430.         public static Bitmap SetGamma(Bitmap img, byte red, byte green, byte blue)  
  431.         {  
  432.             Color c;  
  433.             byte[] reds = CreateGamma(red);  
  434.             byte[] greens = CreateGamma(green);  
  435.             byte[] blues = CreateGamma(blue);  
  436.             for (int x = 0; x < img.Width; x++)  
  437.             {  
  438.                 for (int y = 0; y < img.Height; y++)  
  439.                 {  
  440.                     c = img.GetPixel(x, y);  
  441.                     img.SetPixel(x, y, Color.FromArgb(reds[c.R], greens[c.G], blues[c.B]));  
  442.                 }  
  443.             }  
  444.   
  445.             return img;  
  446.         }  
  447.   
  448.         
  449.         private static byte[] CreateGamma(byte color)  
  450.         {  
  451.             byte[] gammas = new byte[256];  
  452.             for (int i = 0; i < 256; i++)  
  453.             {  
  454.                 gammas[i] = Math.Min((byte)255, (byte)(255.0F * Math.Pow(i / 255, 1.0F / color) + 0.5F));  
  455.             }  
  456.   
  457.             return gammas;  
  458.         }  
  459.   
  460.   
  461.         
  462.         
  463.         
  464.         
  465.         
  466.         
  467.         public static Bitmap MergerImg(List<Bitmap> imgs, int z)  
  468.         {  
  469.             if (imgs.Count <= 0)  
  470.                 return null;  
  471.   
  472.             int w = 0;  
  473.             foreach (Bitmap bmp in imgs)  
  474.                 if (bmp != null)  
  475.                     w = w + bmp.Width;  
  476.   
  477.             w += z * (imgs.Count - 1);  
  478.   
  479.             int h = GetMaxHeight(imgs);  
  480.   
  481.             return MergerImg(imgs, z, w, h);  
  482.         }  
  483.   
  484.   
  485.         private static int GetMaxHeight(List<Bitmap> imgs)  
  486.         {  
  487.             if (imgs == null || imgs.Count == 0)  
  488.                 return 0;  
  489.   
  490.             int maxHeight = 0;  
  491.             foreach (Bitmap bmp in imgs)  
  492.             {  
  493.                 if (bmp == null)  
  494.                     continue;  
  495.   
  496.                 if (maxHeight == -1)  
  497.                 {  
  498.                     maxHeight = bmp.Height;  
  499.                 }  
  500.                 else  
  501.                     maxHeight = bmp.Height > maxHeight ? bmp.Height : maxHeight;  
  502.             }  
  503.   
  504.             return maxHeight;  
  505.         }  
  506.   
  507.         private static int GetMinHeight(List<Bitmap> imgs)  
  508.         {  
  509.             if (imgs == null || imgs.Count == 0)  
  510.                 return 0;  
  511.   
  512.             int mixHeight = 0;  
  513.             foreach (Bitmap bmp in imgs)  
  514.             {  
  515.                 if (mixHeight == 0)  
  516.                 {  
  517.                     mixHeight = bmp.Height;  
  518.                 }  
  519.                 else  
  520.                     mixHeight = bmp.Height < mixHeight ? bmp.Height : mixHeight;  
  521.             }  
  522.             return mixHeight;  
  523.         }  
  524.   
  525.         private static Bitmap MergerImg(List<Bitmap> imgs, int z, int w, int h)  
  526.         {  
  527.             
  528.             Bitmap backgroudImg = new Bitmap(w, h);  
  529.             Graphics g = Graphics.FromImage(backgroudImg);  
  530.   
  531.             
  532.             g.Clear(System.Drawing.Color.White);  
  533.   
  534.             int x = 0;  
  535.             for (int i = 0; i < imgs.Count; i++)  
  536.             {  
  537.                 Bitmap bmp = imgs[i];
  538.                 if (bmp == null)  
  539.                     continue;  
  540.                 g.DrawImage(bmp, x, 0, bmp.Width, h);  
  541.                 x = x + bmp.Width + z;  
  542.                 g.Flush();  
  543.             }  
  544.             g.Dispose();  
  545.             return backgroudImg;  
  546.         }  
  547.   
  548.         
  549.         
  550.         
  551.         
  552.         
  553.         
  554.         
  555.         public static Bitmap MergerImg(List<Bitmap> imgs, int z, int mType)  
  556.         {  
  557.             if (imgs.Count <= 0)  
  558.                 return null;  
  559.   
  560.             int w = 0;  
  561.             foreach (Bitmap bmp in imgs)  
  562.                 w += bmp.Width;  
  563.             w += z * (imgs.Count - 1);  
  564.             int h = mType == 0 ? GetMaxHeight(imgs) : GetMinHeight(imgs);  
  565.   
  566.             return MergerImg(imgs, z, w, h);  
  567.         }  
  568.   
  569.         
  570.         
  571.         
  572.         
  573.         
  574.         
  575.         
  576.         public static Bitmap KiResizeImage(Bitmap bmp, int newW, int newH)  
  577.         {  
  578.             if (bmp == null)  
  579.                 return null;  
  580.   
  581.             int max = bmp.Width > bmp.Height ? bmp.Width : bmp.Height;  
  582.             float l = max == bmp.Width ? (float)newW / (float)bmp.Width : (float)newH / (float)bmp.Height;  
  583.             float ww = bmp.Width * l;  
  584.             float hh = bmp.Height * l;  
  585.             ww = ww > 1 ? ww : newW;  
  586.             hh = hh > 1 ? hh : newH;  
  587.             Bitmap b = new Bitmap((int)ww, (int)hh);  
  588.             try  
  589.             {  
  590.                 Graphics g = Graphics.FromImage(b);  
  591.   
  592.                 g.PixelOffsetMode = PixelOffsetMode.Half;  
  593.                 
  594.                 g.InterpolationMode = InterpolationMode.High;  
  595.                 g.DrawImage(bmp, new Rectangle(0, 0, (int)ww, (int)hh),  
  596.                     new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);  
  597.                 g.Dispose();  
  598.             }  
  599.             catch (Exception ex)  
  600.             {  
  601.                 throw ex;  
  602.             }  
  603.             return b;  
  604.         }  
  605.   
  606.         
  607.         
  608.         
  609.         
  610.         
  611.         public static List<Color> ColorNumber(Bitmap img)  
  612.         {  
  613.             int w = img.Width, h = img.Height;  
  614.             Color nowColor;  
  615.             
  616.             int distance = 90;  
  617.             List<Color> colors = new List<Color>();  
  618.             for (int i = 0; i < w; i++)  
  619.             {  
  620.                 for (int j = 0; j < h; j++)  
  621.                 {  
  622.                     nowColor = img.GetPixel(i, j);  
  623.                     byte r = nowColor.R;  
  624.                     byte g = nowColor.G;  
  625.                     byte b = nowColor.B;  
  626.   
  627.                     if (colors.Count == 0)  
  628.                         colors.Add(nowColor);  
  629.                     else  
  630.                     {  
  631.                         int count = 0;  
  632.                         foreach (Color c in colors)  
  633.                         {  
  634.                             byte or = c.R;  
  635.                             byte og = c.G;  
  636.                             byte ob = c.B;  
  637.                             int R = System.Math.Abs(r - or);  
  638.                             int G = System.Math.Abs(g - og);  
  639.                             int B = System.Math.Abs(b - ob);  
  640.                             double sqr = System.Math.Sqrt(R * R + G * G + B * B);  
  641.                             if (sqr > distance)  
  642.                                 count += 1;  
  643.                         }  
  644.                         if (count >= colors.Count)  
  645.                             colors.Add(nowColor);  
  646.                     }  
  647.                 }  
  648.             }  
  649.             return colors;  
  650.         }  
  651.   
  652.         
  653.         
  654.         
  655.         
  656.         
  657.         
  658.         
  659.         public static Bitmap GetColorImg(Color c,int width,int height)  
  660.         {  
  661.             Bitmap bmp;  
  662.             if (width > 0 && height > 0)  
  663.             {  
  664.                 bmp = new Bitmap(width, height);  
  665.             }  
  666.             else  
  667.             {  
  668.                 bmp = new Bitmap(10, 10);  
  669.             }  
  670.             for (int i = 0; i < bmp.Width; i++)  
  671.             {  
  672.                 for (int j = 0; j < bmp.Height; j++)  
  673.                 {  
  674.                     bmp.SetPixel(i, j, c);  
  675.                 }  
  676.             }  
  677.             return bmp;  
  678.         }  
  679.   
  680.     }  
  681.   
  682. }  

posted @ 2017-06-10 23:28  浮云的等待  阅读(2179)  评论()    收藏  举报