[futurebasic] Re: [FB] JPEG pcture renamer

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2001 : Group Archive : Group : All Groups

From: Chris Stasny <staz@...>
Date: Wed, 13 Jun 2001 10:42:26 -0500
Martin,

Let me begin by suggesting that you never load the image files into 
memory. You can view them without ever setting up a handle and 
without every bringing the whole thing into memory. One of our disk 
examples shows how:

File name: "Cheap Image File display"


// Bare bones image file opener: Open any image type
// Requires FBII runtime.

include "Subs Image Files.Incl"

dim theRect as rect
dim fName$,vRef%

fName$ = files$(_fOpenPreview,"qtif",,vRef%)
long if fName$[0]
DEF GETIMAGEFILERECT(fName$,vRef%,theRect)
Window 1,fName$,@theRect,_docNoGrow
DEF DRAWIMAGEFILE(fName$,vRef%)
end if

do
until fn button


There is also an example on the CD that scans the folder and displays 
the images in slide show fashion, so you can pick up the necessary 
"scanning" routines from  the project in a folder called "Slide Show 
Folder"

Good luck.

>Following a recent thread prompted me to use some code to create a
>utlity to rename
>those pesky Sony Mavica JPEG files that you are left with after taking a
>disk
>full of pictures for class use. If you want to help put 3 or 4 JPEG
>files in a folder
>with this code. The basic idea is to view the files and rename them
>something more
>descriptive than the Mavicafile number.
>
>The following code works but with a few problems
>
>1. Where to dispose of the picture handle? At the moment it just keeps
>grabbing memory
>2. A window refresh problem for the first picture
>3. A more clever way of scanning the folder for valid files
>
>=======================================================
>index2=0:forever = 0:index = 1
>fend = 0:in = 0:start = 0
>DIM AS INT @ gvRef
>DIM pictH AS ^^Picture
>
>Dim fnames$(100)
>
>end globals
>
>INCLUDE "Subs Image Files.Incl"
>'~'7
>CLEAR LOCAL MODE
>'~'8
>LOCAL FN ScalePictureRect (pictH AS HANDLE, r AS ^RECT)
>'~'9
>DIM pictInfo AS PictInfo
>
>LONG IF SYSTEM(_Maxcolors) > 1 AND SYSTEM(_Sysvers) >= 700
>LONG IF FN
>GetPictInfo(pictH,pictInfo,_ReturnColorTable,256,_systemMethod,0) =
>_noErr
>r.top;8 = @pictInfo.sourceRect
>OffsetRect(#r,-r.left, -r.top)
>r.right  = FN FixDiv(r.right  * 72,pictInfo.hRes)
>r.bottom = FN FixDiv(r.bottom * 72,pictInfo.vRes)
>END IF
>END IF
>
>END FN
>'~'7
>CLEAR LOCAL
>'~'8
>LOCAL FN OpenImageFile (fName AS STR63, vRef AS INT)
>'~'9
>DIM AS RECT r
>
>pictH = USR IMAGEFILETOPICT(fName,vRef)
>long IF pictH = _nil
>EXIT FN
>xelse
>edit$(1) = fName
>PICTURE (150,20)-(400,220),pictH
>DEF DISPOSEH(pictH)
>end if
>
>END FN
>'~'7
>CLEAR LOCAL
>'~'8
>LOCAL FN ProcessFolder (vRef AS INT)
>'~'9
>DIM AS INT   out
>DIM AS STR63 fName
>DIM pb.80
>'DO
>pb.ioFDirIndex% =  index
>pb.ioNamePtr&   = @fName
>pb.ioVRefNum%   =  vRef
>
>SELECT FN PBGetFInfoSync (pb)
>CASE _noErr
>pictH = USR IMAGEFILETOPICT(fName,vRef)
>long IF pictH = _nil
>index++
>xelse
>long if in = 0
>in = 1
>start = index
>end if
>FN OpenImageFile(fName,pb.ioVRefNum%)
>EXIT FN
>end if
>CASE ELSE
>fend = index
>index = start-1
>EXIT FN
>END SELECT
>'UNTIL out = 1
>END FN
>'~'7
>CLEAR LOCAL MODE
>'~'8
>LOCAL FN ChoseFolder
>'~'9
>DIM AS INT @ vRef
>DIM AS STR63 fName
>index = 1
>fName = FILES$(_fFolder,"",,vRef)
>gvRef = vRef
>cursor _watchcursor
>IF fName[0] THEN FN ProcessFolder(vRef)
>cursor _arrowcursor
>
>END FN
>'~'7
>
>clear Local
>LOCAL FN HandleDialog
>DIM AS STR63 rName
>DIM DlgEV%,DlgID%
>DlgEV% = DIALOG(0)
>DlgID% = DIALOG(DlgEV%)
>
>SELECT DlgEV%'first figure out what event it was
>'------------- Window events --- (id =  window ID) -----------------
>CASE _wndClick'window clicked
>CASE _wndClose'window closed
>forever = 1
>CASE _wndRefresh
>'window needs refreshing
>'doesn't work for fist pic
>PICTURE (150,20)-(400,220),pictH
>CASE _btnClick'button clicked (id = button id)
>select DlgID%
>case 1
>cursor _watchcursor
>vRef= gvRef
>index++
>FN ProcessFolder(vRef)
>cursor _arrowcursor
>case 2
>fName$ = edit$(1)
>rName$ = edit$(2)
>FN DISPOSHANDLE(pictH)
>rename fName$ to rName$,vRef
>edit$(1) = rName$
>edit$(2) = ""
>case 3
>forever = 1
>end select
>
>END SELECT
>END FN
>
>
>WINDOW 1,"Mavica JPEG Viewer/Renamer",,_docNoGrow
>
>edit field 1,"file name",(100,300)-(250,314),_FramedNoCr,_centerjust
>edit field 2,"New",(100,320)-(250,334),_FramedNoCr,_centerjust
>button 1,_activeBtn,"Next Picture",(300,300)-(450,318),_shadow
>button 2,_activeBtn,"Rename Picture",(300,320)-(450,338),_push
>button 3,_activeBtn,"Quit",(300,340)-(450,358),_push
>long color 55000,45000,65000,0
>cls
>FN ChoseFolder
>on dialog FN HandleDialog
>
>DO
>HANDLEEVENTS
>UNTIL forever = 1
>
>
>
>--
>To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>



Best,

-STAZ  ~)~

800.348.2623 Orders  http://www.stazsoftware.com
228.255.7086 FAX     mailto:staz@...