Solved

Thumbnail to Full Size

Posted on 2004-04-12
11
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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