Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Blend given sprite from 0 to given value
ZGTSB-Bitmap Slider Scroll
DriveInfo
Doutone-Alphamania
Risk
Open a window from inside shockwave
ESCAPE Video Studio
Vector Shape - Create Square Wave
SetMouseXtra
Getting full error messages
 

 

 

Behavior Export JPEG

Added on 7/7/1999

 

Compatibilities:
behavior D7 D8 Mac PC

Rating:

Author: JoachimGola

Uses Director"s own Xtras ("JavaConvert", "Mix Services", "JPEG Export", "Image Translator Helper") to export cast members to JPEGs Allows the configuration of which member is exported, the path of the JPEG file, the JPEG quality and whether the behavior should check for the xtras" availability or not.
If you pass an empty string as export path, FileXtra is used to get a path

-- Recent changes / additions (as of 07/99)
--• With Director 7.02 you"ll need the following Xtras: JavaConvert, Mix Services, Image Translator Helper, JPEG Export
--• The exporting movie has to be external – as Gretchen MacDowall stated. Verified.
--• Iren Gurarye added that the exporting movie must not be protected. Verified.
--• David Foster stated that in D 7.02 the BMP Agent Xtra may be necessary. Not verified for Windows, not true for Mac.
--• David Foster (and others) stated that only members from castlib 1 (standard internal castlib) may be exported. Verified. Baring that in mind you may simplify the above script line to:
--  myinst.ExportMedia(item 1 of the movie, mymember, myfilepath, 1, myquality, 1)
--
--Instead of using undocumented and not-really-tested features, you may think of trying one of these commercial xtras (no risk minimizing without money ;-):

-- JPEG Export behavior
-- © Joachim Gola 1999
-- more fine Director stuff at http://www.director7.de/

-- button behavior, acts on mouseup
-- more information on conventions & checks incorporated see:
-- http://www.director7.de/data/workshop/jowork7_i.html

-- There was a problem with Xtras checking on Windows, that should be corrected.
-- Also there was a problem with fileXtra syntax on windows.

-- The following persons contributed checks or corrections:
-- Gretchen MacDowall, John Foster, Iren Gurarye, Dave Pentin, Chuck Neal

property myinst, xtracheck, xtrasOK
property mymember,myfilepath, myquality, mymovie
property pathdel

--
-- Primary Event Handlers
--
on beginsprite me
  pathdel = the last char of the applicationpath -- pathdelimiter
  -- Check for necessary Xtras
  if xtracheck = 1 then
    myxtras = ["Mix Services", "JPEG Export"]
    if the platform contains "mac" then myxtras.add("JavaConvert")
    else myxtras.add("JavaCnvt")
    global version
    temp = char (the number of chars of version) of version
    case temp of
      "0", "1": myxtras.add("BMP Import Export")
      "2": myxtras.add("Image Translator Helper")
      otherwise
        myxtras.add("Image Translator Helper")
        put "Only tested for Director versions 7.0, 7.01 und 7.02."
    end case
    if checkXtras(me, myXtras) then xtrasOK = 1
    else xtrasOK = 0
  else xtrasOK = 1
  -- check for naming of the director movie
  test = offset(".dir", the movie)
  if test > 0 then
    mymovie = (the movie).char[1..test-1]
    od = the itemdelimiter
    the itemdelimiter = pathdel
    test = the last item of the filename of castlib 1
    if test <> the movie then alert "JPEG Xport won't work with movies inside a projector. Keep external."
    the itemdelimiter = od
  else
    mymovie = VOID
    alert "JPEG Xport won't work with protected movies. Use the normal extension (.dir)"
  end if
end

on mouseup me
  convertToJPEG me
end

on endsprite me
  cleanup me
end

--
-- Specific handlers
--

on convertToJPEG me
  if xtrasOK AND stringP(mymovie) then
    mymember = checkmember(me, mymember)
    thepath = getpath(me, myfilepath)
    cursor 4
    updatestage
    myinst = new(xtra "JavaConvert")
    myinst.ExportMedia(mymovie, mymember, thepath, 1, myquality, mymember.castlibnum)
    cursor 0
    updatestage
  end if
end

on checkXtras me, theXtras
  temp = the xtralist
  od = the itemdelimiter
  the itemdelimiter = "."
  repeat with i = 1 to temp.count()
    mytest = thextras.getpos(temp[i].name.item[1])
    if mytest > 0 then theXtras.deleteat(mytest)
  end repeat
  the itemdelimiter = od
  if theXtras = [] then return TRUE
  else
    retval = ""
    repeat with i = 1 to theXtras.count()
      retval = retval & theXtras[i] & " "
    end repeat
    alert "Xtra(s) missing"&return&retval
    return FALSE
  end if
end

on checkmember me, amember
  if ilk(value(amember)) = #member then return value(amember)
  else if integerp(amember) or stringP(amember) then return member(amember)
  else abort
end

on getpath me, aPath
  if stringP(apath) then
    if apath <> "" then return apath
  end if
  if checkXtras(me, ["FileXtra"]) then
    if the platform contains "Mac" then apath = FileSaveAsDialog("","Export.jpg", "Where should I place the JPEG?")
    else apath = FileSaveAsDialog("", "Export.jpg", "Where should I place the JPEG?", 1)
    if apath = "" then abort
    else return apath
  else
    abort
  end if
end

on cleanup me
  myinst = VOID
end

--Service

on getBehaviorTooltip me
  t = "This Behavior exports a JPEG on mouseup."&return
  t = t & "You may set the following parameters in the behavior's dialog:"&return
  t = t & "- member reference"&return
  t = t & "- pathname (or EMPTY for opening a File Save As dialog)"&return
  t = t & "- JPEG quality (25 - 100)"&return
  t = t & "- do Xtras check (yes/no: takes time, so do only once)"&return
  t = t & "Uses Xtras: JavaConvert, Mix Services, BMP Import Export (7.0, 7.01), Image Translator Helper (7.02), JPEG Export, (FileXtra)"&return
  t = t & "© Joachim Gola 1999 (joachim@bonsaipark.com)"
  return t
end

on getBehaviorDescription me
  t = "This Behavior exports a JPEG on mouseup."&return
  t = t & "You may set the following parameters in the behavior's dialog:"&return
  t = t & "- member reference"&return
  t = t & "- pathname (or EMPTY for opening a File Save As dialog)"&return
  t = t & "- JPEG quality (25 - 100)"&return
  t = t & "- do Xtras check (yes/no: takes time, so do only once)"&return
  t = t & "Uses Xtras: JavaConvert, Mix Services, BMP Import Export (7.0, 7.01), Image Translator Helper (7.02), JPEG Export, (FileXtra)"&return
  t = t & "© Joachim Gola 1999 (joachim@bonsaipark.com)"
  return t
end getBehaviorDescription

on getPropertyDescriptionList me
  memlist = []
  repeat with i = 1 to the number of members of castlib 1
    if member(i,1).type = #bitmap then
      if member(i,1).name = "" then memlist.add(member(i,1))
      else memlist.add(member(i,1).name)
    end if
  end repeat
  ml = [:]
  ml[#mymember] = [#comment: "Export which member:", #format: #bitmap, #default: member(1,1), #range: memlist]
  ml[#myfilepath] = [#comment: "Path to export JPEG to:", #format: #string, #default: ""]
  ml[#myquality] = [#comment: "JPEG quality:", #format: #integer, #default: 80, range: [#min: 25, #max:100]]
  ml[#xtracheck] = [#comment: "Check for necessary xtras:", #format: #boolean, #default: FALSE]
  return ml
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail