Get Sample String from Bitmap - CSharp System.Drawing

CSharp examples for System.Drawing:Bitmap

Description

Get Sample String from Bitmap

Demo Code


using System.Windows.Forms;
using System.Text;
using System.IO;//from  w w  w .  j  a v a 2 s  .  c o  m
using System.Drawing.Imaging;
using System.Drawing;
using System;

public class Main{
        public static string GetSampleString(Bitmap bmp, int accuracy)
        {
            StringBuilder builder = new StringBuilder();
            Bitmap thumb = (Bitmap)bmp.GetThumbnailImage(accuracy, accuracy, null, IntPtr.Zero);
            int thumbWidth = thumb.Width;
            int thumbHeight = thumb.Height;
            for (int x = 0; x < thumbWidth; x++)
            {
                for (int y = 0; y < thumbHeight; y++)
                {
                    Color oldColor = thumb.GetPixel(x, y);
                    int r = oldColor.R;
                    int g = oldColor.G;
                    int b = oldColor.B;
                    int c = (r * 76 + g * 151 + b * 28) >> 8;
                    builder.Append(c / 26);
                }
            }
            thumb.Dispose();
            return builder.ToString();
        }
}

Related Tutorials