Solved

Thumbnail to Full Size

Posted on 2004-04-12
11
522 Views
Last Modified: 2010-04-05
I have a picture database. I wish to reduce the picture's to show as a thubmnail on a form and by clicking on that thumbnail create a full size picture.
0
Comment
Question by:johnshailes
  • 7
  • 2
  • 2
11 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10806978
If images are bmp and equal in size You can do it easy.
Place Image1 on a form and set

Image1.Stretch := True;
// loading from database to thumbnail

var
  MS: TMemoryStream;
begin
  MS := TMemoryStream.Create;
  try
    SQLDataSet1Images.SaveToStream(MS);
    Image1.Picture.Bitmap.LoadFromStream(MS);
  finally
    MS.Free;
  end;
end;

// switching from thumbnail to full and vice versa
procedure TForm1.Image1Click(Sender: TObject);
begin
  if Image1.Stretch then
    begin
    Image1.Stretch := False;
    Image1.AutoSize := True;
    end
  else
    begin
    Image1.Stretch := True;
    Image1.AutoSize := False;
    Image1.Width := 100;
    Image1.Height := 100;
    end
end;
      
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10807016
For a thubmnail you will use TImage components with equal height. The witdh of every picture will be calculated to save true proportion of the image. It is easy to develop OnClick event to show the picture by another form in true size....
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10807182
For thubmnail:

procedure ResizeImage(Image: TImage; DHeight:  Double);
var
  H:      Integer;
  W:      Integer;
  D:      Double;
begin
  D := 1;
  H := Image.Picture.Bitmap.Height;
  W := Image.Picture.Bitmap.Width;
  if (H<>DHeight) then
  try
    begin
      Image.Stretch := True;
      D := DHeight/H
    end;
  finally
    Image.Height := Round(D*H);
    Image.Width := Round(D*W);
  end;
end;
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 12

Expert Comment

by:esoftbg
ID: 10810921
download from        http://www.geocities.com/esoftbg/
                 file        Q_20951029.zip
it is a simple example.
0
 

Author Comment

by:johnshailes
ID: 10815970
esoftbg

Your sample is great. But how would i load a file from a .db file, because in my database the photo's relate to an index which in turn relate to a drawing number and operation number criteria.

john.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10816222
Hi
Why do You ignore my post. You've got there how to load image from database.
0
 

Author Comment

by:johnshailes
ID: 10816477
mokule

I appologise, I missed the SQLDataSet i was to engrosed in the example from esoftbg. I have been useing a TDBimage on my form so it made it easy to show BitMap. I will try all example's.

john.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10816877
johnshailes,
In my example I have declared  a static array:
    Image:  array [FrstImg..LastImg] of TeImage;
I think it would be in your case used a dynamic array:
    Image:  array of TeImage;
Then:
//......................................
  N := 0;
  SetLength(Image, DataSet.RecordCount); // Set the size of the array
  while not DataSet.EOF do
  begin
    Image[N] := TeImage.Create(Self);
    Image[N].Parent := ScrollBox;
    Image[N].Left := // Calculate Left position of every Image;
    Image[N].Top := // Calculate Top position of every Image;
    Image[N].Picture.Bitmap.Assign(DBImage.Picture.Bitmap);
    I := ThumbnailImage(Image[N], ThumbH);
    Inc(N);
  end;

It is just an idea....
emil
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10816904
I forgot some important things:

  N := 0;
  SetLength(Image, DataSet.RecordCount); // Set the size of the array
  DataSet.First;
  while not DataSet.EOF do
  begin
    Image[N] := TeImage.Create(Self);
    Image[N].Parent := ScrollBox;
    Image[N].Left := // Calculate Left position of every Image;
    Image[N].Top := // Calculate Top position of every Image;
    Image[N].Picture.Bitmap.Assign(DBImage.Picture.Bitmap);
    I := ThumbnailImage(Image[N], ThumbH);
    Inc(N);
    DataSet.Next;
  end;
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 250 total points
ID: 10821292
download a new DataBase example from       http://www.geocities.com/esoftbg/ee/Q_20951029.zip
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10827590
This is not a new answer about this question. This is accepted code from the Author of the question. Let it be here, if my site would be destroyed for any reason.

program Q_20951029;

uses
  Forms,
  Unit_Q_20951029 in 'Unit_Q_20951029.pas' {FormThumbnails},
  Unit2_Q_20951029 in 'Unit2_Q_20951029.pas' {FormTrueSize},
  Unit3_Q_20951029 in 'Unit3_Q_20951029.pas' {FormPic};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TFormThumbnails, FormThumbnails);
  Application.CreateForm(TFormTrueSize, FormTrueSize);
  Application.CreateForm(TFormPic, FormPic);
  Application.Run;
end.

//..............................

unit Unit_Q_20951029;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, JPEG, DB, DBTables, Grids, DBGrids, ExtDlgs, Buttons,
  ToolWin, ComCtrls, Clipbrd;

const
  Gap = 16;
  ThumbH  = 64;
type
  TeImage = class(TImage)
    private    { Private declarations }
    protected  { Protected declarations }
      procedure  MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    public     { Public declarations }
     constructor Create(AOwner: TComponent); override;
     destructor  Destroy; override;
    published  { Published declarations }
  end;

  TFormThumbnails = class(TForm)
    ScrollBox: TScrollBox;
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private  { Private declarations }
  public   { Public declarations }
    Image:  array of TeImage;
  end;

var
  FormThumbnails: TFormThumbnails;

implementation

{$R *.dfm}

uses
  Unit2_Q_20951029, Unit3_Q_20951029;

function  ThumbnailImage(Image: TeImage; DHeight:  Double): Integer;
var
  H:      Integer;
  W:      Integer;
  D:      Double;
begin
  try
    D := 1;
    H := Image.Picture.Bitmap.Height;
    W := Image.Picture.Bitmap.Width;
    if (H<>DHeight) then
    try
      begin
        Image.Stretch := True;
        D := DHeight/H
      end;
    finally
      Image.Height := Round(D*H);
      Image.Width := Round(D*W);
    end;
  finally
    Result := Image.Left + Image.Width;
  end;
end;

constructor TeImage.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

procedure TeImage.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  with FormTrueSize do
  begin
    Image.Picture.Bitmap.Assign(Picture.Bitmap);
    Height := Image.Picture.Bitmap.Height+40;
    Width := Image.Picture.Bitmap.Width+16;
    ShowModal;
  end;
end;

destructor  TeImage.Destroy;
begin
  inherited Destroy;
end;

procedure TFormThumbnails.SpeedButton1Click(Sender: TObject);
var
  RP:     Word;
  N:      Word;
  LP:     Word;
  TP:     Word;
begin
  RP := 0;
  LP := Gap;
  TP := Gap;
  try
    N := 0;
    SetLength(Image, FormPic.TablePic.RecordCount);
    FormPic.TablePic.First;
    while not FormPic.TablePic.EOF do
    begin
      Image[N] := TeImage.Create(Self);
      if (N=0) then
      begin
        Image[N].Left := LP;
        Image[N].Top := TP;
      end;
      Image[N].Parent := ScrollBox;
      Image[N].Picture.Assign(FormPic.DBImage.Picture);
      if (RP>ScrollBox.Width) then
      begin
        TP := TP + ThumbH + Gap;
        RP := 0;
      end;
      Image[N].Left := RP + LP;
      Image[N].Top := TP;
      RP := ThumbnailImage(Image[N], ThumbH);
      Inc(N);
      FormPic.TablePic.Next;
    end;
  except
  end;
end;

procedure TFormThumbnails.SpeedButton2Click(Sender: TObject);
begin
  FormPic.ShowModal;
end;

end.

//...........................

unit Unit2_Q_20951029;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TFormTrueSize = class(TForm)
    Scroll_Box: TScrollBox;
    Image: TImage;
  private  { Private declarations }
  public   { Public declarations }
  end;

var
  FormTrueSize: TFormTrueSize;

implementation

{$R *.dfm}

end.

//........................

unit Unit3_Q_20951029;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, ExtDlgs, DB, DBTables, Buttons, ExtCtrls,
  JPEG, DBCtrls;

type
  TFormPic = class(TForm)
    DataSourcePic: TDataSource;
    OpenPictureDialog: TOpenPictureDialog;
    DBGridPic: TDBGrid;
    SpeedButton1: TSpeedButton;
    Image1: TImage;
    TablePic: TTable;
    SpeedButton2: TSpeedButton;
    DBImage: TDBImage;
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private  { Private declarations }
  public   { Public declarations }
  end;

var
  FormPic: TFormPic;

implementation

{$R *.dfm}

procedure TFormPic.SpeedButton1Click(Sender: TObject);
begin
  if OpenPictureDialog.Execute then
  begin
    Image1.Picture.LoadFromFile(OpenPictureDialog.FileName);
    TablePic.Append;
    TablePic.FieldByName('PIC').Assign(Image1.Picture.Bitmap);
    TablePic.Post;
  end;
end;

procedure TFormPic.FormCreate(Sender: TObject);
begin
  TablePic.Active := False;
  TablePic.Active := True;
end;

procedure TFormPic.SpeedButton2Click(Sender: TObject);
begin
  if OpenPictureDialog.Execute then
  begin
    Image1.Picture.LoadFromFile(OpenPictureDialog.FileName);
    TablePic.Edit;
    TablePic.FieldByName('PIC').Assign(Image1.Picture.Bitmap);
    TablePic.Post;
  end;
end;

end.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question