Is there any TXImage method for resizing JPG images

Post Reply
sanilpmc
Posts: 36
Joined: Tue Jun 17, 2008 7:09 am

Is there any TXImage method for resizing JPG images

Post by sanilpmc »

Is there any TXImage method for resizing JPG image according to the pixel aspect ratio without losing image quality. I had an image with width 2821 pixel and height 2620 pixel and I need to resize it into 640*400 pixel

Regards
Sanil
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Is there any TXImage method for resizing JPG images

Post by nageswaragunupudi »

We can use method Zoom( nFactor ), but it is of no use because tximage does not provide any method to save the image.

If you want to resize a jpeg image and save it, you may try GdiBmp class instead. Here is a sample you may try:

Code: Select all | Expand

  oImage   := GdiBmp():New( "file1.jpg" )
   oImage:Resize( nWidth, nHeight )
   oImage:Save( "newfile.jpg", nQuality )
   oImage:End()
 


Please also note that you never need to resize any images if the purpose is only to display in any control of FWH
Regards

G. N. Rao.
Hyderabad, India
sanilpmc
Posts: 36
Joined: Tue Jun 17, 2008 7:09 am

Re: Is there any TXImage method for resizing JPG images

Post by sanilpmc »

nageswaragunupudi wrote:If you want to resize a jpeg image and save it, you may try GdiBmp class instead. Here is a sample you may try:

Code: Select all | Expand

  oImage   := GdiBmp():New( "file1.jpg" )
   oImage:Resize( nWidth, nHeight )
   oImage:Save( "newfile.jpg", nQuality )
   oImage:End()
 


Please also note that you never need to resize any images if the purpose is only to display in any control of FWH


Your Sample code is working fine. Thank you.

My purpose is not just for the display of image on FWH controls, I need to resize the image and then save to Database. The sample code provided by you serves the purpose.

Any built-in function available to resize the image preserving its aspect ratio ?
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: Is there any TXImage method for resizing JPG images

Post by nageswaragunupudi »

XImage's zoom method retains aspect ratio. Actually there is no way of resizing an image without retaining aspect ratio. But ximage is not for saving images. (Note: we will be providing save method in coming versions)

In the existing methods you can retain the aspect ratio by your calculating the new width and height retaining the aspect ratio.

Following functions/methods automatically resize retaining the aspect ratio.

ResizeBitmap( hBitmap, nWidth, nHeight ) --> hNewResizedBitmap

You provide either width or height and leave the other as nil. Result is a resized bitmap retaining the aspect ratio.

In the above example you can use oImg:Resize( nWidth ). The method calculates the height retaining the aspect ratio,
Note: oImg:Resize( nil, nHeight ) also should work similarly but there is a bug in the method.
Regards

G. N. Rao.
Hyderabad, India
sanilpmc
Posts: 36
Joined: Tue Jun 17, 2008 7:09 am

Re: Is there any TXImage method for resizing JPG images

Post by sanilpmc »

nageswaragunupudi wrote:
Following functions/methods automatically resize retaining the aspect ratio.

ResizeBitmap( hBitmap, nWidth, nHeight ) --> hNewResizedBitmap

You provide either width or height and leave the other as nil. Result is a resized bitmap retaining the aspect ratio.

In the above example you can use oImg:Resize( nWidth ). The method calculates the height retaining the aspect ratio,
Note: oImg:Resize( nil, nHeight ) also should work similarly but there is a bug in the method.



As far as the current situation the problem solved by this code, Thank you
Post Reply