[ BGrujic @ 19.12.2009. 14:04 ] @
Treba mi ideja kako u Delphiju da na formi prikazem sve male slike na jednoj formi poredjane jedna pored druge u vise redova. Broj slika nije unaprd odredjen i moze da se menja. Slike mogu da se nalaze u jednom folderu a moze i u bazi.
Pozdrav
[ lan-mi @ 19.12.2009. 20:43 ] @
http://jvcl.delphi-jedi.org/
U moru free komponenti postoji i ThumbView koja radi isto sto i bilo koji program za pregled slika. U paketu postoji i demo.
[ BGrujic @ 23.12.2009. 15:47 ] @
Ustvari treba mi ideja kako napraviti program za skolu da se na formi vide slike svih ucenika iz baze (razliciti broj za razlicita odeljenja). Klikom na sliku da se prikazu podaci o uceniku i ocene.
[ X Files @ 23.12.2009. 17:44 ] @
Recimo, mozes da postavis jedan TScrollBox na formu i u njemu dinamicki kreiras potreban broj TImage objekata koje punis slikama.

Dinamicko kreiranje mozes staviti u dvostrukoj petlji, da bi lakse mogao da izracunavas poziciju (kao u matrici) gde ces postaviti odgovarajuci TImage. Na istom mestu definises sve Evente koji ti trebaju. Ponekad se ovaj koncept moze modifikovati i sa TPaintBox koga takodje prethodno strpas u TScrollBox.

Evo jedan mali test kod na C++ Builderu. Princip je isti jer je VCL u pitanju

Code:

__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   DoubleBuffered = true;
   
   Invalidate();
   Repaint();

   for ( int i=0; i<=7; i++ )
      for ( int j=0; j<=7; j++ )
      {

         Image[i][j] = new TImage( ScrollBox1 );
         Image[i][j]->Parent = ScrollBox1;
         Image[i][j]->Width = 463;
         Image[i][j]->Height= 544;
         Image[i][j]->Left = i*463;
         Image[i][j]->Top  = j*544;
         Image[i][j]->Picture->LoadFromFile(ExtractFilePath( ParamStr(0) )+ "\\Z2\\" + IntToStr(j+1) + IntToStr(i+1) + ".jpg" );
         Image[i][j]->OnMouseDown = MyMouseDown;
         Image[i][j]->OnMouseMove = MyMouseMove;
         Image[i][j]->OnMouseUp   = MyMouseUp;
         // ... ostali dogadjaji
      }
}

[ bondja @ 28.12.2009. 13:40 ] @
Napomena: slike sam numerisao prema ID-ovima ljudi iz baze, sto je olaksalo rad.
Npr: ako korisnik ima id= 134, onda je ime njegove slike : 134.jpg

Postavi na formu komponente: TDrawGrid, TFileListBox i ubaci kod:

Code:

unit frmImages;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, Contnrs, StdCtrls, FileCtrl, ExtCtrls;

type
  TfrmImage = class(TForm)
    DrawGrid1: TDrawGrid;
    filesBox: TFileListBox;
  
    procedure FormCreate(Sender: TObject);
    procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure DrawGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private declarations }
    FImgList: TStringList;
    function LinearIndexOf(Row, Column: integer): integer;
  public
    { Public declarations }
  end;

implementation

{$R *.dfm}

uses Jpeg;

const
  cPicDir = 'Data\Pictures\';

procedure TfrmImage.FormCreate(Sender: TObject);
var
  i: integer;
  sPicFolder: string;
  sFN : string;
  jpg: TJPEGImage;
  bmp: TBitmap;
begin
  DrawGrid1.DefaultDrawing := false;
  filesBox.mask := '*.jpg'; // da ti izlista samo jpg fajlove


  sPicFolder := IncludeTrailingPathDelimiter
     ( IncludeTrailingPathDelimiter( ExtractFilePath( Application.ExeName)) + cPicDir);

  self.filesBox.Directory :=  sPicFolder;
  DrawGrid1.ColCount := 6;
  DrawGrid1.RowCount := 1 + (filesBox.Items.Count div  DrawGrid1.ColCount);


  FimgList := TStringList.Create;
  jpg := TJPEGImage.Create;
  for i:=0 to filesBox.Items.Count-1 do
  begin
    sFN := sPicFolder + filesBox.Items.Strings[i];

    if fileExists(sFN) then
    begin
      jpg.LoadFromFile(sFN);

      bmp := TBitmap.Create;
      bmp.Assign(jpg);

      // ime slike  + slika:
      FImgList.AddObject( filesBox.Items.Strings[i], bmp);
    end;
  end;

  FreeAndNil(jpg);
end;

function TfrmImage.LinearIndexOf (Row, Column : integer) : integer;
begin
  Result := DrawGrid1.ColCount * Row +  Column // Returns the index of the given cell
end;


procedure TfrmImage.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  index : integer;
  bmp: TBitmap;
begin
  // ovo iscrtava slike:
  index := LinearIndexOf(ARow, ACol);

  if (0<=index) and ( index < FImgList.Count) then
  begin
    bmp := TBitmap( FImgList.Objects[index]);
    try
      if assigned( bmp) then
        DrawGrid1.Canvas.StretchDraw(Rect, bmp);
    except

    end;
  end;
end;


procedure TfrmImage.DrawGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
var
  index: integer;
  IDValue: integer;
begin
  index := LinearIndexOf(ARow, ACol);

  if (0<=index) and ( index < FImgList.Count) then
  begin
    try
      IDValue := StrToInt(ChangeFileExt( FImgList.Strings[index], ''));

      // iscitas iz baze za dati ID podatke . .  .
    except

    end;
  end;
end;

end.