模拟Photo的直方图,不过只是显示;
有对图像四角的密度和反差进行补偿,这是现在LDD(LCD+LED)数码裁放机上常用的补偿方法!
主要还是对GDI+的应用,大家不妨看看原码!
http://www.nxxn.net/soft/dreign.rar
//图像处理--------------------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace zft
{
public class BitmapFilter
{
public static bool modu1(Bitmap image,int r,int g,int b)
{
if(r==0) r=1;
if(g==0) g=1;
if(b==0) b=1;
BitmapData bmData = image.LockBits(new Rectangle(0, 0,image.Width , image.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
{
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - image.Width*3;
int nWidth=image.Width;
int nHeight=image.Height;
int red,green,blue;
int w0=(int)(nWidth/2);
int h0=(int)(nHeight/2);
int r0,t1,t2,kr=r,kg=g,kb=b;
double z,z0;
int k1r=r,k1g=g,k1b=b,
k2r=r,k2g=g,k2b=b,
k3r=r,k3g=g,k3b=b,
k4r=r,k4g=g,k4b=b;
if(w0>h0)
r0=w0;
else
r0=h0;
z0=Math.Sqrt(w0*w0+h0*h0);
z0=z0/1.5;
for(int y=0;y<nHeight;++y)
{
for(int x=0; x < nWidth; ++x )
{
red=p[2];
green=p[1];
blue=p[0];
t1=x-w0;
t2=y-h0;
if(t1<0) t1=0-t1;
if(t2<0) t2=0-t2;
z=Math.Sqrt(t1*t1+t2*t2);
if(z<z0)
{
z=z0;
kr=0;
kg=0;
kb=0;
}
else
{
double xx=(z-z0)/z;
kr=(int)(15*r*xx*xx);
kg=(int)(15*g*xx*xx);
kb=(int)(15*b*xx*xx);
}
red+=kr;
green+=kg;
blue+=kb;
if(red>255) red=255;
if(red<0) red=0;
if(green>255) green=255;
if(green<0) green=0;
if(blue>255) blue=255;
if(blue<0) blue=0;
p[2]=(byte)red;
p[1]=(byte)green;
p[0]=(byte)blue;
p+=3;
}
p += nOffset;
}
}
image.UnlockBits(bmData);
return true;
}
/// <summary>
/// 反差圆补偿
/// </summary>
/// <param name="image">图像</param>
/// <param name="con">反差系数</param>
/// <param name="k">圆半径系数</param>
/// <returns></returns>
public static bool ccon(Bitmap image,float con,float k)
{
BitmapData bmData = image.LockBits(new Rectangle(0, 0,image.Width , image.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
{
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - image.Width*3;
int nWidth=image.Width;
int nHeight=image.Height;
int red,green,blue;
int w0=(int)(nWidth/2);
int h0=(int)(nHeight/2);
int r0,t1,t2;
double z,z0,pixel,contrast;
if(w0>h0)
r0=w0;
else
r0=h0;
z0=Math.Sqrt(w0*w0+h0*h0);
z0=z0/k;
for(int y=0;y<nHeight;++y)
{
for(int x=0; x < nWidth; ++x )
{
red=p[2];
green=p[1];
blue=p[0];
t1=x-w0;
t2=y-h0;
if(t1<0) t1=0-t1;
if(t2<0) t2=0-t2;
z=Math.Sqrt(t1*t1+t2*t2);
if(z>z0)
{
contrast = (z-z0)/z * con ;
pixel = red-(127-red) * contrast;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
p[2] = (byte) pixel;
pixel = green-(127-green) * contrast;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
p[1] = (byte) pixel;
pixel = blue-(127-blue) * contrast;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
p[0] = (byte) pixel;
}
p+=3;
}
p += nOffset;
}
}
image.UnlockBits(bmData);
return true;
}
/// <summary>
/// 基本反差调整
/// </summary>
/// <param name="b"></param>
/// <param name="nContrast"></param>
/// <returns></returns>
public static bool Contrast(Bitmap b, int nContrast)
{
if (nContrast < -100) return false;
if (nContrast > 100) return false;
double pixel = 0, contrast = (100.0+nContrast)/100.0;
contrast *= contrast;
int red, green, blue;
// GDI+ still lies to us - the return format is BGR, NOT RGB.
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
int h=b.Height,w=b.Width;
unsafe
{
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - b.Width*3;
for(int y=0;y<h;++y)
{
for(int x=0; x < w; ++x )
{
blue = p[0];
green = p[1];
red = p[2];
pixel = red/255.0;
pixel -= 0.5;
pixel *= contrast;
pixel += 0.5;
pixel *= 255;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
p[2] = (byte) pixel;
pixel = green/255.0;
pixel -= 0.5;
pixel *= contrast;
pixel += 0.5;
pixel *= 255;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
p[1] = (byte) pixel;
pixel = blue/255.0;
pixel -= 0.5;
pixel *= contrast;
pixel += 0.5;
pixel *= 255;
if (pixel < 0) pixel = 0;
if (pixel > 255) pixel = 255;
p[0] = (byte) pixel;
p += 3;
}
p += nOffset;
}
}
b.UnlockBits(bmData);
return true;
}
public static bool zft(Bitmap b,out int[] all,out int[] rhow, out int[] ghow,out int[] bhow)
{
int [] gray=new int[256];
int [] rr = new int[256];
int [] gg = new int[256];
int [] bb = new int[256];
int tt=0;
foreach(int i in gray)
{
gray[i]=0;
}
foreach(int i in rr)
{
rr[i]=0;
}
foreach(int i in gg)
{
gg[i]=0;
}
foreach(int i in bb)
{
bb[i]=0;
}
// GDI+ still lies to us - the return format is BGR, NOT RGB.
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - b.Width*3;
byte red, green, blue;
int nWidth = b.Width;
int nHeight= b.Height;
for(int y=0;y<nHeight;++y)
{
for(int x=0; x < nWidth; ++x )
{
blue = p[0];
green = p[1];
red = p[2];
tt = (byte)(.299 * red + .587 * green + .114 * blue);
#region rr
switch(red)
{
case 0:
rr[0]++;
break;
case 1:
rr[1]++;
break;
case 2:
rr[2]++;
break;
case 3:
rr[3]++;
break;
case 4:
rr[4]++;
break;
case 5:
rr[5]++;
break;
case 6:
rr[6]++;
break;
case 7:
rr[7]++;
break;
case 8:
rr[8]++;
break;
case 9:
rr[9]++;
break;
case 10:
rr[10]++;
break;
case 11:
rr[11]++;
break;
case 12:
rr[12]++;
break;
case 13:
rr[13]++;
break;
case 14:
rr[14]++;
break;
case 15:
rr[15]++;
break;
case 16:
rr[16]++;
break;
case 17:
rr[17]++;
break;
case 18:
rr[18]++;
break;
case 19:
rr[19]++;
break;
case 20:
rr[20]++;
break;
case 21:
rr[21]++;
break;
case 22:
rr[22]++;
break;
case 23:
rr[23]++;
break;
case 24:
rr[24]++;
break;
case 25:
rr[25]++;
break;
case 26:
rr[26]++;
break;
case 27:
rr[27]++;
break;
case 28:
rr[28]++;
break;
case 29:
rr[29]++;
break;
case 30:
rr[30]++;
break;
case 31:
rr[31]++;
break;
case 32:
rr[32]++;
break;
case 33:
rr[33]++;
break;
case 34:
rr[34]++;
break;
case 35:
rr[35]++;
break;
case 36:
rr[36]++;
break;
case 37:
rr[37]++;
break;
case 38:
rr[38]++;
break;
case 39:
rr[39]++;
break;
case 40:
rr[40]++;
break;
case 41:
rr[41]++;
break;
case 42:
rr[42]++;
break;
case 43:
rr[43]++;
break;
case 44:
rr[44]++;
break;
case 45:
rr[45]++;
break;
case 46:
rr[46]++;
break;
case 47:
rr[47]++;
break;
case 48:
rr[48]++;
break;
case 49:
rr[49]++;
break;
case 50:
rr[50]++;
break;
case 51:
rr[51]++;
break;
case 52:
rr[52]++;
break;
case 53:
rr[53]++;
break;
case 54:
rr[54]++;
break;
case 55:
rr[55]++;
break;
case 56:
rr[56]++;
break;
case 57:
rr[57]++;
break;
case 58:
rr[58]++;
break;
case 59:
rr[59]++;
break;
case 60:
rr[60]++;
break;
case 61:
rr[61]++;
break;
case 62:
rr[62]++;
break;
case 63:
rr[63]++;
break;
case 64:
rr[64]++;
break;
case 65:
rr[65]++;
break;
case 66:
rr[66]++;
break;
case 67:
rr[67]++;
break;
case 68:
rr[68]++;
break;
case 69:
rr[69]++;
break;
case 70:
rr[70]++;
break;
case 71:
rr[71]++;
break;
case 72:
rr[72]++;
break;
case 73:
rr[73]++;
break;
case 74:
rr[74]++;
break;
case 75:
rr[75]++;
break;
case 76:
rr[76]++;
break;
case 77:
rr[77]++;
break;
case 78:
rr[78]++;
break;
case 79:
rr[79]++;
break;
case 80:
rr[80]++;
break;
case 81:
rr[81]++;
break;
case 82:
rr[82]++;
break;
case 83:
rr[83]++;
break;
case 84:
rr[84]++;
break;
case 85:
rr[85]++;
break;
case 86:
rr[86]++;
break;
case 87:
rr[87]++;
break;
case 88:
rr[88]++;
break;
case 89:
rr[89]++;
break;
case 90:
rr[90]++;
break;
case 91:
rr[91]++;
break;
case 92:
rr[92]++;
break;
case 93:
rr[93]++;
break;
case 94:
rr[94]++;
break;
case 95:
rr[95]++;
break;
case 96:
rr[96]++;
break;
case 97:
rr[97]++;
break;
case 98:
rr[98]++;
break;
case 99:
rr[99]++;
break;
case 100:
rr[100]++;
break;
//=-----------------------------------------------------------------------------
case 101:
rr[101]++;
break;
case 102:
rr[102]++;
break;
case 103:
rr[103]++;
break;
case 104:
rr[104]++;
break;
case 105:
rr[105]++;
break;
case 106:
rr[106]++;
break;
case 107:
rr[107]++;
break;
case 108:
rr[108]++;
break;
case 109:
rr[109]++;
break;
case 110:
rr[110]++;
break;
case 111:
rr[111]++;
break;
case 112:
rr[112]++;
break;
case 113:
rr[113]++;
break;
case 114:
rr[114]++;
break;
case 115:
rr[115]++;
break;
case 116:
rr[116]++;
break;
case 117:
rr[117]++;
break;
case 118:
rr[118]++;
break;
case 119:
rr[119]++;
break;
case 120:
rr[120]++;
break;
case 121:
rr[121]++;
break;
case 122:
rr[122]++;
break;
case 123:
rr[123]++;
break;
case 124:
rr[124]++;
break;
case 125:
rr[125]++;
break;
case 126:
rr[126]++;
break;
case 127:
rr[127]++;
break;
case 128:
rr[128]++;
break;
case 129:
rr[129]++;
break;
case 130:
rr[130]++;
break;
case 131:
rr[131]++;
break;
case 132:
rr[132]++;
break;
case 133:
rr[133]++;
break;
case 134:
rr[134]++;
break;
case 135:
rr[135]++;
break;
case 136:
rr[136]++;
break;
case 137:
rr[137]++;
break;
case 138:
rr[138]++;
break;
case 139:
rr[139]++;
break;
case 140:
rr[140]++;
break;
case 141:
rr[141]++;
break;
case 142:
rr[142]++;
break;
case 143:
rr[143]++;
break;
case 144:
rr[144]++;
break;
case 145:
rr[145]++;
break;
case 146:
rr[146]++;
break;
case 147:
rr[147]++;
break;
case 148:
rr[148]++;
break;
case 149:
rr[149]++;
break;
case 150:
rr[150]++;
break;
case 151:
rr[151]++;
break;
case 152:
rr[152]++;
break;
case 153:
rr[153]++;
break;
case 154:
rr[154]++;
break;
case 155:
rr[155]++;
break;
case 156:
rr[156]++;
break;
case 157:
rr[157]++;
break;
case 158:
rr[158]++;
break;
case 159:
rr[159]++;
break;
case 160:
rr[160]++;
break;
case 161:
rr[161]++;
break;
case 162:
rr[162]++;
break;
case 163:
rr[163]++;
break;
case 164:
rr[164]++;
break;
case 165:
rr[165]++;
break;
case 166:
rr[166]++;
break;
case 167:
rr[167]++;
break;
case 168:
rr[168]++;
break;
case 169:
rr[169]++;
break;
case 170:
rr[170]++;
break;
case 171:
rr[171]++;
break;
case 172:
rr[172]++;
break;
case 173:
rr[173]++;
break;
case 174:
rr[174]++;
break;
case 175:
rr[175]++;
break;
case 176:
rr[176]++;
break;
case 177:
rr[177]++;
break;
case 178:
rr[178]++;
break;
case 179:
rr[179]++;
break;
case 180:
rr[180]++;
break;
case 181:
rr[181]++;
break;
case 182:
rr[182]++;
break;
case 183:
rr[183]++;
break;
case 184:
rr[184]++;
break;
case 185:
rr[185]++;
break;
case 186:
rr[186]++;
break;
case 187:
rr[187]++;
break;
case 188:
rr[188]++;
break;
case 189:
rr[189]++;
break;
case 190:
rr[190]++;
break;
case 191:
rr[191]++;
break;
case 192:
rr[192]++;
break;
case 193:
rr[193]++;
break;
case 194:
rr[194]++;
break;
case 195:
rr[195]++;
break;
case 196:
rr[196]++;
break;
case 197:
rr[197]++;
break;
case 198:
rr[198]++;
break;
case 199:
rr[199]++;
break;
case 200:
rr[200]++;
break;
//-----------------------------------------------------------------
case 201:
rr[201]++;
break;
case 202:
rr[202]++;
break;
case 203:
rr[203]++;
break;
case 204:
rr[204]++;
break;
case 205:
rr[205]++;
break;
case 206:
rr[206]++;
break;
case 207:
rr[207]++;
break;
case 208:
rr[208]++;
break;
case 209:
rr[209]++;
break;
case 210:
rr[210]++;
break;
case 211:
rr[211]++;
break;
case 212:
rr[212]++;
break;
case 213:
rr[213]++;
break;
case 214:
rr[214]++;
break;
case 215:
rr[215]++;
break;
case 216:
rr[216]++;
break;
case 217:
rr[217]++;
break;
case 218:
rr[218]++;
break;
case 219:
rr[219]++;
break;
case 220:
rr[220]++;
break;
case 221:
rr[221]++;
break;
case 222:
rr[222]++;
break;
case 223:
rr[223]++;
break;
case 224:
rr[224]++;
break;
case 225:
rr[225]++;
break;
case 226:
rr[226]++;
break;
case 227:
rr[227]++;
break;
case 228:
rr[228]++;
break;
case 229:
rr[229]++;
break;
case 230:
rr[230]++;
break;
case 231:
rr[231]++;
break;
case 232:
rr[232]++;
break;
case 233:
rr[233]++;
break;
case 234:
rr[234]++;
break;
case 235:
rr[235]++;
break;
case 236:
rr[236]++;
break;
case 237:
rr[237]++;
break;
case 238:
rr[238]++;
break;
case 239:
rr[239]++;
break;
case 240:
rr[240]++;
break;
case 241:
rr[241]++;
break;
case 242:
rr[242]++;
break;
case 243:
rr[243]++;
break;
case 244:
rr[244]++;
break;
case 245:
rr[245]++;
break;
case 246:
rr[246]++;
break;
case 247:
rr[247]++;
break;
case 248:
rr[248]++;
break;
case 249:
rr[249]++;
break;
case 250:
rr[250]++;
break;
case 251:
rr[251]++;
break;
case 252:
rr[252]++;
break;
case 253:
rr[253]++;
break;
case 254:
rr[254]++;
break;
case 255:
rr[255]++;
break;
}
#endregion
#region gg
switch(green)
{
case 0:
gg[0]++;
break;
case 1:
gg[1]++;
break;
case 2:
gg[2]++;
break;
case 3:
gg[3]++;
break;
case 4:
gg[4]++;
break;
case 5:
gg[5]++;
break;
case 6:
gg[6]++;
break;
case 7:
gg[7]++;
break;
case 8:
gg[8]++;
break;
case 9:
gg[9]++;
break;
case 10:
gg[10]++;
break;
case 11:
gg[11]++;
break;
case 12:
gg[12]++;
break;
case 13:
gg[13]++;
break;
case 14:
gg[14]++;
break;
case 15:
gg[15]++;
break;
case 16:
gg[16]++;
break;
case 17:
gg[17]++;
break;
case 18:
gg[18]++;
break;
case 19:
gg[19]++;
break;
case 20:
gg[20]++;
break;
case 21:
gg[21]++;
break;
case 22:
gg[22]++;
break;
case 23:
gg[23]++;
break;
case 24:
gg[24]++;
break;
case 25:
gg[25]++;
break;
case 26:
gg[26]++;
break;
case 27:
gg[27]++;
break;
case 28:
gg[28]++;
break;
case 29:
gg[29]++;
break;
case 30:
gg[30]++;
break;
case 31:
gg[31]++;
break;
case 32:
gg[32]++;
break;
case 33:
gg[33]++;
break;
case 34:
gg[34]++;
break;
case 35:
gg[35]++;
break;
case 36:
gg[36]++;
break;
case 37:
gg[37]++;
break;
case 38:
gg[38]++;
break;
case 39:
gg[39]++;
break;
case 40:
gg[40]++;
break;
case 41:
gg[41]++;
break;
case 42:
gg[42]++;
break;
case 43:
gg[43]++;
break;
case 44:
gg[44]++;
break;
case 45:
gg[45]++;
break;
case 46:
gg[46]++;
break;
case 47:
gg[47]++;
break;
case 48:
gg[48]++;
break;
case 49:
gg[49]++;
break;
case 50:
gg[50]++;
break;
case 51:
gg[51]++;
break;
case 52:
gg[52]++;
break;
case 53:
gg[53]++;
break;
case 54:
gg[54]++;
break;
case 55:
gg[55]++;
break;
case 56:
gg[56]++;
break;
case 57:
gg[57]++;
break;
case 58:
gg[58]++;
break;
case 59:
gg[59]++;
break;
case 60:
gg[60]++;
break;
case 61:
gg[61]++;
break;
case 62:
gg[62]++;
break;
case 63:
gg[63]++;
break;
case 64:
gg[64]++;
break;
case 65:
gg[65]++;
break;
case 66:
gg[66]++;
break;
case 67:
gg[67]++;
break;
case 68:
gg[68]++;
break;
case 69:
gg[69]++;
break;
case 70:
gg[70]++;
break;
case 71:
gg[71]++;
break;
case 72:
gg[72]++;
break;
case 73:
gg[73]++;
break;
case 74:
gg[74]++;
break;
case 75:
gg[75]++;
break;
case 76:
gg[76]++;
break;
case 77:
gg[77]++;
break;
case 78:
gg[78]++;
break;
case 79:
gg[79]++;
break;
case 80:
gg[80]++;
break;
case 81:
gg[81]++;
break;
case 82:
gg[82]++;
break;
case 83:
gg[83]++;
break;
case 84:
gg[84]++;
break;
case 85:
gg[85]++;
break;
case 86:
gg[86]++;
break;
case 87:
gg[87]++;
break;
case 88:
gg[88]++;
break;
case 89:
gg[89]++;
break;
case 90:
gg[90]++;
break;
case 91:
gg[91]++;
break;
case 92:
gg[92]++;
break;
case 93:
gg[93]++;
break;
case 94:
gg[94]++;
break;
case 95:
gg[95]++;
break;
case 96:
gg[96]++;
break;
case 97:
gg[97]++;
break;
case 98:
gg[98]++;
break;
case 99:
gg[99]++;
break;
case 100:
gg[100]++;
break;
//=-----------------------------------------------------------------------------
case 101:
gg[101]++;
break;
case 102:
gg[102]++;
break;
case 103:
gg[103]++;
break;
case 104:
gg[104]++;
break;
case 105:
gg[105]++;
break;
case 106:
gg[106]++;
break;
case 107:
gg[107]++;
break;
case 108:
gg[108]++;
break;
case 109:
gg[109]++;
break;
case 110:
gg[110]++;
break;
case 111:
gg[111]++;
break;
case 112:
gg[112]++;
break;
case 113:
gg[113]++;
break;
case 114:
gg[114]++;
break;
case 115:
gg[115]++;
break;
case 116:
gg[116]++;
break;
case 117:
gg[117]++;
break;
case 118:
gg[118]++;
break;
case 119:
gg[119]++;
break;
case 120:
gg[120]++;
break;
case 121:
gg[121]++;
break;
case 122:
gg[122]++;
break;
case 123:
gg[123]++;
break;
case 124:
gg[124]++;
break;
case 125:
gg[125]++;
break;
case 126:
gg[126]++;
break;
case 127:
gg[127]++;
break;
case 128:
gg[128]++;
break;
case 129:
gg[129]++;
break;
case 130:
gg[130]++;
break;
case 131:
gg[131]++;
break;
case 132:
gg[132]++;
break;
case 133:
gg[133]++;
break;
case 134:
gg[134]++;
break;
case 135:
gg[135]++;
break;
case 136:
gg[136]++;
break;
case 137:
gg[137]++;
break;
case 138:
gg[138]++;
break;
case 139:
gg[139]++;
break;
case 140:
gg[140]++;
break;
case 141:
gg[141]++;
break;
case 142:
gg[142]++;
break;
case 143:
gg[143]++;
break;
case 144:
gg[144]++;
break;
case 145:
gg[145]++;
break;
case 146:
gg[146]++;
break;
case 147:
gg[147]++;
break;
case 148:
gg[148]++;
break;
case 149:
gg[149]++;
break;
case 150:
gg[150]++;
break;
case 151:
gg[151]++;
break;
case 152:
gg[152]++;
break;
case 153:
gg[153]++;
break;
case 154:
gg[154]++;
break;
case 155:
gg[155]++;
break;
case 156:
gg[156]++;
break;
case 157:
gg[157]++;
break;
case 158:
gg[158]++;
break;
case 159:
gg[159]++;
break;
case 160:
gg[160]++;
break;
case 161:
gg[161]++;
break;
case 162:
gg[162]++;
break;
case 163:
gg[163]++;
break;
case 164:
gg[164]++;
break;
case 165:
gg[165]++;
break;
case 166:
gg[166]++;
break;
case 167:
gg[167]++;
break;
case 168:
gg[168]++;
break;
case 169:
gg[169]++;
break;
case 170:
gg[170]++;
break;
case 171:
gg[171]++;
break;
case 172:
gg[172]++;
break;
case 173:
gg[173]++;
break;
case 174:
gg[174]++;
break;
case 175:
gg[175]++;
break;
case 176:
gg[176]++;
break;
case 177:
gg[177]++;
break;
case 178:
gg[178]++;
break;
case 179:
gg[179]++;
break;
case 180:
gg[180]++;
break;
case 181:
gg[181]++;
break;
case 182:
gg[182]++;
break;
case 183:
gg[183]++;
break;
case 184:
gg[184]++;
break;
case 185:
gg[185]++;
break;
case 186:
gg[186]++;
break;
case 187:
gg[187]++;
break;
case 188:
gg[188]++;
break;
case 189:
gg[189]++;
break;
case 190:
gg[190]++;
break;
case 191:
gg[191]++;
break;
case 192:
gg[192]++;
break;
case 193:
gg[193]++;
break;
case 194:
gg[194]++;
break;
case 195:
gg[195]++;
break;
case 196:
gg[196]++;
break;
case 197:
gg[197]++;
break;
case 198:
gg[198]++;
break;
case 199:
gg[199]++;
break;
case 200:
gg[200]++;
break;
//-----------------------------------------------------------------
case 201:
gg[201]++;
break;
case 202:
gg[202]++;
break;
case 203:
gg[203]++;
break;
case 204:
gg[204]++;
break;
case 205:
gg[205]++;
break;
case 206:
gg[206]++;
break;
case 207:
gg[207]++;
break;
case 208:
gg[208]++;
break;
case 209:
gg[209]++;
break;
case 210:
gg[210]++;
break;
case 211:
gg[211]++;
break;
case 212:
gg[212]++;
break;
case 213:
gg[213]++;
break;
case 214:
gg[214]++;
break;
case 215:
gg[215]++;
break;
case 216:
gg[216]++;
break;
case 217:
gg[217]++;
break;
case 218:
gg[218]++;
break;
case 219:
gg[219]++;
break;
case 220:
gg[220]++;
break;
case 221:
gg[221]++;
break;
case 222:
gg[222]++;
break;
case 223:
gg[223]++;
break;
case 224:
gg[224]++;
break;
case 225:
gg[225]++;
break;
case 226:
gg[226]++;
break;
case 227:
gg[227]++;
break;
case 228:
gg[228]++;
break;
case 229:
gg[229]++;
break;
case 230:
gg[230]++;
break;
case 231:
gg[231]++;
break;
case 232:
gg[232]++;
break;
case 233:
gg[233]++;
break;
case 234:
gg[234]++;
break;
case 235:
gg[235]++;
break;
case 236:
gg[236]++;
break;
case 237:
gg[237]++;
break;
case 238:
gg[238]++;
break;
case 239:
gg[239]++;
break;
case 240:
gg[240]++;
break;
case 241:
gg[241]++;
break;
case 242:
gg[242]++;
break;
case 243:
gg[243]++;
break;
case 244:
gg[244]++;
break;
case 245:
gg[245]++;
break;
case 246:
gg[246]++;
break;
case 247:
gg[247]++;
break;
case 248:
gg[248]++;
break;
case 249:
gg[249]++;
break;
case 250:
gg[250]++;
break;
case 251:
gg[251]++;
break;
case 252:
gg[252]++;
break;
case 253:
gg[253]++;
break;
case 254:
gg[254]++;
break;
case 255:
gg[255]++;
break;
}
#endregion
#region bb
switch(blue)
{
case 0:
bb[0]++;
break;
case 1:
bb[1]++;
break;
case 2:
bb[2]++;
break;
case 3:
bb[3]++;
break;
case 4:
bb[4]++;
break;
case 5:
bb[5]++;
break;
case 6:
bb[6]++;
break;
case 7:
bb[7]++;
break;
case 8:
bb[8]++;
break;
case 9:
bb[9]++;
break;
case 10:
bb[10]++;
break;
case 11:
bb[11]++;
break;
case 12:
bb[12]++;
break;
case 13:
bb[13]++;
break;
case 14:
bb[14]++;
break;
case 15:
bb[15]++;
break;
case 16:
bb[16]++;
break;
case 17:
bb[17]++;
break;
case 18:
bb[18]++;
break;
case 19:
bb[19]++;
break;
case 20:
bb[20]++;
break;
case 21:
bb[21]++;
break;
case 22:
bb[22]++;
break;
case 23:
bb[23]++;
break;
case 24:
bb[24]++;
break;
case 25:
bb[25]++;
break;
case 26:
bb[26]++;
break;
case 27:
bb[27]++;
break;
case 28:
bb[28]++;
break;
case 29:
bb[29]++;
break;
case 30:
bb[30]++;
break;
case 31:
bb[31]++;
break;
case 32:
bb[32]++;
break;
case 33:
bb[33]++;
break;
case 34:
bb[34]++;
break;
case 35:
bb[35]++;
break;
case 36:
bb[36]++;
break;
case 37:
bb[37]++;
break;
case 38:
bb[38]++;
break;
case 39:
bb[39]++;
break;
case 40:
bb[40]++;
break;
case 41:
bb[41]++;
break;
case 42:
bb[42]++;
break;
case 43:
bb[43]++;
break;
case 44:
bb[44]++;
break;
case 45:
bb[45]++;
break;
case 46:
bb[46]++;
break;
case 47:
bb[47]++;
break;
case 48:
bb[48]++;
break;
case 49:
bb[49]++;
break;
case 50:
bb[50]++;
break;
case 51:
bb[51]++;
break;
case 52:
bb[52]++;
break;
case 53:
bb[53]++;
break;
case 54:
bb[54]++;
break;
case 55:
bb[55]++;
break;
case 56:
bb[56]++;
break;
case 57:
bb[57]++;
break;
case 58:
bb[58]++;
break;
case 59:
bb[59]++;
break;
case 60:
bb[60]++;
break;
case 61:
bb[61]++;
break;
case 62:
bb[62]++;
break;
case 63:
bb[63]++;
break;
case 64:
bb[64]++;
break;
case 65:
bb[65]++;
break;
case 66:
bb[66]++;
break;
case 67:
bb[67]++;
break;
case 68:
bb[68]++;
break;
case 69:
bb[69]++;
break;
case 70:
bb[70]++;
break;
case 71:
bb[71]++;
break;
case 72:
bb[72]++;
break;
case 73:
bb[73]++;
break;
case 74:
bb[74]++;
break;
case 75:
bb[75]++;
break;
case 76:
bb[76]++;
break;
case 77:
bb[77]++;
break;
case 78:
bb[78]++;
break;
case 79:
bb[79]++;
break;
case 80:
bb[80]++;
break;
case 81:
bb[81]++;
break;
case 82:
bb[82]++;
break;
case 83:
bb[83]++;
break;
case 84:
bb[84]++;
break;
case 85:
bb[85]++;
break;
case 86:
bb[86]++;
break;
case 87:
bb[87]++;
break;
case 88:
bb[88]++;
break;
case 89:
bb[89]++;
break;
case 90:
bb[90]++;
break;
case 91:
bb[91]++;
break;
case 92:
bb[92]++;
break;
case 93:
bb[93]++;
break;
case 94:
bb[94]++;
break;
case 95:
bb[95]++;
break;
case 96:
bb[96]++;
break;
case 97:
bb[97]++;
break;
case 98:
bb[98]++;
break;
case 99:
bb[99]++;
break;
case 100:
bb[100]++;
break;
//=-----------------------------------------------------------------------------
case 101:
bb[101]++;
break;
case 102:
bb[102]++;
break;
case 103:
bb[103]++;
break;
case 104:
bb[104]++;
break;
case 105:
bb[105]++;
break;
case 106:
bb[106]++;
break;
case 107:
bb[107]++;
break;
case 108:
bb[108]++;
break;
case 109:
bb[109]++;
break;
case 110:
bb[110]++;
break;
case 111:
bb[111]++;
break;
case 112:
bb[112]++;
break;
case 113:
bb[113]++;
break;
case 114:
bb[114]++;
break;
case 115:
bb[115]++;
break;
case 116:
bb[116]++;
break;
case 117:
bb[117]++;
break;
case 118:
bb[118]++;
break;
case 119:
bb[119]++;
break;
case 120:
bb[120]++;
break;
case 121:
bb[121]++;
break;
case 122:
bb[122]++;
break;
case 123:
bb[123]++;
break;
case 124:
bb[124]++;
break;
case 125:
bb[125]++;
break;
case 126:
bb[126]++;
break;
case 127:
bb[127]++;
break;
case 128:
bb[128]++;
break;
case 129:
bb[129]++;
break;
case 130:
bb[130]++;
break;
case 131:
bb[131]++;
break;
case 132:
bb[132]++;
break;
case 133:
bb[133]++;
break;
case 134:
bb[134]++;
break;
case 135:
bb[135]++;
break;
case 136:
bb[136]++;
break;
case 137:
bb[137]++;
break;
case 138:
bb[138]++;
break;
case 139:
bb[139]++;
break;
case 140:
bb[140]++;
break;
case 141:
bb[141]++;
break;
case 142:
bb[142]++;
break;
case 143:
bb[143]++;
break;
case 144:
bb[144]++;
break;
case 145:
bb[145]++;
break;
case 146:
bb[146]++;
break;
case 147:
bb[147]++;
break;
case 148:
bb[148]++;
break;
case 149:
bb[149]++;
break;
case 150:
bb[150]++;
break;
case 151:
bb[151]++;
break;
case 152:
bb[152]++;
break;
case 153:
bb[153]++;
break;
case 154:
bb[154]++;
break;
case 155:
bb[155]++;
break;
case 156:
bb[156]++;
break;
case 157:
bb[157]++;
break;
case 158:
bb[158]++;
break;
case 159:
bb[159]++;
break;
case 160:
bb[160]++;
break;
case 161:
bb[161]++;
break;
case 162:
bb[162]++;
break;
case 163:
bb[163]++;
break;
case 164:
bb[164]++;
break;
case 165:
bb[165]++;
break;
case 166:
bb[166]++;
break;
case 167:
bb[167]++;
break;
case 168:
bb[168]++;
break;
case 169:
bb[169]++;
break;
case 170:
bb[170]++;
break;
case 171:
bb[171]++;
break;
case 172:
bb[172]++;
break;
case 173:
bb[173]++;
break;
case 174:
bb[174]++;
break;
case 175:
bb[175]++;
break;
case 176:
bb[176]++;
break;
case 177:
bb[177]++;
break;
case 178:
bb[178]++;
break;
case 179:
bb[179]++;
break;
case 180:
bb[180]++;
break;
case 181:
bb[181]++;
break;
case 182:
bb[182]++;
break;
case 183:
bb[183]++;
break;
case 184:
bb[184]++;
break;
case 185:
bb[185]++;
break;
case 186:
bb[186]++;
break;
case 187:
bb[187]++;
break;
case 188:
bb[188]++;
break;
case 189:
bb[189]++;
break;
case 190:
bb[190]++;
break;
case 191:
bb[191]++;
break;
case 192:
bb[192]++;
break;
case 193:
bb[193]++;
break;
case 194:
bb[194]++;
break;
case 195:
bb[195]++;
break;
case 196:
bb[196]++;
break;
case 197:
bb[197]++;
break;
case 198:
bb[198]++;
break;
case 199:
bb[199]++;
break;
case 200:
bb[200]++;
break;
//-----------------------------------------------------------------
case 201:
bb[201]++;
break;
case 202:
bb[202]++;
break;
case 203:
bb[203]++;
break;
case 204:
bb[204]++;
break;
case 205:
bb[205]++;
break;
case 206:
bb[206]++;
break;
case 207:
bb[207]++;
break;
case 208:
bb[208]++;
break;
case 209:
bb[209]++;
break;
case 210:
bb[210]++;
break;
case 211:
bb[211]++;
break;
case 212:
bb[212]++;
break;
case 213:
bb[213]++;
break;
case 214:
bb[214]++;
break;
case 215:
bb[215]++;
break;
case 216:
bb[216]++;
break;
case 217:
bb[217]++;
break;
case 218:
bb[218]++;
break;
case 219:
bb[219]++;
break;
case 220:
bb[220]++;
break;
case 221:
bb[221]++;
break;
case 222:
bb[222]++;
break;
case 223:
bb[223]++;
break;
case 224:
bb[224]++;
break;
case 225:
bb[225]++;
break;
case 226:
bb[226]++;
break;
case 227:
bb[227]++;
break;
case 228:
bb[228]++;
break;
case 229:
bb[229]++;
break;
case 230:
bb[230]++;
break;
case 231:
bb[231]++;
break;
case 232:
bb[232]++;
break;
case 233:
bb[233]++;
break;
case 234:
bb[234]++;
break;
case 235:
bb[235]++;
break;
case 236:
bb[236]++;
break;
case 237:
bb[237]++;
break;
case 238:
bb[238]++;
break;
case 239:
bb[239]++;
break;
case 240:
bb[240]++;
break;
case 241:
bb[241]++;
break;
case 242:
bb[242]++;
break;
case 243:
bb[243]++;
break;
case 244:
bb[244]++;
break;
case 245:
bb[245]++;
break;
case 246:
bb[246]++;
break;
case 247:
bb[247]++;
break;
case 248:
bb[248]++;
break;
case 249:
bb[249]++;
break;
case 250:
bb[250]++;
break;
case 251:
bb[251]++;
break;
case 252:
bb[252]++;
break;
case 253:
bb[253]++;
break;
case 254:
bb[254]++;
break;
case 255:
bb[255]++;
break;
}
#endregion
#region gray
switch(tt)
{
case 0:
gray[0]++;
break;
case 1:
gray[1]++;
break;
case 2:
gray[2]++;
break;
case 3:
gray[3]++;
break;
case 4:
gray[4]++;
break;
case 5:
gray[5]++;
break;
case 6:
gray[6]++;
break;
case 7:
gray[7]++;
break;
case 8:
gray[8]++;
break;
case 9:
gray[9]++;
break;
case 10:
gray[10]++;
break;
case 11:
gray[11]++;
break;
case 12:
gray[12]++;
break;
case 13:
gray[13]++;
break;
case 14:
gray[14]++;
break;
case 15:
gray[15]++;
break;
case 16:
gray[16]++;
break;
case 17:
gray[17]++;
break;
case 18:
gray[18]++;
break;
case 19:
gray[19]++;
break;
case 20:
gray[20]++;
break;
case 21:
gray[21]++;
break;
case 22:
gray[22]++;
break;
case 23:
gray[23]++;
break;
case 24:
gray[24]++;
break;
case 25:
gray[25]++;
break;
case 26:
gray[26]++;
break;
case 27:
gray[27]++;
break;
case 28:
gray[28]++;
break;
case 29:
gray[29]++;
break;
case 30:
gray[30]++;
break;
case 31:
gray[31]++;
break;
case 32:
gray[32]++;
break;
case 33:
gray[33]++;
break;
case 34:
gray[34]++;
break;
case 35:
gray[35]++;
break;
case 36:
gray[36]++;
break;
case 37:
gray[37]++;
break;
case 38:
gray[38]++;
break;
case 39:
gray[39]++;
break;
case 40:
gray[40]++;
break;
case 41:
gray[41]++;
break;
case 42:
gray[42]++;
break;
case 43:
gray[43]++;
break;
case 44:
gray[44]++;
break;
case 45:
gray[45]++;
break;
case 46:
gray[46]++;
break;
case 47:
gray[47]++;
break;
case 48:
gray[48]++;
break;
case 49:
gray[49]++;
break;
case 50:
gray[50]++;
break;
case 51:
gray[51]++;
break;
case 52:
gray[52]++;
break;
case 53:
gray[53]++;
break;
case 54:
gray[54]++;
break;
case 55:
gray[55]++;
break;
case 56:
gray[56]++;
break;
case 57:
gray[57]++;
break;
case 58:
gray[58]++;
break;
case 59:
gray[59]++;
break;
case 60:
gray[60]++;
break;
case 61:
gray[61]++;
break;
case 62:
gray[62]++;
break;
case 63:
gray[63]++;
break;
case 64:
gray[64]++;
break;
case 65:
gray[65]++;
break;
case 66:
gray[66]++;
break;
case 67:
gray[67]++;
break;
case 68:
gray[68]++;
break;
case 69:
gray[69]++;
break;
case 70:
gray[70]++;
break;
case 71:
gray[71]++;
break;
case 72:
gray[72]++;
break;
case 73:
gray[73]++;
break;
case 74:
gray[74]++;
break;
case 75:
gray[75]++;
break;
case 76:
gray[76]++;
break;
case 77:
gray[77]++;
break;
case 78:
gray[78]++;
break;
case 79:
gray[79]++;
break;
case 80:
gray[80]++;
break;
case 81:
gray[81]++;
break;
case 82:
gray[82]++;
break;
case 83:
gray[83]++;
break;
case 84:
gray[84]++;
break;
case 85:
gray[85]++;
break;
case 86:
gray[86]++;
break;
case 87:
gray[87]++;
break;
case 88:
gray[88]++;
break;
case 89:
gray[89]++;
break;
case 90:
gray[90]++;
break;
case 91:
gray[91]++;
break;
case 92:
gray[92]++;
break;
case 93:
gray[93]++;
break;
case 94:
gray[94]++;
break;
case 95:
gray[95]++;
break;
case 96:
gray[96]++;
break;
case 97:
gray[97]++;
break;
case 98:
gray[98]++;
break;
case 99:
gray[99]++;
break;
case 100:
gray[100]++;
break;
//=-----------------------------------------------------------------------------
case 101:
gray[101]++;
break;
case 102:
gray[102]++;
break;
case 103:
gray[103]++;
break;
case 104:
gray[104]++;
break;
case 105:
gray[105]++;
break;
case 106:
gray[106]++;
break;
case 107:
gray[107]++;
break;
case 108:
gray[108]++;
break;
case 109:
gray[109]++;
break;
case 110:
gray[110]++;
break;
case 111:
gray[111]++;
break;
case 112:
gray[112]++;
break;
case 113:
gray[113]++;
break;
case 114:
gray[114]++;
break;
case 115:
gray[115]++;
break;
case 116:
gray[116]++;
break;
case 117:
gray[117]++;
break;
case 118:
gray[118]++;
break;
case 119:
gray[119]++;
break;
case 120:
gray[120]++;
break;
case 121:
gray[121]++;
break;
case 122:
gray[122]++;
break;
case 123:
gray[123]++;
break;
case 124:
gray[124]++;
break;
case 125:
gray[125]++;
break;
case 126:
gray[126]++;
break;
case 127:
gray[127]++;
break;
case 128:
gray[128]++;
break;
case 129:
gray[129]++;
break;
case 130:
gray[130]++;
break;
case 131:
gray[131]++;
break;
case 132:
gray[132]++;
break;
case 133:
gray[133]++;
break;
case 134:
gray[134]++;
break;
case 135:
gray[135]++;
break;
case 136:
gray[136]++;
break;
case 137:
gray[137]++;
break;
case 138:
gray[138]++;
break;
case 139:
gray[139]++;
break;
case 140:
gray[140]++;
break;
case 141:
gray[141]++;
break;
case 142:
gray[142]++;
break;
case 143:
gray[143]++;
break;
case 144:
gray[144]++;
break;
case 145:
gray[145]++;
break;
case 146:
gray[146]++;
break;
case 147:
gray[147]++;
break;
case 148:
gray[148]++;
break;
case 149:
gray[149]++;
break;
case 150:
gray[150]++;
break;
case 151:
gray[151]++;
break;
case 152:
gray[152]++;
break;
case 153:
gray[153]++;
break;
case 154:
gray[154]++;
break;
case 155:
gray[155]++;
break;
case 156:
gray[156]++;
break;
case 157:
gray[157]++;
break;
case 158:
gray[158]++;
break;
case 159:
gray[159]++;
break;
case 160:
gray[160]++;
break;
case 161:
gray[161]++;
break;
case 162:
gray[162]++;
break;
case 163:
gray[163]++;
break;
case 164:
gray[164]++;
break;
case 165:
gray[165]++;
break;
case 166:
gray[166]++;
break;
case 167:
gray[167]++;
break;
case 168:
gray[168]++;
break;
case 169:
gray[169]++;
break;
case 170:
gray[170]++;
break;
case 171:
gray[171]++;
break;
case 172:
gray[172]++;
break;
case 173:
gray[173]++;
break;
case 174:
gray[174]++;
break;
case 175:
gray[175]++;
break;
case 176:
gray[176]++;
break;
case 177:
gray[177]++;
break;
case 178:
gray[178]++;
break;
case 179:
gray[179]++;
break;
case 180:
gray[180]++;
break;
case 181:
gray[181]++;
break;
case 182:
gray[182]++;
break;
case 183:
gray[183]++;
break;
case 184:
gray[184]++;
break;
case 185:
gray[185]++;
break;
case 186:
gray[186]++;
break;
case 187:
gray[187]++;
break;
case 188:
gray[188]++;
break;
case 189:
gray[189]++;
break;
case 190:
gray[190]++;
break;
case 191:
gray[191]++;
break;
case 192:
gray[192]++;
break;
case 193:
gray[193]++;
break;
case 194:
gray[194]++;
break;
case 195:
gray[195]++;
break;
case 196:
gray[196]++;
break;
case 197:
gray[197]++;
break;
case 198:
gray[198]++;
break;
case 199:
gray[199]++;
break;
case 200:
gray[200]++;
break;
//-----------------------------------------------------------------
case 201:
gray[201]++;
break;
case 202:
gray[202]++;
break;
case 203:
gray[203]++;
break;
case 204:
gray[204]++;
break;
case 205:
gray[205]++;
break;
case 206:
gray[206]++;
break;
case 207:
gray[207]++;
break;
case 208:
gray[208]++;
break;
case 209:
gray[209]++;
break;
case 210:
gray[210]++;
break;
case 211:
gray[211]++;
break;
case 212:
gray[212]++;
break;
case 213:
gray[213]++;
break;
case 214:
gray[214]++;
break;
case 215:
gray[215]++;
break;
case 216:
gray[216]++;
break;
case 217:
gray[217]++;
break;
case 218:
gray[218]++;
break;
case 219:
gray[219]++;
break;
case 220:
gray[220]++;
break;
case 221:
gray[221]++;
break;
case 222:
gray[222]++;
break;
case 223:
gray[223]++;
break;
case 224:
gray[224]++;
break;
case 225:
gray[225]++;
break;
case 226:
gray[226]++;
break;
case 227:
gray[227]++;
break;
case 228:
gray[228]++;
break;
case 229:
gray[229]++;
break;
case 230:
gray[230]++;
break;
case 231:
gray[231]++;
break;
case 232:
gray[232]++;
break;
case 233:
gray[233]++;
break;
case 234:
gray[234]++;
break;
case 235:
gray[235]++;
break;
case 236:
gray[236]++;
break;
case 237:
gray[237]++;
break;
case 238:
gray[238]++;
break;
case 239:
gray[239]++;
break;
case 240:
gray[240]++;
break;
case 241:
gray[241]++;
break;
case 242:
gray[242]++;
break;
case 243:
gray[243]++;
break;
case 244:
gray[244]++;
break;
case 245:
gray[245]++;
break;
case 246:
gray[246]++;
break;
case 247:
gray[247]++;
break;
case 248:
gray[248]++;
break;
case 249:
gray[249]++;
break;
case 250:
gray[250]++;
break;
case 251:
gray[251]++;
break;
case 252:
gray[252]++;
break;
case 253:
gray[253]++;
break;
case 254:
gray[254]++;
break;
case 255:
gray[255]++;
break;
}
#endregion
p += 3;
}
p += nOffset;
}
}
all=gray;
rhow=rr;
ghow=gg;
bhow=bb;
b.UnlockBits(bmData);
return true;
}
}
}
//直方图--------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace zft
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button button1;
int [] gray=new int[256];
int [] rr = new int[256];
int [] gg = new int[256];
int [] bb = new int[256];
public Bitmap a=new Bitmap(500,500);
public Bitmap b=new Bitmap(500,500);
Pen pen1=new Pen(Color.Black);
int flag=0;
float count ;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label l_sejie;
private System.Windows.Forms.Label l_pinjun;
private System.Windows.Forms.Label l_pixel;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox3;
float [] gl=new float[256];
private System.Windows.Forms.Label l_bfb;
private System.Windows.Forms.Label l_how;
private bool aline=false;
private System.Windows.Forms.Label lcolor;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button undo;
private System.Windows.Forms.Button refresh;
int xx=-1;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button5 = new System.Windows.Forms.Button();
this.l_pinjun = new System.Windows.Forms.Label();
this.l_pixel = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label11 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.lcolor = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.l_how = new System.Windows.Forms.Label();
this.l_bfb = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.l_sejie = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.undo = new System.Windows.Forms.Button();
this.refresh = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(276, 56);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 28);
this.button1.TabIndex = 0;
this.button1.Text = "灰度";
this.button1.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(276, 92);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 28);
this.button2.TabIndex = 1;
this.button2.Text = "红";
this.button2.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(276, 124);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(64, 28);
this.button3.TabIndex = 2;
this.button3.Text = "绿";
this.button3.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(276, 156);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(64, 28);
this.button4.TabIndex = 3;
this.button4.Text = "蓝";
this.button4.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// label1
//
this.label1.BackColor = System.Drawing.Color.White;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Cursor = System.Windows.Forms.Cursors.Cross;
this.label1.Location = new System.Drawing.Point(12, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(258, 129);
this.label1.TabIndex = 4;
this.label1.Paint += new System.Windows.Forms.PaintEventHandler(this.label1_Paint);
this.label1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.label1_MouseUp);
this.label1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.label1_MouseMove);
this.label1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.label1_MouseDown);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.button5);
this.groupBox1.Controls.Add(this.l_pinjun);
this.groupBox1.Controls.Add(this.l_pixel);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.groupBox4);
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.label11);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.lcolor);
this.groupBox1.Controls.Add(this.textBox3);
this.groupBox1.Controls.Add(this.l_how);
this.groupBox1.Controls.Add(this.l_bfb);
this.groupBox1.Controls.Add(this.label10);
this.groupBox1.Controls.Add(this.label9);
this.groupBox1.Controls.Add(this.label8);
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.l_sejie);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.button4);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Font = new System.Drawing.Font("宋体", 12F);
this.groupBox1.Location = new System.Drawing.Point(8, 4);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(352, 340);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "直方图";
this.groupBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.groupBox1_Paint);
//
// button5
//
this.button5.Location = new System.Drawing.Point(276, 224);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(64, 24);
this.button5.TabIndex = 26;
this.button5.Text = "ok";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// l_pinjun
//
this.l_pinjun.Location = new System.Drawing.Point(76, 292);
this.l_pinjun.Name = "l_pinjun";
this.l_pinjun.Size = new System.Drawing.Size(88, 20);
this.l_pinjun.TabIndex = 8;
this.l_pinjun.Text = "0";
this.l_pinjun.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// l_pixel
//
this.l_pixel.Location = new System.Drawing.Point(76, 272);
this.l_pixel.Name = "l_pixel";
this.l_pixel.Size = new System.Drawing.Size(88, 20);
this.l_pixel.TabIndex = 9;
this.l_pixel.Text = "0";
this.l_pixel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(124, 224);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(48, 26);
this.textBox1.TabIndex = 16;
this.textBox1.Text = "0";
//
// groupBox4
//
this.groupBox4.Location = new System.Drawing.Point(176, 228);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(44, 8);
this.groupBox4.TabIndex = 25;
this.groupBox4.TabStop = false;
//
// groupBox2
//
this.groupBox2.Location = new System.Drawing.Point(176, 32);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(40, 8);
this.groupBox2.TabIndex = 24;
this.groupBox2.TabStop = false;
//
// label11
//
this.label11.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label11.Location = new System.Drawing.Point(220, 28);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(52, 23);
this.label11.TabIndex = 23;
this.label11.Text = "255";
this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label6
//
this.label6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label6.Location = new System.Drawing.Point(124, 28);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(48, 23);
this.label6.TabIndex = 22;
this.label6.Text = "0";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 224);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(116, 23);
this.label5.TabIndex = 21;
this.label5.Text = "输出色阶范围:";
//
// lcolor
//
this.lcolor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lcolor.Location = new System.Drawing.Point(12, 192);
this.lcolor.Name = "lcolor";
this.lcolor.Size = new System.Drawing.Size(260, 12);
this.lcolor.TabIndex = 19;
this.lcolor.Paint += new System.Windows.Forms.PaintEventHandler(this.lcolor_Paint);
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(224, 224);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(48, 26);
this.textBox3.TabIndex = 18;
this.textBox3.Text = "255";
//
// l_how
//
this.l_how.Location = new System.Drawing.Point(212, 292);
this.l_how.Name = "l_how";
this.l_how.Size = new System.Drawing.Size(120, 20);
this.l_how.TabIndex = 15;
this.l_how.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// l_bfb
//
this.l_bfb.Location = new System.Drawing.Point(208, 312);
this.l_bfb.Name = "l_bfb";
this.l_bfb.Size = new System.Drawing.Size(124, 20);
this.l_bfb.TabIndex = 14;
this.l_bfb.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label10
//
this.label10.Location = new System.Drawing.Point(144, 312);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(68, 20);
this.label10.TabIndex = 13;
this.label10.Text = "百分比:";
this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label9
//
this.label9.Location = new System.Drawing.Point(16, 28);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(84, 23);
this.label9.TabIndex = 12;
this.label9.Text = "色阶范围:";
//
// label8
//
this.label8.Location = new System.Drawing.Point(4, 292);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(68, 20);
this.label8.TabIndex = 11;
this.label8.Text = "平均值:";
this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label7
//
this.label7.Location = new System.Drawing.Point(144, 272);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(68, 20);
this.label7.TabIndex = 10;
this.label7.Text = "色阶:";
this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// l_sejie
//
this.l_sejie.Location = new System.Drawing.Point(212, 272);
this.l_sejie.Name = "l_sejie";
this.l_sejie.Size = new System.Drawing.Size(120, 20);
this.l_sejie.TabIndex = 7;
this.l_sejie.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label3
//
this.label3.Location = new System.Drawing.Point(152, 292);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(60, 20);
this.label3.TabIndex = 6;
this.label3.Text = "数量:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 272);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 20);
this.label2.TabIndex = 5;
this.label2.Text = "像素:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// undo
//
this.undo.Location = new System.Drawing.Point(368, 16);
this.undo.Name = "undo";
this.undo.TabIndex = 6;
this.undo.Text = "undo";
this.undo.Click += new System.EventHandler(this.undo_Click);
//
// refresh
//
this.refresh.Location = new System.Drawing.Point(368, 48);
this.refresh.Name = "refresh";
this.refresh.TabIndex = 7;
this.refresh.Text = "refresh";
this.refresh.Click += new System.EventHandler(this.refresh_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(450, 350);
this.Controls.Add(this.refresh);
this.Controls.Add(this.undo);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "色阶和直方图";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void Form1_Load(object sender, System.EventArgs e)
{
this.TopMost=true;
this.Left=800;
BitmapFilter.zft(a,out gray,out rr,out gg, out bb);
graydo();
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
Graphics g=e.Graphics;
}
private void button1_Click(object sender, System.EventArgs e)
{
graydo();
}
private void graydo()
{
this.flag=1;
count = a.Width * a.Height;
gl=new float[256];
for(int i=0;i<256; i++)
gl[i]= gray[i]/count *10000;
pen1=Pens.Black;
this.label1.Invalidate();
this.lcolor.Invalidate();
}
private void button2_Click(object sender, System.EventArgs e)
{
this.flag=2;
count = a.Width * a.Height;
gl=new float[256];
for(int i=0;i<256; i++)
gl[i]= rr[i]/count *10000;
pen1=Pens.Red;
this.label1.Invalidate();
this.lcolor.Invalidate();
}
private void button3_Click(object sender, System.EventArgs e)
{
this.flag=3;
count = a.Width * a.Height;
gl=new float[256];
for(int i=0;i<256; i++)
gl[i]= gg[i]/count *10000;
pen1=Pens.Green;
this.label1.Invalidate();
this.lcolor.Invalidate();
}
private void button4_Click(object sender, System.EventArgs e)
{
this.flag=4;
count = a.Width * a.Height;
gl=new float[256];
for(int i=0;i<256; i++)
gl[i]= bb[i]/count *10000;
pen1=Pens.Blue;
this.label1.Invalidate();
this.lcolor.Invalidate();
}
private void label1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g=e.Graphics;
int p;
p= a.Width*a.Height;
this.l_pixel.Text=p.ToString();
int height =this.label1.Height;
for(int j=0;j<256;j++)
{
if(gl[j]>height)
gl[j]=height;
g.DrawLine(pen1,j,height,j,height-gl[j]);
}
if(aline)
{
g.DrawLine(Pens.OrangeRed,xx,0,xx,height);
}
if(xx!=-1)
{
this.l_sejie.Text =xx.ToString();
this.l_how.Text =this.gray[xx].ToString();
this.l_bfb.Text =this.gl[xx].ToString();
}
else
{
this.l_sejie.Text=" ";
this.l_how.Text =" ";
this.l_bfb.Text =" ";
}
}
private void label1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
xx=e.X;
if(xx>255)
xx=255;
if(xx<=0)
xx=0;
aline=true;
this.label1.Invalidate();
}
private void label1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
/*
if((e.X>255)&&(e.X<0)&&(e.Y<0)&&(e.Y>127))
{
this.xx=-1;
}
else
{
this.xx=e.X;
}
this.label4.Text=e.X.ToString()+" "+e.Y.ToString();
*/
Point p=new Point(e.X,e.Y);
if(new Rectangle(0,0,256,127).Contains(p))
{
this.xx=e.X;
}
else
{
this.xx=-1;
}
this.label1.Invalidate();
}
private void label1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
aline=false;
}
private void lcolor_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
int width=this.lcolor.Width;
int height=this.lcolor.Height;
int j;
Color c;
Graphics g=e.Graphics;
switch(flag)
{
case 1:
{
for(int i=width;i>=0;i--)
{
j=i;
if(j>255) j=255;
c=Color.FromArgb(j,j,j);
Pen pen2=new Pen(c,1);
g.DrawLine(pen2,i,0,i,height);
}
break;
}
case 2:
{
for(int i=width;i>=0;i--)
{
j=i;
if(j>255) j=255;
c=Color.FromArgb(j,0,0);
Pen pen2=new Pen(c,1);
g.DrawLine(pen2,i,0,i,height);
}
break;
}
case 3:
{
for(int i=width;i>=0;i--)
{
j=i;
if(j>255) j=255;
c=Color.FromArgb(0,j,0);
Pen pen2=new Pen(c,1);
g.DrawLine(pen2,i,0,i,height);
}
break;
}
case 4:
{
for(int i=width;i>=0;i--)
{
j=i;
if(j>255) j=255;
c=Color.FromArgb(0,0,j);
Pen pen2=new Pen(c,1);
g.DrawLine(pen2,i,0,i,height);
}
break;
}
default:
break;
}
}
private void groupBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g=e.Graphics;
int x=this.lcolor.Left;
int y=this.lcolor.Top;
int w=this.lcolor.Width;
int h=this.lcolor.Height;
PointF [] pp=new PointF [4];
pp[0]=new PointF(x ,y+h+5);
pp[1]=new PointF(x-5 ,y+h+15);
pp[2]=new PointF(x+5 ,y+h+15);
pp[3]=new PointF(x ,y+h+5);
g.FillPolygon(Brushes.Black,pp);
x+=w/2;
pp[0]=new PointF(x ,y+h+5);
pp[1]=new PointF(x-5 ,y+h+15);
pp[2]=new PointF(x+5 ,y+h+15);
pp[3]=new PointF(x ,y+h+5);
g.FillPolygon(Brushes.Gray,pp);
x+=w/2;
pp[0]=new PointF(x ,y+h+5);
pp[1]=new PointF(x-5 ,y+h+15);
pp[2]=new PointF(x+5 ,y+h+15);
pp[3]=new PointF(x ,y+h+5);
g.FillPolygon(Brushes.Black,pp);
}
private void button5_Click(object sender, System.EventArgs e)
{
int a1=Convert.ToInt32(this.textBox1.Text);
int a2=Convert.ToInt32(this.textBox3.Text);
}
private void undo_Click(object sender, System.EventArgs e)
{
this.a=(Bitmap)this.b.Clone();
}
private void refresh_Click(object sender, System.EventArgs e)
{
doing();
}
public void doing()
{
BitmapFilter.zft(a,out gray,out rr,out gg, out bb);
graydo();
this.Invalidate();
}
}
}
//有点累,呵呵!
本文地址:http://com.8s8s.com/it/it44114.htm