unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, TAGraph, TASeries, Forms, Controls, Graphics,
Dialogs, ExtCtrls, ExtDlgs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Chart1: TChart;
Chart1BarSeries1: TBarSeries;
Chart1BarSeries2: TBarSeries;
Chart1BarSeries3: TBarSeries;
Chart1BarSeries4: TBarSeries;
Chart1BarSeries5: TBarSeries;
Chart1BarSeries6: TBarSeries;
Chart2: TChart;
Chart3: TChart;
Chart4: TChart;
Chart5: TChart;
Chart6: TChart;
Image1: TImage;
Image2: TImage;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
Procedure NegatifImage;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
Procedure TForm1.NegatifImage;
Function NegatifIt (Color : TColor) : TColor;
Begin
Result := RgbToColor ((255 - Red (Color)),(255 - Green (Color)),(255 - Blue (Color)));
end;
var
TempBitmap : TBitmap;
X,Y : Integer;
TempColor : TColor;
RR : TRect;
HistDataRed : Array [0..255] Of Byte;
HistDataGreen : Array [0..255] Of Byte;
HistDataBlue : Array [0..255] Of Byte;
HistDataRed1 : Array [0..255] Of Byte;
HistDataGreen1 : Array [0..255] Of Byte;
HistDataBlue1 : Array [0..255] Of Byte;
begin
If Not Image1.Picture.Graphic.Empty Then
Begin
TempBitmap := TBitmap.Create;
TempBitmap.SetSize(250,250);
TempBitmap.Canvas.Clear;
RR.Top:=0;
RR.Left := 0;
RR.Bottom:= 250;
RR.Right:= 250;
FillByte(HistDataRed,SizeOf (HistDataRed),0);
FillByte(HistDataGreen,SizeOf (HistDataGreen),0);
FillByte(HistDataBlue,SizeOf (HistDataBlue),0);
FillByte(HistDataRed1,SizeOf (HistDataRed1),0);
FillByte(HistDataGreen1,SizeOf (HistDataGreen1),0);
FillByte(HistDataBlue1,SizeOf (HistDataBlue1),0);
TempBitmap.Canvas.StretchDraw(RR,Image1.Picture.Graphic);
For Y := 0 To TempBitmap.Height - 1 Do
Begin
For X := 0 To TempBitmap.Width - 1 Do
Begin
TempColor := TempBitmap.Canvas.Pixels[X,Y];
Inc (HistDataRed [Red (TempColor)]);
Inc (HistDataGreen [Green (TempColor)]);
Inc (HistDataBlue [Blue (TempColor)]);
TempColor := NegatifIt(TempColor);
Inc (HistDataRed1 [Red (TempColor)]);
Inc (HistDataGreen1 [Green (TempColor)]);
Inc (HistDataBlue1 [Blue (TempColor)]);
TempBitmap.Canvas.Pixels[X,Y] := TempColor;
end;
end;
For X := 0 To 255 Do
Begin
Chart1BarSeries1.AddXY(X,HistDataRed[X],'',clRed);
Chart1BarSeries2.AddXY(X,HistDataGreen[X],'',clGreen);
Chart1BarSeries3.AddXY(X,HistDataBlue[X],'',clBlue);
Chart1BarSeries4.AddXY(X,HistDataRed1[X],'',clRed);
Chart1BarSeries5.AddXY(X,HistDataGreen1[X],'',clGreen);
Chart1BarSeries6.AddXY(X,HistDataBlue1[X],'',clBlue);
end;
Image2.Picture.Assign(TempBitmap);
TempBitmap.free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
If OpenPictureDialog1.Execute Then
Begin
Image1.Picture.Clear;
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
Image2.Picture.Clear;
Chart1BarSeries1.Clear;
Chart1BarSeries2.Clear;
Chart1BarSeries3.Clear;
Chart1BarSeries4.Clear;
Chart1BarSeries5.Clear;
Chart1BarSeries6.Clear;
NegatifImage;
end;
end;
end.
//unit main.lfm
object Form1: TForm1
Left = 79
Height = 559
Top = 129
Width = 1081
Caption = 'Membuat gambar negatif plus histogram gambar 250*250'
ClientHeight = 559
ClientWidth = 1081
ShowHint = True
LCLVersion = '1.4.4.0'
object Image1: TImage
Left = 8
Height = 250
Top = 8
Width = 250
Center = True
ParentShowHint = False
Stretch = True
end
object Button1: TButton
Left = 80
Height = 25
Top = 264
Width = 96
Caption = 'Buka Gambar'
OnClick = Button1Click
TabOrder = 0
end
object Image2: TImage
Left = 8
Height = 250
Top = 296
Width = 250
end
object Chart1: TChart
Left = 288
Height = 250
Top = 8
Width = 250
AxisList = <
item
Grid.Visible = False
Minors = <>
Range.UseMin = True
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Jumlah'
end
item
Grid.Visible = False
Intervals.Count = 0
Alignment = calBottom
Marks.Range.Max = 255
Marks.Range.UseMax = True
Marks.Range.UseMin = True
Minors = <>
Range.Max = 255
Range.UseMax = True
Range.UseMin = True
Title.Caption = 'Color'
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clRed
Foot.Text.Strings = (
'Warna'
)
Foot.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
object Chart1BarSeries1: TBarSeries
Title = 'Histogram Color'
BarBrush.Color = clRed
BarWidthPercent = 1
end
end
object Chart2: TChart
Left = 552
Height = 250
Top = 8
Width = 250
AxisList = <
item
Grid.Visible = False
Minors = <>
Range.UseMin = True
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Jumlah'
end
item
Grid.Visible = False
Intervals.Count = 0
Alignment = calBottom
Marks.Range.Max = 255
Marks.Range.UseMax = True
Marks.Range.UseMin = True
Minors = <>
Range.Max = 255
Range.UseMax = True
Range.UseMin = True
Title.Caption = 'Color'
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clGreen
Foot.Text.Strings = (
'Warna'
)
Foot.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
object Chart1BarSeries2: TBarSeries
Title = 'Histogram Color'
BarBrush.Color = clRed
BarWidthPercent = 1
end
end
object Chart3: TChart
Left = 816
Height = 250
Top = 8
Width = 250
AxisList = <
item
Grid.Visible = False
Minors = <>
Range.UseMin = True
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Jumlah'
end
item
Grid.Visible = False
Intervals.Count = 0
Alignment = calBottom
Marks.Range.Max = 255
Marks.Range.UseMax = True
Marks.Range.UseMin = True
Minors = <>
Range.Max = 255
Range.UseMax = True
Range.UseMin = True
Title.Caption = 'Color'
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Foot.Text.Strings = (
'Warna'
)
Foot.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
object Chart1BarSeries3: TBarSeries
Title = 'Histogram Color'
BarBrush.Color = clRed
BarWidthPercent = 1
end
end
object Chart4: TChart
Left = 288
Height = 250
Top = 296
Width = 250
AxisList = <
item
Grid.Visible = False
Minors = <>
Range.UseMin = True
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Jumlah'
end
item
Grid.Visible = False
Intervals.Count = 0
Alignment = calBottom
Marks.Range.Max = 255
Marks.Range.UseMax = True
Marks.Range.UseMin = True
Minors = <>
Range.Max = 255
Range.UseMax = True
Range.UseMin = True
Title.Caption = 'Color'
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clRed
Foot.Text.Strings = (
'Warna'
)
Foot.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
object Chart1BarSeries4: TBarSeries
Title = 'Histogram Color'
BarBrush.Color = clRed
BarWidthPercent = 1
end
end
object Chart5: TChart
Left = 552
Height = 250
Top = 296
Width = 250
AxisList = <
item
Grid.Visible = False
Minors = <>
Range.UseMin = True
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Jumlah'
end
item
Grid.Visible = False
Intervals.Count = 0
Alignment = calBottom
Marks.Range.Max = 255
Marks.Range.UseMax = True
Marks.Range.UseMin = True
Minors = <>
Range.Max = 255
Range.UseMax = True
Range.UseMin = True
Title.Caption = 'Color'
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clGreen
Foot.Text.Strings = (
'Warna'
)
Foot.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
object Chart1BarSeries5: TBarSeries
Title = 'Histogram Color'
BarBrush.Color = clRed
BarWidthPercent = 1
end
end
object Chart6: TChart
Left = 816
Height = 250
Top = 296
Width = 250
AxisList = <
item
Grid.Visible = False
Minors = <>
Range.UseMin = True
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Jumlah'
end
item
Grid.Visible = False
Intervals.Count = 0
Alignment = calBottom
Marks.Range.Max = 255
Marks.Range.UseMax = True
Marks.Range.UseMin = True
Minors = <>
Range.Max = 255
Range.UseMax = True
Range.UseMin = True
Title.Caption = 'Color'
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
Foot.Text.Strings = (
'Warna'
)
Foot.Visible = True
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
object Chart1BarSeries6: TBarSeries
Title = 'Histogram Color'
BarBrush.Color = clRed
BarWidthPercent = 1
end
end
object OpenPictureDialog1: TOpenPictureDialog
left = 208
top = 16
end
end
***** SEMOGA BERMANFAAT *****
Tidak ada komentar:
Posting Komentar