Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Example1.c
/* |
File: Example1.c |
Contains: Compression of PICT Files |
The following sample code shows the simplest case of asking the user for a picture file |
to be compressed, asking them for some compression settings, then compressing the |
picture file with those settings and quitting. |
This is only a marginally practical example. A real application would not want to use |
the various calls exactly in the manner described below. It is more useful as a |
demonstration of how the calls behave in different situations. |
Written by: |
Copyright: Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/17/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
12/4/94 khs changed the format of the file to the new look and feel |
*/ |
// INCLUDE FILES |
#include <menus.h> |
#include <fonts.h> |
#include <osevents.h> |
#include <components.h> |
#include <quicktimecomponents.h> |
// FUNCTION PROTOTYPES |
void Example1(void); |
// FUNCTIONS |
void Example1(void) |
{ |
ComponentResult result; |
Point where; |
ComponentInstance ci; |
short sref; |
SFTypeList typeList; |
SFReply reply; |
// Tell SFGetFilePreview to center on the best monitor. |
where.h = where.v = -2; |
// Show only 'PICT' files in the file list. |
typeList[0] = 'PICT'; |
// Ask user to select PICT file to be compressed. |
SFGetFilePreview(where, "\p", nil, 1, typeList, nil, &reply); |
if (reply.good) |
{ |
// If they selected a file, open that file. |
result = FSOpen(reply.fName, reply.vRefNum, &sref); |
if (!result) |
{ |
// Open the Standard Compression Dialog component. |
ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType); |
if (ci) |
{ |
// If the component opened successfully, set the picture file to |
// be the test image shown in the dialog. Passing nil for srcRect |
// means use the entire image. Passing 0 for testFlags means |
// to use the default system method of displaying the test image |
// which is currently a combination of cropping and scaling. |
SCSetTestImagePictFile(ci, sref, nil, 0); |
// We don't need to explicitly set default compression settings |
// in this example. SCCompressPictureFile will see that no |
// defaults have been set since the component has been open |
// and call SCDefaultPictFileSettings with the test image for you. |
// If other defaults did exist, the following call would need to be made: |
// |
// result = SCDefaultPictFileSettings(ci,sref); |
// Again, because no settings exist yet, SCCompressPictureFile will |
// call SCRequestImageSettings automatically to get settings from |
// the user. If other settings had been made previously, the following |
// call would have to be made to explicitly ask the user for settings: |
// |
// result = SCRequestImageSettings(ci); |
// Compress the picture file with the settings chosen by the user. |
// The settings include any custom color table found in the source |
// picture if still appropriate for the depth chosen by the user. |
// |
// Note that we are able to pass the source file ref for both the |
// source and destination picture files. In this case, the picture |
// file will be compressed in place. It would probably be better to |
// ask the user for a name to save the compressed file as, rather than |
// compressing it in place. |
// |
// Also note that the result code returned could include scUserCancelled. |
result = SCCompressPictureFile(ci, sref, sref); |
// Close the Standard Compression Dialog component. |
CloseComponent(ci); |
} |
// Close the source picture file. |
FSClose(sref); |
} |
} |
} |
// MAIN FUNCTION |
void main(void) |
{ |
InitGraf(&qd.thePort); |
InitFonts(); |
FlushEvents(everyEvent, 0); |
InitWindows(); |
InitMenus(); |
InitDialogs(nil); |
InitCursor(); |
MaxApplZone(); |
Example1(); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14