procedure TDemoHistogram.Run;
var
Bitmap: IGPBitmap;
Histogram: IGPHistogram;
I, J, X, Y, MaxVal: Integer;
Scale: Double;
Pen: IGPPen;
begin
Bitmap := TGPBitmap.Create('
ImageFileSmall.jpg');
// <-- Hier drum geht es !
Graphics.DrawImage(Bitmap, 10, 10, Bitmap.Width, Bitmap.Height);
// Retrieve RGB histogram of bitmap
Histogram := Bitmap.GetHistogram(HistogramFormatRGB);
// Determine the maximum value in the histogram
MaxVal := 0;
for J := 0
to Histogram.ChannelCount - 1
do
for I := 0
to Histogram.EntryCount - 1
do
MaxVal := Max(MaxVal, Histogram[J, I]);
// Scale maximum value so it displays as the height of the bitmap
Scale := Bitmap.Height / MaxVal;
// Draw the histogram next to the bitmap
Pen := TGPPen.Create(0);
X := 10 + Bitmap.Width + 10;
Y := 10 + Bitmap.Height;
for I := 0
to Histogram.ChannelCount - 1
do
begin
if (I = 0)
then
Pen.Color := TGPColor.Create(128, 255, 0, 0)
else if (I = 1)
then
Pen.Color := TGPColor.Create(128, 0, 255, 0)
else
Pen.Color := TGPColor.Create(128, 0, 0, 255);
for J := 0
to Histogram.EntryCount - 1
do
Graphics.DrawLine(Pen, X + J, Y, X + J, Y - Scale * Histogram[I, J]);
end;
end;