FWH 18.03: FW_SaveImage()

FWH 18.03: FW_SaveImage()

Postby nageswaragunupudi » Tue Apr 24, 2018 1:26 pm

New functions in FWH 18.03

FW_SaveHBitmap( hBitmap, cBmpFile ) --> lSuccess
FW_SaveHIContoIco( hIcon, cIconFile ) --> lSuccess


The above two functions are self explanatory.

FW_SaveImage( [uSource], [cFile], [lJpgQuality] ) --> lSuccess


Parameters:
1. uSource (optional):

(a) If empty, image in clipboard, if any, is taken as the source.
(b) hBitmap
(c) hIcon: (i) If the destination file has extension "ico", the image is saved using function FW_SaveHIcontoIco(). (ii) Otherwise, hIcon is converted to hBitmap for saving in other formats
(d) pImage (gdi+ image pointer)
(e) URL pointing to any image on the Web.
(f) Resource name of any image
(g) Image file on disk:
By default, files with extensions bmp,jpg,jpeg,tif,tiff,gif,png are supported.
If freeimage.dll is available, any file type supported by the dll are accepted.

In other cases, the function returns failure.

2. cFile (optional):

If omitted, a file selector dialog is displayed and the user has to select a file name with any supported extension.

Supported filetypes, by default, are bmp,jpg,jpeg,tif,tiff,gif,png.
If freeimage.dll is available, any file type supported by the dll can be selected.

3. nJpegQuality (optional) Used only for jpg/jpeg files
Range 0 (maximum compression) to 100 (no compression). Default 10

Note: If both source file and destination file have the same extension, the source file is simply copied to the destination.

Saving contents of Window/Dialog/Controls:
New method SaveAsImage( cFile, [aRect] ) can be used. By default, the entire client area is saved.

XImage:
oImage:Save( cFile, .t. ): Saves whatever is viewed in the image control.
oImage:Save( cFile, .f. ): Saves original image without any transformations.

FW_TransformBitmap( hBitmap, [aCrop], [nZoom], [nRotate] ) --> modified bitmap
Parameters are self explanatory.
Example usage:
Code: Select all  Expand view  RUN

hBmp := FW_ReadImage( nil, "\fwh\bitmaps\olga1.jpg" )[ 1 ]
hNew := FW_TransormBitmap( hBmp, { 0.2, 0.2, -0.2, -0.2 }, 0.75, 45 )
FW_SaveImage( hNew, "olganew.png" )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FWH 18.03: FW_SaveImage()

Postby AntoninoP » Tue Apr 24, 2018 2:09 pm

nageswaragunupudi wrote:FW_TransformBitmap( hBitmap, [aCrop], [nZoom], [nRotate] ) --> modified bitmap
Parameters are self explanatory.


not so much.. aCrop are {top,left,height,width} or {left,top,right,bottom} or ....
what they mean, in the example there are a -0.2?!?! :shock:

nZoom is percentual normalized? not from 0 to 100 but from 0 to 1?

nRotate is degree or radiant, clockwise or anticlockwise?

Never "Parameters are self explanatory" :x


nageswaragunupudi wrote:3. nJpegQuality (optional) Used only for jpg/jpeg files
Range 0 (maximum compression) to 100 (no compression). Default 10


default 10?!? is not too little? usually for jpeg 80 is used... :)

nageswaragunupudi wrote:Note: If both source file and destination file have the same extension, the source file is simply copied to the destination.


so it is not possible reduce jpeg quality without some work around... :twisted:

excuse me for being so bad :oops:
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: FWH 18.03: FW_SaveImage()

Postby nageswaragunupudi » Tue Apr 24, 2018 2:51 pm

Ok. Let us attempt to describe.

nRotate: Degrees. Positive values for anti-clockwise and negative values for clockwise rotation. (Same in XImage also).

nZoom: 1.0 is same size. Less than 1.0 is reduction (unZoom). 0.75 means 75% of the size. Values greater than 1.0 means zoom (enlargement). 2.5 means 250% of the size. (Same as in TBitmap, TImage and TXImage)

aCrop is a rectangle { nTop, nLeft, nBottom, nRight }
The rectangle can be absolute or relative to the size of the image.

nTop and nLeft: If NIL, default to the top and left of image rect.
Values >= 1 indicate absolute pixels
Values > 0 and < 1 indicate percentage of height and width

0.25 means 25% of height/width as applicable.

nBottom and nRight:
NIL default to bottom and right of the image rect.
Negavive values indicate offset from bottom / right.

Some examples of Usage:
If we want to cut 25 pixels all around the image then we can use
{ 25, 25, -25, -25 }. We need not know in advance the actual size of the image.

If we want top-left quarter of the image:
{ nil, nil, 0.5, 0.5 }

The same notation is followed in FW_SayText() and FW_DrawImage(). This allows retaining the position when windows are resized and avoids the need for doing calculations by the programmer everytime.

In any case, if the programmer so chooses he can specify the absolute pixel values like { 30, 50, 200, 300 }.

Jpeg quality: It is better for the user to specify the quality of his preference.

so it is not possible reduce jpeg quality without some work around

Your point is well-taken. Right now we need to adopt work around
FW_Save( FW_ReadImage( nil, "in.jpg" )[ 1 ], "out.jpg", 80 )

We welcome your comments and feedback.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 50 guests