[futurebasic] Re: [FB] Folder exists

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2003 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Thu, 22 May 2003 04:04:50 +0200

Robert Covington wrote:
> 
> On Wednesday, May 21, 2003, at 05:27  PM, Alain Pastor wrote:
> 
>>
>>
>> Craig Hoyt wrote:
>>
>>> Michael, thank you for the reply to my question. I've been away from my
>>> computer for several days and haven't had a chance to test your 
>>> routine. It
>>> looks like what I need.
>>> As long as I'm sending this... I have another question for the List. 
>>> I need
>>> to save an image as a JPEG file. I've looked around to see what FB has to
>>> offer and also in the QT toolbox routines but can't find a match for my
>>> situation. The image is in memory (a PICT handle) and I need to save it
>>> without user intervention (no SaveAs dialog). Does anybody know how to do
>>> this?
>>
>>
>> Craig,
>>
>> Why don't you save your PICT in a file first and use USR 
>> ConvertImageFile right after?
>>
>> Alain
> 
> 
> That's easy enough, but not as flexible as the below (if this works, I 
> adapted it from my GWorld sourced same)
> 
> You will need :
> 

Here is the function slightly reworked to make it in local mode and 
with the correct Toolbox missing declaration, as a bonus I have 
created a handy Toolbox alias, I tried it and that worked beautifully 
(caution with linebreaks):


#Define GraphicsExportComponent As ComponentInstance
#If carbonlib
Library "Apple;Carbon;Multimedia"
#Else
Library "QuickTimeLib"
#Endif
Toolbox fn GraphicsExportSetDepth( GraphicsExportComponent ci,¬
  long depth) = ComponentResult `0x2F3C, 0x0004, 0x001D, 0x7000, 0xA82A
Library

Clear Local Mode
Local Fn SavePICTasJPEGFiIe( PictH As handle,¬
                        fileSpec As ^FSSpec,¬
                          format As OSType, ¬
                        theDepth As Short,  ¬
                            xDpi As Long,   ¬
                            yDpi As Long,   ¬
                          fCrtr  As OSType)
Dim @ vers As long
Dim @ ge   As GraphicsExportComponent
Dim   err  As ComponentResult

err = Fn OpenADefaultComponent( _"grex",_"JPEG", @ge )
If err Then Exit "BAIL JPEG"
err = Fn GraphicsExportSetInputPicture( ge, PictH )
If err Then Exit "BAIL JPEG"
err = Fn GraphicsExportSetDepth(ge,theDepth )
If err Then Exit "BAIL JPEG"
err = Fn GraphicsExportSetOutputFile( ge, #fileSpec )
If err Then Exit "BAIL JPEG"
If Fn Gestalt(_"qtim", @vers) Then vers = 0
Long If (vers >> 16) > 0x399
err = Fn GraphicsExportSetResolution (ge,¬
                           Fn Long2Fix(xDpi), ¬
                           Fn Long2Fix(yDpi) )
If err Then Exit "BAIL JPEG"
err = Fn GraphicsExportSetCompressionQuality(ge,_codecNormalQuality)
If err Then Exit "BAIL JPEG"
err = Fn GraphicsExportSetOutputFileTypeAndCreator(ge,format,fCrtr)
If err Then Exit "BAIL JPEG"
End If
err = Fn GraphicsExportDoExport( ge, #_nil )
"BAIL JPEG"
vers = Fn CloseComponent (ge)

End Fn = err

// CALL WITH your FSSpec and PictHandle and hRes  and vRes (72 or 
whatever)
Dim err
Dim @ pictH As Handle
Dim fSpec   As FSSpec
Dim r       As Rect
Window 1
SetRect( r, 10,10,100,100)
Picture On
Color _zRed : PaintOval(r)
Picture Off, pictH
Long If pictH
Long If Len(Files$(_FSSpecSave,"test JPEG","Picasso",fSpec))
err = Fn SavePICTasJPEGFiIe(PictH,fSpec, _"JPEG",32,72,72, _"GKON")
End If
End If
include Ssubs Quick Event Loop.Incl"

Put that in the QT library and try:
TBAlias GraphicsExportSetOutputFileTypeAndCreator, 
GraphicExportWouldYouPleaseSetTheFileTypeAndTheCreatorCodeWhileYourAtItOfTheFileYouCanProbablyFindInThatComponentJustBehindTheParenthesisThanks

Alain