• 08-04-2020, 14:10:19
    #1
    Bunun için bir kod varsa yarım ederseniz çok sevinirim.
  • 08-04-2020, 18:02:57
    #2
    Bitmap için:
    using System.Drawing;
    
    Bitmap img = new Bitmap("*imagePath*");
    for (int i = 0; i < img.Width; i++)
    {
    for (int j = 0; j < img.Height; j++)
    {
    Color pixel = img.GetPixel(i,j);
    
    if (pixel == *somecondition*)
    {
    **Store pixel here in a array or list or whatever**
    }
    }
    }
    Alıntı : https://stackoverflow.com/a/10128284
  • 09-04-2020, 03:26:25
    #3
    https://github.com/bahax41/C-Sharp/b...dunu-bulma.txt diye paylaşmıştık belki işine yarar
  • 23-04-2020, 01:13:19
    #4
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Bende bir zamanlar bunu kullanmıştım, ama ağırlık olan rengi almıştım sanırım. Eski bir kod açıkcası.
    public static class PictureAnalysis
            {
                public static List<Color> TenMostUsedColors { get; private set; }
                public static List<int> TenMostUsedColorIncidences { get; private set; }
    
                public static Color MostUsedColor { get; private set; }
                public static int MostUsedColorIncidence { get; private set; }
    
                private static int pixelColor;
    
                private static Dictionary<int, int> dctColorIncidence;
    
                public static void GetMostUsedColor(Bitmap theBitMap)
                {
                    TenMostUsedColors = new List<Color>();
                    TenMostUsedColorIncidences = new List<int>();
    
                    MostUsedColor = Color.Empty;
                    MostUsedColorIncidence = 0;
    
                    // does using Dictionary<int,int> here
                    // really pay-off compared to using
                    // Dictionary<Color, int> ?
    
                    // would using a SortedDictionary be much slower, or ?
    
                    dctColorIncidence = new Dictionary<int, int>();
    
                    // this is what you want to speed up with unmanaged code
                    for (int row = 0; row < theBitMap.Size.Width; row++)
                    {
                        for (int col = 0; col < theBitMap.Size.Height; col++)
                        {
                            pixelColor = theBitMap.GetPixel(row, col).ToArgb();
    
                            if (dctColorIncidence.Keys.Contains(pixelColor))
                            {
                                dctColorIncidence[pixelColor]++;
                            }
                            else
                            {
                                dctColorIncidence.Add(pixelColor, 1);
                            }
                        }
                    }
    
                    // note that there are those who argue that a
                    // .NET Generic Dictionary is never guaranteed
                    // to be sorted by methods like this
                    var dctSortedByValueHighToLow = dctColorIncidence.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
    
                    // this should be replaced with some elegant Linq ?
                    foreach (KeyValuePair<int, int> kvp in dctSortedByValueHighToLow.Take(10))
                    {
                        TenMostUsedColors.Add(Color.FromArgb(kvp.Key));
                        TenMostUsedColorIncidences.Add(kvp.Value);
                    }
    
                    MostUsedColor = Color.FromArgb(dctSortedByValueHighToLow.First().Key);
                    MostUsedColorIncidence = dctSortedByValueHighToLow.First().Value;
                }
    
            }
            public static System.Drawing.Color GetDominantColor(Bitmap bmp)
            {
                if (bmp == null)
                {
                    throw new ArgumentNullException("bmp");
                }
    
                BitmapData srcData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);
    
                int bytesPerPixel = Image.GetPixelFormatSize(srcData.PixelFormat) / 8;
    
                int stride = srcData.Stride;
    
                IntPtr scan0 = srcData.Scan0;
    
                long[] totals = new long[] { 0, 0, 0 };
    
                int width = bmp.Width * bytesPerPixel;
                int height = bmp.Height;
    
                unsafe
                {
                    byte* p = (byte*)(void*)scan0;
    
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x += bytesPerPixel)
                        {
                            totals[0] += p[x + 0];
                            totals[1] += p[x + 1];
                            totals[2] += p[x + 2];
                        }
    
                        p += stride;
                    }
                }
    
                long pixelCount = bmp.Width * height;
    
                int avgB = Convert.ToInt32(totals[0] / pixelCount);
                int avgG = Convert.ToInt32(totals[1] / pixelCount);
                int avgR = Convert.ToInt32(totals[2] / pixelCount);
    
                bmp.UnlockBits(srcData);
    
                return Color.FromArgb(avgR, avgG, avgB);
    
            }