FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Is there any TXImage method for resizing JPG images
Posts: 36
Joined: Tue Jun 17, 2008 07:09 AM
Is there any TXImage method for resizing JPG images
Posted: Sat Mar 05, 2016 06:57 AM

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

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Is there any TXImage method for resizing JPG images
Posted: Sun Mar 06, 2016 01:46 PM
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 (fw): Select all Collapse
   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
Posts: 36
Joined: Tue Jun 17, 2008 07:09 AM
Re: Is there any TXImage method for resizing JPG images
Posted: Mon Mar 07, 2016 04:58 AM
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 (fw): Select all Collapse
   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 ?
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Is there any TXImage method for resizing JPG images
Posted: Mon Mar 07, 2016 05:17 AM

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
Posts: 36
Joined: Tue Jun 17, 2008 07:09 AM
Re: Is there any TXImage method for resizing JPG images
Posted: Mon Mar 07, 2016 07:33 AM
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

Continue the discussion