FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour To save an image
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
To save an image
Posted: Thu Oct 22, 2015 12:59 PM

As I understood,

GDIP_IMAGEFROMFILE( cFile, .T. )

can now be used to load an image without FREEIMAGE.DLL. Is there something similar to SAVE an image?

EMG

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: To save an image
Posted: Thu Oct 22, 2015 04:07 PM

Enrico,

Manuel (Mastintin) is our GDI master. Lets see what he can tell us.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: To save an image
Posted: Thu Oct 22, 2015 04:56 PM
GDIP_IMAGEFROMFILE( cFile, .T. ) return classic hbitmap

Seria posible no usar freeimage.dll en la mayoria de los formatos imagenes comunes .
Funciona correcto con jpg, gif,tif,png, bmp , ico
Mas facil es unsar la clase creada a tal efecto y que se encuentra en c:\fwh\sources\tgdiplus.prg ...
Para grabar una imagen seria lago asi ...

Code (fw): Select all Collapse
local cImage := "image.bmp"
local 
local oGdi := GDIBmp():new( cImage ) 
        oGdi:save( "imagenfinal.png")
       oGdi:end()
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: To save an image
Posted: Thu Oct 22, 2015 05:16 PM

Thank you. I'm going to experiment with it.

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: To save an image
Posted: Thu Oct 22, 2015 08:28 PM

Ok, it's working, thank you.

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: To save an image
Posted: Fri Oct 23, 2015 11:06 AM
These are a couple of functions I wrote:

Code (fw): Select all Collapse
REQUEST GDIBMP


FUNCTION LOADIMG( cFile )

    IF !FILE( cFile )
        RETURN 0
    ENDIF

    RETURN GDIP_IMAGEFROMFILE( cFile, .T. )


FUNCTION SAVEIMG( cSrcFile, cDstFile )

    LOCAL aExt := { "BMP", "JPG", "GIF", "TIF", "PNG" }

    LOCAL aIds := { "{557CF400-1A04-11D3-9A73-0000F81EF32E}",;
                    "{557CF401-1A04-11D3-9A73-0000F81EF32E}",;
                    "{557CF402-1A04-11D3-9A73-0000F81EF32E}",;
                    "{557CF405-1A04-11D3-9A73-0000F81EF32E}",;
                    "{557CF406-1A04-11D3-9A73-0000F81EF32E}",;
                    "{557CF403-1A04-11D3-9A73-0000F81EF32E}",;
                    "{557CF404-1A04-11D3-9A73-0000F81EF32E}",;
                    "{557CF407-1A04-11D3-9A73-0000F81EF32E}" }

    LOCAL cExt := CFILEEXT( cDstFile )

    LOCAL nExt := ASCAN( aExt, cExt )

    LOCAL cId := aIds[ nExt ]

    LOCAL hImg := GDIPLUSIMAGELOADCACHEDFILE( cSrcFile )

    IF hImg = 0 THEN RETURN .F.

    GDIPLUSIMAGESAVE( hImg, ANSITOWIDE( cDstFile ), ANSITOWIDE( cId ) )

    DELETEOBJECT( hImg )

    RETURN .T.


EMG
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: To save an image
Posted: Fri Oct 23, 2015 12:57 PM
Enrico Maria Giordano wrote:These are a couple of functions I wrote:

[code=fw]

GDIPLUSIMAGESAVE( hImg, ANSITOWIDE( cDstFile ), ANSITOWIDE( cId ) )


EMG


Enrico, GDIPLUSIMAGESAVE function transform asitowide in your code ... is not necessary ansitowide functions

std::string str = hb_parc(2) ;
std::wstring wstr (str.begin(), str.end());
LPWSTR file = (LPWSTR) wstr.c_str();

:-)
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: To save an image
Posted: Fri Oct 23, 2015 01:00 PM

I've already tried: it doesn't work without ANSITOWIDE().

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: To save an image
Posted: Sat Nov 07, 2015 01:38 PM
[quote="Enrico Maria Giordano"
Code (fw): Select all Collapse
    LOCAL hImg := GDIPLUSIMAGELOADCACHEDFILE( cSrcFile )

    IF hImg = 0 THEN RETURN .F.

    GDIPLUSIMAGESAVE( hImg, ANSITOWIDE( cDstFile ), ANSITOWIDE( cId ) )

    DELETEOBJECT( hImg )[/quote]


Do I have to use

Code (fw): Select all Collapse
GDIP_DELETEIMAGE( hImg )


instead to release the image, right? Can you confirm this?

EMG
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: To save an image [Solved]
Posted: Sat Nov 07, 2015 02:28 PM
Enrico Maria Giordano wrote:[quote="Enrico Maria Giordano"
Code (fw): Select all Collapse
    LOCAL hImg := GDIPLUSIMAGELOADCACHEDFILE( cSrcFile )

    IF hImg = 0 THEN RETURN .F.

    GDIPLUSIMAGESAVE( hImg, ANSITOWIDE( cDstFile ), ANSITOWIDE( cId ) )

    DELETEOBJECT( hImg )[/quote]


Do I have to use

Code (fw): Select all Collapse
GDIP_DELETEIMAGE( hImg )


instead to release the image, right? Can you confirm this?

EMG

Yes. Enrico use
GDIP_DELETEIMAGE( hImg ) // release pointer to gdi+ image object
instead
DELETEOBJECT( hImg ) // release pointer to "classic" image object
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: To save an image [Solved]
Posted: Sat Nov 07, 2015 02:32 PM
Thank you. Do you have any news for the quality of saved GIF?

Sample:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL cSrcImage := "c:\fwh\bitmaps\magic.bmp"
    LOCAL cDstImage := "magic.gif"

    LOCAL oGdi := GDIBmp():New( cSrcImage )

    oGdi:Save( cDstImage )

    oGdi:End()

    RETURN NIL


EMG
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: To save an image [Solved]
Posted: Sat Nov 07, 2015 02:45 PM

Enrico . No more news.
to solve the problem, we first have to develop code for octree algorithm and my c ++ does not go that far. I have c ++ code that is done but do not get removed compile errors.
However, the GIF format is licensed for use and is overwhelmed by png or tif.
If anyone is encouraged... your code is this ....

https://www.dropbox.com/s/3syub4enpg5lx ... r.cpp?dl=0
Cheers

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: To save an image [Solved]
Posted: Sat Nov 07, 2015 02:54 PM

Do you have QColorQuantizer.h?

EMG

Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: To save an image [Solved]
Posted: Sat Nov 07, 2015 04:31 PM
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: To save an image [Solved]
Posted: Sat Nov 07, 2015 04:35 PM

Error 404 (Page not found). :-(

EMG