不会把,我写了一个灰度直方图的东西,好像是可以的:
procedure TMainForm.GrayDiagramClick(Sender: TObject);
var
p: PByteArray;
i, x, y, j: Integer;
Bmp, bmp2: TBitmap;
Gray: byte;
color: Tcolor;
grayform: tgrayform;
maxvalue: integer;
begin
StartTime := GetTickCount;
Bmp := TBitmap.Create;
Bmp.Assign(childForm.Image1.Picture.Bitmap);
Bmp.PixelFormat := pf24Bit;
for y := 0 to Bmp.Height - 1 do//某一灰度出现频率
begin
p := Bmp.scanline[y];
for x := 0 to Bmp.Width - 1 do
begin
Gray := round(p[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x * 3]
* 0.11);
for i := 0 to 255 do
begin
if Gray = i then
begin
Grayclass := Grayclass + 1;
end;
end;
end
end;
bmp.Free;
maxvalue := grayclass[0];
grayform := Tgrayform.Create(self);
GrayForm.Show;
GrayFORM.Image1.Canvas.Brush.color := clblack;
GrayFORM.Image1.Canvas.Pen.Color := clblue;
for i := 1 to 255 do
begin
if maxvalue < grayclass then
begin
maxvalue := grayclass; //最大灰度值
end;
end;
for i := 0 to 255 do //画图
begin
begin
Grayform.Image1.Canvas.MoveTo(i, 273);
Grayform.Image1.Canvas.LineTo(i, 273 - round(50 * (log10(grayclass
+
1))));
end;
end;
Grayform.Image1.Canvas.Pen.Color := clred;
Grayform.Image1.Canvas.MoveTo(0, 272); //画标尺
Grayform.Image1.Canvas.LineTo(255, 272);
for i := 0 to 25 do
begin
Grayform.Image1.Canvas.MoveTo(10 * i, 272);
Grayform.Image1.Canvas.LineTo(10 * i, 269);
end;
for i := 0 to 5 do
begin
Grayform.Image1.Canvas.MoveTo(50 * i, 272);
Grayform.Image1.Canvas.LineTo(50 * i, 266);
end;
bmp2 := Tbitmap.Create; //画灰度渐变条
bmp2.Width := grayform.Image2.Width;
bmp2.Height := grayform.Image2.Height;
for i := 0 to bmp2.Width do
begin
color := RGB(i, i, i);
for j := 0 to bmp2.Height do
begin
bmp2.Canvas.Pixels[i, j] := color;
end;
end;
grayform.Image2.Picture.Bitmap.Assign(bmp2);
bmp2.Free;
end;