Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: How to save an image?



On Tue, 29 Apr 2008 09:16:05 +0100 (BST), Andrew Davis
<email@hidden> wrote:

> Hi,
>     I am taking an image from the system, displaying it in a window and
modifying it. Now, i need to save that modified image(jpeg, bmp, png) in some
other location within the system. All i have is the CGContextRef and the
CGImageRef( the image drawn on that context ). How to save this in a FILE?

/*****************************************************
*
* QTIE_ExportCGImageToFile( imageRef, path )
*
* Purpose:  export the image to a file at the path
*
* Inputs:   CGImageRef - the imported image
*            inExportComponentSubType - the type of file to export to
*            inPath - the path to the file to export to
*
* Returns:  OSStatus - error code ( 0 == no error )*/
OSStatus QTIE_ExportCGImageToFile( CGImageRef imageRef, const OSType
inExportComponentSubType, CFStringRef inPathCFStringRef )
{
    OSStatus                    status;

    Handle                        dataRef = NULL;
    OSType                        dataRefType;
    status = QTNewDataReferenceFromFullPathCFString( inPathCFStringRef,
kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType );
    require_noerr( status, bail );

    GraphicsExportComponent        graphicsExporter = 0L;
    status = OpenADefaultComponent( GraphicsExporterComponentType,
inExportComponentSubType, &graphicsExporter );
    require_noerr( status, bail );

    status = GraphicsExportSetInputCGImage( graphicsExporter, imageRef );
    require_noerr( status, bail );

    status = GraphicsExportSetOutputDataReference( graphicsExporter,
dataRef, dataRefType );
    require_noerr( status, bail );

    unsigned long                sizeWritten;
    status = GraphicsExportDoExport( graphicsExporter, &sizeWritten );
    // require_noerr( status, bail );
bail:
    if ( 0L != graphicsExporter ) {
        CloseComponent( graphicsExporter );
    }
    if ( 0 != dataRef )
        DisposeHandle( dataRef );
    
    return status;
}

-- 
Enjoy,
George Warner,
Schizophrenic Optimization Scientist
Apple Developer Technical Support (DTS)


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.