From: Saulo Rodrigues on
Hi everybody,

With FabPaint I can create a jpeg file through a resource bitmap,
however I'd like to make the inverse thing. Any help is welcome.

TIA,
Saulo

From: Sherlock on
Saulo

DIBSaveAsJPEG(ptrBitmap, String2Psz(cFName))

Phil McGuinness
------------------------


Saulo Rodrigues wrote:
> Hi everybody,
>
> With FabPaint I can create a jpeg file through a resource bitmap,
> however I'd like to make the inverse thing. Any help is welcome.
>
> TIA,
> Saulo

From: Saulo Rodrigues on
Thanks Phil

> DIBSaveAsJPEG(ptrBitmap, String2Psz(cFName))

In fact I need the inverse one, something like: JPEGSaveAsBMP(ptrJPEG,
String2Psz(cFName)). Anyway I think I will need an external DLL to do
that.

Regards
Saulo

From: John Martens on
Saulo,

Here's my function to save a picture file in another format.

John


FUNCTION PictureSaveAs(cFileNmOld AS STRING,cMode AS STRING) AS LOGIC
*
* function to save a file as DIB
* base from the code of FabPaint
* needs FabPaint Wrappers to use FabPaint.DLL instead of CaPaint.dll
LOCAL lFuncResult := FALSE AS LOGIC
LOCAL hf AS PTR
LOCAL dwSize AS DWORD
LOCAL pBmpBuffer AS PTR
LOCAL pDib AS PTR
LOCAL aKeuzeOpties := {} AS ARRAY
LOCAL dwKeuze AS DWORD
LOCAL cFileNmNew AS STRING
*
* see for the extension of the file
DO CASE
CASE ! File(cFileNmOld)
*
* file does not extist
ToonMelding('W','Bestand '+cFileNmOld+' bestaat niet.<.><.>Bestand kan
niet worden opgeslagen.',AlgShellWindow())
CASE Upper(LeesAlleenFileExt(cFileNmOld)) $
'|JPG|JPEG|TIF|TIFF|BMP|TGA|PNG|PCX|PCT|GIF|'
*
* get the pointer to the DIB
hf := FOpen(cFileNmOld)
IF hf = F_ERROR
*
* fileopen went wrong
ToonMelding('SU','Bestand '+cFileNmOld+' is niet te openen door
FOpen().<.><.>Bestand kan niet worden opgeslagen.',AlgShellWindow())
ELSE
dwSize := FSeek(hf, 0, FS_END)
FSeek(hf, 0, FS_SET)
pBmpBuffer := MemAlloc(dwSize)
DO CASE
CASE pBmpBuffer = NULL_PTR
*
* ptr not right
ToonMelding('SU','Bestand '+cFileNmOld+' geeft geen juiste
pointer.<.><.>Bestand kan niet worden opgeslagen.',AlgShellWindow())
CASE ! FRead3(hf, pBmpBuffer, dwSize) == dwSize
*
* filesize not right
ToonMelding('SU','Bestand '+cFileNmOld+' heeft niet de juiste
afmeting.<.><.>Afmeting kan niet worden opgehaald.',AlgShellWindow())
OTHERWISE
pDib := DIBCreateFromPTR(pBmpBuffer, dwSize)
IF Empty(pDib)
*
* DIB creation was wrong
ToonMelding('SU','Bestand '+cFileNmOld+' is niet te lezen door
DIBCreateFromPTR().<.><.>Bestand kan niet worden
opgeslagen.',AlgShellWindow())
ELSE
*
* kijken of soort op is gegeven
IF 'Format(' $ cMode

AAdd(aKeuzeOpties,{'',LeesLinksVan(LeesRechtsVan(cMode,'Format('),')')})
dwKeuze := 1
ELSE
AAdd(aKeuzeOpties,{'JPEG formaat','JPG'})
AAdd(aKeuzeOpties,{'PNG formaat','PNG'})
AAdd(aKeuzeOpties,{'TIFF formaat','TIFF'})
AAdd(aKeuzeOpties,{'DIB formaat','DIB'})
dwKeuze := LeesKeuze('Kies formaat','Kies het formaat waarin
'+cFileNmOld+' moet worden opgeslagen.',aKeuzeOpties,'',AlgShellWindow())
ENDIF
*
* nieuwe naam als basis opbouwen
cFileNmNew := cFileNmOld
DO WHILE '.' $ cFileNmNew .and. (! Right(cFileNmNew,1) == '.')
cFileNmNew := LeesLinksVan(cFileNmNew,1)
ENDDO
*
* save as
DO CASE
CASE 'JPG' == aKeuzeOpties[dwKeuze,2]
cFileNmNew += 'JPG'
FileDel(cFileNmNew)
DIBSaveAsJPEG(pDib,String2Psz(cFileNmNew))
CASE 'PNG' == aKeuzeOpties[dwKeuze,2]
cFileNmNew += 'PNG'
FileDel(cFileNmNew)
DIBSaveAsPNG(pDib,String2Psz(cFileNmNew))
CASE 'TIFF' == aKeuzeOpties[dwKeuze,2]
cFileNmNew += 'TIFF'
FileDel(cFileNmNew)
DIBSaveAsTIFF(pDib,String2Psz(cFileNmNew))
OTHERWISE
cFileNmNew += 'DIB'
FileDel(cFileNmNew)
DIBSaveAs(pDib,String2Psz(cFileNmNew))
ENDCASE
IF File(cFileNmNew)
lFuncResult := TRUE
ELSE
*
* fileinfo was not right
ToonMelding('W','Bestand '+cFileNmOld+' is niet op te slaan als
'+cFileNmNew+'.<.><.>Bestand kan niet worden opgeslagen.',AlgShellWindow())
ENDIF
*
* delete the pointer
DIBDelete(pDib)
ENDIF
ENDCASE
FClose(hf)
MemFree(pBmpBuffer)
*
* kijken naar openen
IF lFuncResult .and. 'OPEN' $ cMode
Wacht(1,TRUE)
FileOpen(cFileNmNew,'',{})
ENDIF
ENDIF
OTHERWISE
*
* unforseen
ToonMelding('W','De extensie van bestand '+cFileNmOld+' is niet
voorzien.<.><.>Bestand kan niet worden opgeslagen.',AlgShellWindow())
ENDCASE
RETURN lFuncResult


Saulo Rodrigues schreef:
> Thanks Phil
>
>> DIBSaveAsJPEG(ptrBitmap, String2Psz(cFName))
>
> In fact I need the inverse one, something like: JPEGSaveAsBMP(ptrJPEG,
> String2Psz(cFName)). Anyway I think I will need an external DLL to do
> that.
>
> Regards
> Saulo
>
From: Saulo Rodrigues on
John, thanks for share your code, but that is not what I am looking
for.
Please let me try to explain it better:

My real intention is do declare a resource entity:
For example:
RESOURCE MYJPG jpg c:\images\myjpg.jpg

And so, like FabPaintLib:CreateFromResourceName(...) does:
something like:
CreateFromResourceName( _GetInst(), "MYJPG" )
but this method only work for BMP's resources.

Thanks again and sorry about your time
Saulo

John Martens escreveu:

> Saulo,
>
> Here's my function to save a picture file in another format.
>
> John
>
>
> FUNCTION PictureSaveAs(cFileNmOld AS STRING,cMode AS STRING) AS LOGIC
> *
> * function to save a file as DIB
> * base from the code of FabPaint
> * needs FabPaint Wrappers to use FabPaint.DLL instead of CaPaint.dll
> LOCAL lFuncResult := FALSE AS LOGIC
> LOCAL hf AS PTR
> LOCAL dwSize AS DWORD
> LOCAL pBmpBuffer AS PTR
> LOCAL pDib AS PTR
> LOCAL aKeuzeOpties := {} AS ARRAY
> LOCAL dwKeuze AS DWORD
> LOCAL cFileNmNew AS STRING
> *
> * see for the extension of the file
> DO CASE
> CASE ! File(cFileNmOld)
> *
> * file does not extist
> ToonMelding('W','Bestand '+cFileNmOld+' bestaat niet.<.><.>Bestand kan
> niet worden opgeslagen.',AlgShellWindow())
> CASE Upper(LeesAlleenFileExt(cFileNmOld)) $
> '|JPG|JPEG|TIF|TIFF|BMP|TGA|PNG|PCX|PCT|GIF|'
> *
> * get the pointer to the DIB
> hf := FOpen(cFileNmOld)
> IF hf = F_ERROR
> *
> * fileopen went wrong
> ToonMelding('SU','Bestand '+cFileNmOld+' is niet te openen door
> FOpen().<.><.>Bestand kan niet worden opgeslagen.',AlgShellWindow())
> ELSE
> dwSize := FSeek(hf, 0, FS_END)
> FSeek(hf, 0, FS_SET)
> pBmpBuffer := MemAlloc(dwSize)
> DO CASE
> CASE pBmpBuffer = NULL_PTR
> *
> * ptr not right
> ToonMelding('SU','Bestand '+cFileNmOld+' geeft geen juiste
> pointer.<.><.>Bestand kan niet worden opgeslagen.',AlgShellWindow())
> CASE ! FRead3(hf, pBmpBuffer, dwSize) == dwSize
> *
> * filesize not right
> ToonMelding('SU','Bestand '+cFileNmOld+' heeft niet de juiste
> afmeting.<.><.>Afmeting kan niet worden opgehaald.',AlgShellWindow())
> OTHERWISE
> pDib := DIBCreateFromPTR(pBmpBuffer, dwSize)
> IF Empty(pDib)
> *
> * DIB creation was wrong
> ToonMelding('SU','Bestand '+cFileNmOld+' is niet te lezen door
> DIBCreateFromPTR().<.><.>Bestand kan niet worden
> opgeslagen.',AlgShellWindow())
> ELSE
> *
> * kijken of soort op is gegeven
> IF 'Format(' $ cMode
>
> AAdd(aKeuzeOpties,{'',LeesLinksVan(LeesRechtsVan(cMode,'Format('),')')})
> dwKeuze := 1
> ELSE
> AAdd(aKeuzeOpties,{'JPEG formaat','JPG'})
> AAdd(aKeuzeOpties,{'PNG formaat','PNG'})
> AAdd(aKeuzeOpties,{'TIFF formaat','TIFF'})
> AAdd(aKeuzeOpties,{'DIB formaat','DIB'})
> dwKeuze := LeesKeuze('Kies formaat','Kies het formaat waarin
> '+cFileNmOld+' moet worden opgeslagen.',aKeuzeOpties,'',AlgShellWindow())
> ENDIF
> *
> * nieuwe naam als basis opbouwen
> cFileNmNew := cFileNmOld
> DO WHILE '.' $ cFileNmNew .and. (! Right(cFileNmNew,1) == '.')
> cFileNmNew := LeesLinksVan(cFileNmNew,1)
> ENDDO
> *
> * save as
> DO CASE
> CASE 'JPG' == aKeuzeOpties[dwKeuze,2]
> cFileNmNew += 'JPG'
> FileDel(cFileNmNew)
> DIBSaveAsJPEG(pDib,String2Psz(cFileNmNew))
> CASE 'PNG' == aKeuzeOpties[dwKeuze,2]
> cFileNmNew += 'PNG'
> FileDel(cFileNmNew)
> DIBSaveAsPNG(pDib,String2Psz(cFileNmNew))
> CASE 'TIFF' == aKeuzeOpties[dwKeuze,2]
> cFileNmNew += 'TIFF'
> FileDel(cFileNmNew)
> DIBSaveAsTIFF(pDib,String2Psz(cFileNmNew))
> OTHERWISE
> cFileNmNew += 'DIB'
> FileDel(cFileNmNew)
> DIBSaveAs(pDib,String2Psz(cFileNmNew))
> ENDCASE
> IF File(cFileNmNew)
> lFuncResult := TRUE
> ELSE
> *
> * fileinfo was not right
> ToonMelding('W','Bestand '+cFileNmOld+' is niet op te slaan als
> '+cFileNmNew+'.<.><.>Bestand kan niet worden opgeslagen.',AlgShellWindow())
> ENDIF
> *
> * delete the pointer
> DIBDelete(pDib)
> ENDIF
> ENDCASE
> FClose(hf)
> MemFree(pBmpBuffer)
> *
> * kijken naar openen
> IF lFuncResult .and. 'OPEN' $ cMode
> Wacht(1,TRUE)
> FileOpen(cFileNmNew,'',{})
> ENDIF
> ENDIF
> OTHERWISE
> *
> * unforseen
> ToonMelding('W','De extensie van bestand '+cFileNmOld+' is niet
> voorzien.<.><.>Bestand kan niet worden opgeslagen.',AlgShellWindow())
> ENDCASE
> RETURN lFuncResult
>
>
> Saulo Rodrigues schreef:
> > Thanks Phil
> >
> >> DIBSaveAsJPEG(ptrBitmap, String2Psz(cFName))
> >
> > In fact I need the inverse one, something like: JPEGSaveAsBMP(ptrJPEG,
> > String2Psz(cFName)). Anyway I think I will need an external DLL to do
> > that.
> >
> > Regards
> > Saulo
> >

 |  Next  |  Last
Pages: 1 2 3 4
Prev: CRC32
Next: CAVORT20.DLL and 2.7