To save an image

User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

To save an image

Post by Enrico Maria Giordano »

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
User avatar
Antonio Linares
Site Admin
Posts: 42520
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 75 times
Contact:

Re: To save an image

Post by Antonio Linares »

Enrico,

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

Antonio Linares
www.fivetechsoft.com
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: To save an image

Post by mastintin »

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: Select all | Expand



local cImage := "image.bmp"
local
local oGdi := GDIBmp():new( cImage )
        oGdi:save( "imagenfinal.png")
       oGdi:end()
 
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: To save an image

Post by Enrico Maria Giordano »

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

EMG
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: To save an image

Post by Enrico Maria Giordano »

These are a couple of functions I wrote:

Code: Select all | Expand

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
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: To save an image

Post by mastintin »

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();

:D
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: To save an image

Post by Enrico Maria Giordano »

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

EMG
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: To save an image

Post by Enrico Maria Giordano »

[quote="Enrico Maria Giordano"

Code: Select all | Expand

    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: Select all | Expand

GDIP_DELETEIMAGE( hImg )


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

EMG
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: To save an image [Solved]

Post by mastintin »

Enrico Maria Giordano wrote:[quote="Enrico Maria Giordano"

Code: Select all | Expand

   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: Select all | Expand

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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: To save an image [Solved]

Post by Enrico Maria Giordano »

Thank you. Do you have any news for the quality of saved GIF?

Sample:

Code: Select all | Expand

#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
User avatar
mastintin
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: To save an image [Solved]

Post by mastintin »

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
Post Reply