Einzelnen Beitrag anzeigen

utd123

Registriert seit: 3. Nov 2011
Ort: Deutschland
29 Beiträge
 
Delphi 7 Personal
 
#14

AW: Prozentrechnung

  Alt 8. Nov 2011, 10:55
Hier gleich mal der gesamte Quelltext
ist aber noch nicht fertig ein paar farben Fehlen noch, wie z.B.gelb:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, ExtDlgs, jpeg, Menus, ComCtrls, MidasLib;

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    Image1: TImage;
    OpenPictureDialog1: TOpenPictureDialog;
    MainMenu1: TMainMenu;
    bildffnen1: TMenuItem;
    Memo1: TMemo;
    Memo2: TMemo;
    Memo3: TMemo;
    ProgressBar1: TProgressBar;
    Ende1: TMenuItem;
    procedure BitBtn1Click(Sender: TObject);
    procedure bildffnen1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Ende1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1:TForm1;
  y,u,v,b,r,g,maxu,maxv,minu,minv,z,maxz,minz:real;
  rot,blau,lila,gruen,schwarz,orange,grauweiss:integer;
  color:TColor;
  mein_jpeg: TJpegImage;
  mein_bmp: tBitmap;

implementation

{$R *.dfm}
procedure TForm1.bildffnen1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute
         then
          begin
           Image1.Picture.LoadFromFile(OpenPictureDialog1.filename);
          end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  x,y:Integer;

begin
ProgressBar1.position:=0;
for x:=0 to Image1.Picture.Bitmap.Width -1 do
  begin
  //Progress Bar
  ProgressBar1.Max := Image1.Picture.Bitmap.Width +1;
  ProgressBar1.Position := ProgressBar1.Position+1;
  //Progress Bar Ende
  for y:=0 to Image1.Picture.Bitmap.Height -1 do
    begin
    color :=Image1.Picture.Bitmap.Canvas.Pixels[x,y];
    b:=getbvalue(color);
    g:=getgvalue(color);
    r:=getrvalue(color);
    z:=(0.299*r)+(0.587*g)+(0.114*b);
    u:=(b-z)*0.493;
    v:=(r-z)*0.877;
    //Memo1.Lines.Add('r: ' + floattostr(r) + ' g: ' + floattostr(g) +' b: ' + floattostr(b));
    //Memo2.Lines.add(floattostr(z) + floattostr(u) + floattostr(u));
    //start Farbe verzweigungen
      if (z>0) and (z<121)then begin
         // y = 0 - 0.33
         if (u>-112) and (u<16) and (v<157) and (v>33.64)then
            rot:=rot+1
         else begin
                if (u<8) and (u>-64) and (v<33.64) and (v>11.21)then
                    rot:=rot+1
                else begin
                    if (u<112) and (u>16) and (v<157) and (v>100.92)then
                        lila:=lila+1
                    else begin
                          if (u<112) and (u>32) and (v<100.92) and (v>33.64)then
                              blau:=blau+1
                          else begin
                              if (u<112) and (u>8) and (v<33.64) and (v>-157)then
                                  blau:=blau+1
                              else begin
                                  if (u<8) and (u>-8) and (v<11.21) and (v>-157)then
                                      gruen:=gruen+1
                                  else begin
                                      if (u<-8) and (u>-112) and (v<0) and (v>-157)then
                                          gruen:=gruen+1
                                      else begin
                                          if (u<64) and (u>-112) and (v<33.64) and (v>0)then
                                              gruen:=gruen+1
                                          else begin
                                              if (u<-8) and (u>64) and (v<11.21) and (v>0)then
                                                  gruen:=gruen+1
                                              else begin
                                                  if (u<8) and (u>-8) and (v<11.21) and (v>-11.21)then
                                                      schwarz:=schwarz+1
                                              end;
                                          end;
                                      end;
                                  end;
                              end;
                          end;
                    end;
                end;
         end;
      end
      else begin
        if (z>120) and (z<171)then begin
            //y = 86 - 170
            if (u<-16) and (u>-112) and (v<112.14) and (v>22.42)then
                orange:=orange+1
            else begin
                if (u<16) and (u>-112) and (v<157) and (v>112.14)then
                    orange:=orange+1
                else begin
                    if (u<112) and (u>-16) and (v<157) and (v>11.21)then
                        lila:=lila+1
                    else begin
                        if (u<122) and (u>8) and (v<11.21) and (v>-11.21)then
                            blau:=blau+1
                        else begin
                            if (u<112) and (u>0) and (v<-11.21) and (v>-157)then
                                blau:=blau+1
                            else begin
                                if (u<0) and (u>-112) and (v<-11.21) and (v>-157)then
                                    gruen:=gruen+1
                                else begin
                                    if (u<-8) and (u>-112) and (v<11.21) and (v>-11.21)then
                                        gruen:=gruen+1
                                    else begin
                                        if (u<8) and (u>-8) and (v<11.21) and (v>-11.21)then
                                            grauweiss:=grauweiss+1;
                                    end;
                                end;
                            end;
                        end;
                    end;
                end;
            end;
        end
        else begin
            //y = 171 - 255

        end;
      end;

    //ende Farbe verzweigungen
  end;
  end;
    Memo3.Lines.Add('Rot:' + inttostr(rot));
    Memo3.Lines.add(FloatToStr(rot * 100 / (Image1.Picture.Width * Image1.Picture.Height)) + '%');
    Memo3.Lines.Add('Violett:' + inttostr(lila));
    Memo3.Lines.add(FloatToStr(lila * 100 / (Image1.Picture.Width * Image1.Picture.Height)) + '%');
    Memo3.Lines.Add('Blau:' + inttostr(blau));
    Memo3.Lines.add(FloatToStr(blau * 100 / (Image1.Picture.Width * Image1.Picture.Height)) + '%');
    Memo3.Lines.Add('Grün:' + inttostr(gruen));
    Memo3.Lines.add(FloatToStr(gruen * 100 / (Image1.Picture.Width * Image1.Picture.Height)) + '%');
    Memo3.Lines.Add('Schwarz:' + inttostr(schwarz));
    Memo3.Lines.add(FloatToStr(schwarz * 100 / (Image1.Picture.Width * Image1.Picture.Height)) + '%');
    Memo3.Lines.Add('Orange:' + inttostr(orange));
    Memo3.Lines.add(FloatToStr(orange * 100 / (Image1.Picture.Width * Image1.Picture.Height)) + '%');
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.lines.Delete(0);
Memo2.lines.Delete(0);
Memo3.lines.Delete(0);
end;

procedure TForm1.Ende1Click(Sender: TObject);
begin
close;
end;

end.
  Mit Zitat antworten Zitat