Is there any TXImage method for resizing JPG images

Is there any TXImage method for resizing JPG images

Postby sanilpmc » Sat Mar 05, 2016 6: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
sanilpmc
 
Posts: 36
Joined: Tue Jun 17, 2008 7:09 am

Re: Is there any TXImage method for resizing JPG images

Postby nageswaragunupudi » Sun Mar 06, 2016 1: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: Select all  Expand view
  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
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Is there any TXImage method for resizing JPG images

Postby sanilpmc » Mon Mar 07, 2016 4: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: Select all  Expand view
  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 ?
sanilpmc
 
Posts: 36
Joined: Tue Jun 17, 2008 7:09 am

Re: Is there any TXImage method for resizing JPG images

Postby nageswaragunupudi » Mon Mar 07, 2016 5: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
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Is there any TXImage method for resizing JPG images

Postby sanilpmc » Mon Mar 07, 2016 7: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
sanilpmc
 
Posts: 36
Joined: Tue Jun 17, 2008 7:09 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 78 guests