I want to do this but not spend a lot of development time.
Is this possible with BCB?
Thanks
Eric
I have been involved in a very similar excercise and have found the
following useful:
1. A Delphi component (extract from ReadMe):
Component Name: TmThumbs
Author: Mats Asplund
Creation: 2002-01-25
Version: 1.0
Description: A component who produces jpeg-thumbnails.
Credit: Made from a Public Domain project by
Artchil Gogava, ArGo Software
E-mail: mas...@telia.com
Site: http://go.to/masdp
2. A nice standalone utility (extract from ReadMe):
Mihov Image Resizer 0.4
------------------------------------
Mihov Image Resizer is a handy tool
for resizing images in bmp, gif, and
jpg picture formats. It can also
convert images from and to bmp,
gif, and jpg.
Mihov Image Resizer is FREE.
----------------------------------
Miha Psenica, © 2000-2001
free...@mihov.com
http://www.mihov.com/eng/ir.html
http://www.mihov.com/update
Neither of the above does quite what I want so I am writing my own
using BCB5 (nowhere near complete yet as I keep side tracking) but I
did write a small test program to check out creation of thumbnails by:
a) Loading jpeg
b) converting to a bitmap (via Assign)
c) Using StretchDraw to draw this bitmap as a thumbnail on a the
canvas of a second bitmap
d) Saving the bitmap to file (not a jpeg in this test)
An important part I did not bother to include in the program (since it
was just a test) was setting Height/Width of the second bitmap (before
drawing on it) in order to preserve the aspect ratio.
Note that it is no good just saving the first bitmap created by step
(b) as this retains the original image size when saved to file.
The test program is basically as follows. Note the TImage controls
SourceImage and ThumbnailImage must have properties Autosize=false and
Stretch=true. Label1, 2 and 3 are just so I could easily check the
sizes of the graphics.
---------------------- main.h ---------------------------
class TMainForm : public TForm
{
__published: // IDE-managed Components
TGroupBox *ImageGroupBox;
TImage *SourceImage;
TGroupBox *SourceFileNameGroupBox;
TLabel *SourceFileLabel;
TOpenDialog *SourceFileOpenDialog;
TGroupBox *ThumbnailGroupBox;
TImage *ThumbnailImage;
TSaveDialog *ThumbnailSaveDialog;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
void __fastcall SourceFileLabelClick(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
};
---------------------- main.cpp -------------------------
void __fastcall TMainForm::SourceFileLabelClick(TObject *Sender)
{
if (SourceFileOpenDialog->Execute())
{
SourceFileLabel->Caption=SourceFileOpenDialog->FileName;
try
{
SourceImage->Picture->LoadFromFile(SourceFileOpenDialog->FileName);
}
catch ( Exception const& e )
{
Application->MessageBox(e.Message.c_str(),Application->Title.c_str(),0);
}
// Note need to adjust TImage Top, Left, Height, Width here to
// maintain aspect ratio and keep it centred in the parent control.
ThumbnailImage->Picture->Bitmap->Assign(SourceImage->Picture->Graphic);
Label1->Caption=AnsiString(ThumbnailImage->Left) +','
+AnsiString(ThumbnailImage->Width)+','
+AnsiString(ThumbnailImage->Top) +','
+AnsiString(ThumbnailImage->Height);
Label2->Caption=AnsiString(ThumbnailImage->Picture->Width)+','
+AnsiString(ThumbnailImage->Picture->Height);
Label3->Caption=AnsiString(ThumbnailImage->Picture->Bitmap->Width)+','
+AnsiString(ThumbnailImage->Picture->Bitmap->Height);
Graphics::TBitmap* p=new Graphics::TBitmap;
p->Height=ThumbnailImage->Height;
p->Width=ThumbnailImage->Width;
p->Canvas->StretchDraw(TRect(0,0,p->Width,p->Height),
ThumbnailImage->Picture->Bitmap);
if ( ThumbnailSaveDialog->Execute() )
p->SaveToFile(ThumbnailSaveDialog->FileName) ;
delete p ;
}
}
---------------------- form (as text) -------------------
object MainForm: TMainForm
Left = 200
Top = 107
Width = 577
Height = 566
Caption = 'Test creating thumbnail'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 384
Top = 232
Width = 32
Height = 13
Caption = 'Label1'
end
object Label2: TLabel
Left = 384
Top = 266
Width = 32
Height = 13
Caption = 'Label2'
end
object Label3: TLabel
Left = 384
Top = 299
Width = 32
Height = 13
Caption = 'Label3'
end
object ImageGroupBox: TGroupBox
Left = 8
Top = 8
Width = 353
Height = 473
Caption = 'Source Image'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 0
object SourceImage: TImage
Left = 12
Top = 17
Width = 329
Height = 449
Stretch = True
end
end
object ThumbnailGroupBox: TGroupBox
Left = 384
Top = 16
Width = 169
Height = 145
Caption = 'Thumbnail'
TabOrder = 1
object ThumbnailImage: TImage
Left = 8
Top = 16
Width = 153
Height = 121
Stretch = True
end
end
object SourceFileNameGroupBox: TGroupBox
Left = 8
Top = 488
Width = 353
Height = 41
Caption = 'Source File'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 2
object SourceFileLabel: TLabel
Left = 8
Top = 16
Width = 337
Height = 17
AutoSize = False
Layout = tlCenter
OnClick = SourceFileLabelClick
end
end
object SourceFileOpenDialog: TOpenDialog
Left = 392
Top = 176
end
object ThumbnailSaveDialog: TSaveDialog
DefaultExt = 'bmp'
Left = 456
Top = 176
end
end
Paul Witheridge - Marlow, UK
--
...
...
...This Post Has Been Tested and is Anthrax Free...
...
...
"Paul Witheridge" <paul.wi...@ntlworld.com> wrote in message
news:ne82kusm5q4qmerqm...@4ax.com...
TJPEGImage *JPeg1;
double H, W, NewWidth;
Graphics::TBitmap *Bitmap;
NewWidth = 300;
JPeg1 = new TJPEGImage();
JPeg1->LoadFromFile(Src);
H = JPeg1->Height;
W = JPeg1->Width;
Image1->AutoSize = false;
Image1->Stretch = true;
Image1->Width = NewWidth;
Image1->Height = H / (W / NewWidth);
Image1->Picture->Assign(JPeg1);
Bitmap = new Graphics::TBitmap;
Bitmap->Height = Image1->Height;
Bitmap->Width = Image1->Width;
Bitmap->Canvas->Draw(0,0,Image1->Picture->Bitmap);
Image2->AutoSize = true;
Image2->Visible = true;
Image2->Width = NewWidth;
Image2->Height = Image1->Height;
Image2->Picture->Assign(Bitmap);
delete Bitmap;
delete JPeg1;
bool __fastcall TForm1::ResizeJPG(AnsiString Src, AnsiString Dst, int
NewWidth)
{
TJPEGImage *JPeg1;
double H, W;
int NewHeight;
Graphics::TBitmap *Bitmap;
JPeg1 = new TJPEGImage();
JPeg1->LoadFromFile(Src);
H = JPeg1->Height;
W = JPeg1->Width;
NewHeight = H/(W/NewWidth);
Image1->AutoSize = false;
Image1->Stretch = true;
Image1->Width = NewWidth;
Image1->Height = NewHeight;
Image1->Picture->Assign(JPeg1);
Bitmap = new Graphics::TBitmap;
Bitmap->Height = Image1->Height;
Bitmap->Width = Image1->Width;
TRect rect = TRect(0,0,NewWidth, NewHeight);
Bitmap->Canvas->StretchDraw(rect,Image1->Picture->Graphic);
Image2->AutoSize = false;
Image2->Stretch = false;
Image2->Visible = true;
Image2->Width = NewWidth;
Image2->Height = NewHeight;
Image2->Canvas->Draw(0,0,Bitmap);
SaveBitMapAsJpeg(Image2->Picture->Bitmap, Dst);
delete Bitmap;
delete JPeg1;
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::SaveBitMapAsJpeg(Graphics::TBitmap *Bitmap,
AnsiString FileName)
{
TJPEGImage *jp = new TJPEGImage();
try
{
jp->Assign(Bitmap);
jp->SaveToFile(FileName);
}
__finally
{
delete jp;
}
}
//--------------------------------------------------------------------------
-