Resize

Resize

Post by Asko Korpe » Fri, 13 Oct 2006 04:50:29


How can I resize jpg fotos in D 2006?
In D7 I used CBImage, but it does not work any more.

--
Asko Korpela
http://www.yqcomputer.com/
+358(0)50 529 9539
 
 
 

Resize

Post by Charles Ha » Sat, 14 Oct 2006 07:36:51


You can copy your JPEG to a bitmap, resize the bitmap, then copy that
back
to your JPEG.

uses jpeg;

var Jpg : TJPEGImage;
Bmp : TBitmap;

procedure ResizeBMP(b : TBitmap; NewWidth, NewHeight : integer);
var
tbmp : TBitmap;
begin
// Not the best Bitmap resizer
// Got to EFG site and download a Bitmap 'resampler' code
// for better resized image
tbmp := TBitmap.Create;
tbmp.Width := b.Width;
tbmp.Height := b.Height;
BitBlt(tbmp.Canvas.Handle,0,0,tbmp.Width,tbmp.Height,
b.Canvas.Handle,0,0,SRCCOPY);
b.Width := NewWidth;
b.Height := NewHeight;
StretchBlt(b.Canvas.Handle,0,0,b.Width,b.Height,tbmp.Canvas.Handle,
0,0,tbmp.Width,tbmp.Height,SRCCOPY);
tbmp.Free;
end;

// Example code
begin
Jpg := TJPEGImage.Create;
Bmp := TBitmap.Create;
Jpg.LoadFromFile('FileName.jpg');
// Copy JPEG to bitmap:
Bmp.Width := Jpg.Width;
Bmp.Height := Jpg.Height;
Bmp.Canvas.Draw(0,0,Jpg);
// Resize Bitmap
ResizeBMP(Bmp,[newsizeW],[newsizeh]);
// Copy BMP back to JPG
Jpg.Assign(Bmp);
Jpg.SaveToFile('NewFileName.jpg');
Jpg.Free;
Bmp.Free;
end;


--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia

 
 
 

Resize

Post by Michael Ha » Sat, 14 Oct 2006 15:56:11


If you are looking for high quality (or fast low/medium quality) resampling
features, you could take a look at Graphics32 (www.graphics32.org).

Regards,

Michael Hansen
 
 
 

Resize

Post by Asko Korpe » Sun, 15 Oct 2006 05:22:26

Thank you again. I am almost 70, have been programming over 40 years. This
time happened something that almost never before has happended: the very
first trial after having written the code brought the correct result. But...
as you hinted, the quality is not good enough to be really used. According
to your advise I went to EFG, but could not find any code for bitmap
resampler. Have you got something specific in your mind?

--
Asko Korpela
http://www.yqcomputer.com/
+358(0)50 529 9539
"Charles Hacker" < XXXX@XXXXX.COM > kirjoitti
viestiss XXXX@XXXXX.COM ...
>>> >>> How can I resize jpg fotos in D 2006? >> >> >> You can copy your JPEG to a bitmap, resize the bitmap, then copy that >> back >> to your JPEG. >> >> uses jpeg; >> >> var Jpg : TJPEGImage; >> Bmp : TBitmap; >> >> procedure ResizeBMP(b : TBitmap; NewWidth, NewHeight : integer); >> var >> tbmp : TBitmap; >> begin >> // Not the best Bitmap resizer >> // Got to EFG site and download a Bitmap 'resampler' code >> // for better resized image >> tbmp := TBitmap.Create; >> tbmp.Width := b.Width; >> tbmp.Height := b.Height; >> BitBlt(tbmp.Canvas.Handle,0,0,tbmp.Width,tbmp.Height, >> b.Canvas.Handle,0,0,SRCCOPY); >> b.Width := NewWidth; >> b.Height := NewHeight; >> StretchBlt(b.Canvas.Handle,0,0,b.Width,b.Height,tbmp.Canvas.Handle, >> 0,0,tbmp.Width,tbmp.Height,SRCCOPY); >> tbmp.Free; >> end; >> >> // Example code >> begin >> Jpg := TJPEGImage.Create; >> Bmp := TBitmap.Create; >> Jpg.LoadFromFile('FileName.jpg'); >> // Copy JPEG to bitmap: >> Bmp.Width := Jpg.Width; >> Bmp.Height := Jpg.Height; >> Bmp.Canvas.Draw(0,0,Jpg); >> // Resize Bitmap >> ResizeBMP(Bmp,[newsizeW],[newsizeh]); >> // Copy BMP back to JPG >> Jpg.Assign(Bmp); >> Jpg.SaveToFile('NewFileName.jpg'); >> Jpg.Free; >> Bmp.Free; >> end; >> >> >> -- >> Charles Hacker >> Lecturer in Electronics and Computing >> School of Engineering >> Griffith University - Gold Coast >> Australia
 
 
 

Resize

Post by Asko Korpe » Sun, 15 Oct 2006 06:28:04

Thank you for your advise.
I got graphics 32-1-8-1 package, where there is some resampling methods, but
in no way could install the package according to the instructions.
Would there be something else?

--
Asko Korpela
http://www.yqcomputer.com/
+358(0)50 529 9539
"Michael Hansen" < XXXX@XXXXX.COM > kirjoitti
viestiss452f3886$ XXXX@XXXXX.COM ...
>>> How can I resize jpg fotos in D 2006? >>> In D7 I used CBImage, but it does not work any more. >> >> If you are looking for high quality (or fast low/medium quality) >> resampling features, you could take a look at Graphics32 >> (www.graphics32.org). >> >> Regards, >> >> Michael Hansen >>
 
 
 

Resize

Post by Charles Ha » Sun, 15 Oct 2006 16:38:36


Go to:
http://www.yqcomputer.com/

And do a search for:
Antialiasing , or
Resampling,


Note this page points to 'Anders Melander' resample Delphi code example:
Web page:
http://www.yqcomputer.com/
Actual example resampling code:
http://www.yqcomputer.com/

Note: I use the above resampler code in my image processing app of
http://www.yqcomputer.com/

--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia