Dippen
asked on
Cutting and saving piece of JPG-file...
Hi dear experts!
I have a JPEG-image stored on disk (MyPic.jpg). Its size is 400x300 pixels, and the color-depth is 24 bit.
Now I would like to cut out the region (100,100,199,199) and save it both as a BMP (MyBmp.bmp) and a JPG (MyJPG.JPG). Now, the thing is that I want the two new pictures to be only 50x50 pixels in size. How do I do this?
Actually, I've managed to do it, but when using CopyRect the colors get terribly degraded and I don't know why. Could someone please give me full source for this problem, including creating and destroying of all components needed in the transformation?
Thanks!
/Daniel, Sweden
I have a JPEG-image stored on disk (MyPic.jpg). Its size is 400x300 pixels, and the color-depth is 24 bit.
Now I would like to cut out the region (100,100,199,199) and save it both as a BMP (MyBmp.bmp) and a JPG (MyJPG.JPG). Now, the thing is that I want the two new pictures to be only 50x50 pixels in size. How do I do this?
Actually, I've managed to do it, but when using CopyRect the colors get terribly degraded and I don't know why. Could someone please give me full source for this problem, including creating and destroying of all components needed in the transformation?
Thanks!
/Daniel, Sweden
listeninig....
var bmpToLoad,bmpToSave:Tbitma p;
Jpg:TJpegimage;
begin
Jpg:=TJpegimage.Create;
BmpToLoad:=TBitmap.create;
BmpToSave:=Tbitmap.create;
With Jpg do
begin
PixelFormat:=jf24bit;
LoadFromFile('z:\Myjpg.jpg ');
end;
with bmpToLoad do
begin
PixelFormat:=pf24bit;
Assign(Jpg);
end;
With bmpToSave do
begin
height:=199;
Width:=100;
PixelFormat:=pf24bit;
Canvas.CopyRect(Canvas.Cli prect,bmpT oLoad.canv as,Canvas. Cliprect);
end;
Jpg.assign(BmpToSave);
Jpg.SaveToFile('z:\MynewJp g.jpg');
BmpToSave.SaveToFile('z:\m ynewBmp.bm p');
FreeAndNil(bmptoLoad);
FreeAndNil(bmptoSave);
FreeAndNil(Jpg);
Jpg:TJpegimage;
begin
Jpg:=TJpegimage.Create;
BmpToLoad:=TBitmap.create;
BmpToSave:=Tbitmap.create;
With Jpg do
begin
PixelFormat:=jf24bit;
LoadFromFile('z:\Myjpg.jpg
end;
with bmpToLoad do
begin
PixelFormat:=pf24bit;
Assign(Jpg);
end;
With bmpToSave do
begin
height:=199;
Width:=100;
PixelFormat:=pf24bit;
Canvas.CopyRect(Canvas.Cli
end;
Jpg.assign(BmpToSave);
Jpg.SaveToFile('z:\MynewJp
BmpToSave.SaveToFile('z:\m
FreeAndNil(bmptoLoad);
FreeAndNil(bmptoSave);
FreeAndNil(Jpg);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Listening...
ASKER
Great work Doc! Thx alot!
The secret seems to be never to use CopyRect to resize the portion of the picture, but let StretchDraw do that work instead.
Points well earned!
The secret seems to be never to use CopyRect to resize the portion of the picture, but let StretchDraw do that work instead.
Points well earned!
Cheers.