Professional Web Applications Themes

saving images to file - Mac Programming

I use c and code warrior ide 1.7.4 my computer is a 7100 with g3 card i'm still programming 68k code, and i haven't gotten around to ppc code question: how i do i save an image from a window to a pict file? i've looked everywhere in every book, and when i do find an answer, it is larded with other minutiae, it is not specific. i can be reached at this newsgroup or at net thank you....

  1. #1

    Default saving images to file

    I use c and code warrior ide 1.7.4
    my computer is a 7100 with g3 card
    i'm still programming 68k code, and i haven't gotten around to ppc code
    question: how i do i save an image from a window to a pict file? i've looked
    everywhere in every book, and when i do find an answer, it is larded with
    other minutiae, it is not specific.
    i can be reached at this newsgroup or at net
    thank you.

    johnoco Guest

  2. #2

    Default Re: saving images to file

    In article <BBDD69DD.3F87%net>,
    johnoco <net> wrote:
     

    In pseudo code:

    ph = OpenPicture(&portR);
    // You could just call your Update event handler here. or:
    CopyBits(GetBitMapForCopyBits(port), GetBitMapForCopyBits(port).
    &portR, &portR, srcCopy, NULL);
    ClosePicture();

    Now, insert 512 bytes of zero in the front of ph, with:

    SetHandleSize((Handle) ph, GetHandleSize((Handle) ph) + 512L);
    BlockMoveData(*(Handle) ph, 512 + *(Handle) ph, GetHandleSize((Handle)
    ph) - 512L);
    memset(*ph, 0, 512);

    Now write that handle as the data fork of a file of type PICT, and you've
    got a PICT file.

    Create();
    FSOpenDF();
    FSWrite();
    FSClose();


    KillPicture();
    David Guest

  3. #3

    Default Re: saving images to file

    In article <sf.sbcglobal.net>,
    David Phillip Oster <org> wrote:
     
    >
    > In pseudo code:
    >
    > ph = OpenPicture(&portR);
    > // You could just call your Update event handler here. or:
    > CopyBits(GetBitMapForCopyBits(port), GetBitMapForCopyBits(port).
    > &portR, &portR, srcCopy, NULL);
    > ClosePicture();
    >
    > Now, insert 512 bytes of zero in the front of ph, with:
    >
    > SetHandleSize((Handle) ph, GetHandleSize((Handle) ph) + 512L);
    > BlockMoveData(*(Handle) ph, 512 + *(Handle) ph, GetHandleSize((Handle)
    > ph) - 512L);
    > memset(*ph, 0, 512);
    >
    > Now write that handle as the data fork of a file of type PICT, and you've
    > got a PICT file.
    >
    > Create();
    > FSOpenDF();
    > FSWrite();
    > FSClose();
    >
    >
    > KillPicture();[/ref]

    In actual code:

    // WriteMyPictFile - actually write the data to the file.
    static OSErr WriteMyPictFile(WindowPtr win, SInt16 ref){
    OSErr e = noErr;
    PicHandle ph = NULL;
    Str255 s = {0};
    long len;
    Rect bounds;
    bounds = win->portRect;
    if(NULL == (ph = CreateMyPict(win, &bounds, gSiz))){
    e = memFullErr;
    }
    if(noErr == e){ e = SetEOF(ref, 0); } // file already exists,
    truncate it.
    len = 256;
    if(noErr == e){ e = FSWrite(ref, &len, s); }
    if(noErr == e){ e = FSWrite(ref, &len, s); }
    if(noErr == e){
    len = GetHandleSize((Handle) ph);
    e = FSWrite(ref, &len, *ph);
    }
    if(NULL != ph){
    KillPicture(ph);
    }
    return e;
    }

    // DoSave - given the file, open it, save the data, close it. (note, it
    might already exist, so truncate it.)
    static OSStatus DoSave1(WindowPtr win, FSSpec *fs){
    OSStatus e = noErr;
    OSStatus e1 = noErr;
    FInfo info;
    short ref = 0;

    FSpCreate(fs, 'ttxt', 'PICT', smSystemScript); // may fail if file
    already exists.
    if(noErr == e){ e = FSpGetFInfo(fs, &info); } // if file already
    exists.
    info.fdType = 'PICT';
    info.fdCreator = 'ttxt';
    if(noErr == e){ e = FSpSetFInfo(fs, &info); } // make it the right
    type
    if(noErr == e){ e = FSpOpenDF(fs, fsRdWrPerm, &ref); }
    if(noErr == e){ e = WriteMyPictFile(win, ref); }
    if(0 != ref){
    e1 = FSClose(ref);
    if(noErr == e){ e = e1; } // if we aren't already erroring,
    propagate the return code.
    }
    if(noErr != e){
    e1 = FSpDelete(fs);
    }
    return e;
    }

    // DoSaveAs - save as menu command
    OSStatus DoSaveAs(WindowPtr win){
    StandardFileReply myReply;
    OSStatus e = noErr;
    StandardPutFile("\pSave as:", "\punTitled", &myReply);
    if( ! myReply.sfGood){
    return userCanceledErr;
    }
    return DoSave1(win, &myReply.sfFile);
    }


    // DoSave - save menu command
    OSStatus DoSave(WindowPtr win){
    if( ! gIsInitFS){
    return DoSaveAs(win);
    }else{
    return DoSave1(win, &gFS);
    }
    }
    David Guest

Similar Threads

  1. Saving Images?
    By tennisknight in forum Macromedia Flash Player
    Replies: 0
    Last Post: November 28th, 05:36 PM
  2. Saving Images
    By pezmorized in forum Macromedia Contribute General Discussion
    Replies: 1
    Last Post: May 11th, 09:27 PM
  3. Saving Images While Saving ASP Pages !
    By Lovely Angel For You in forum ASP
    Replies: 1
    Last Post: October 3rd, 12:03 AM
  4. [PHP] saving images into pdf file using PDFlib
    By Jay Blanchard in forum PHP Development
    Replies: 1
    Last Post: August 13th, 01:00 PM
  5. saving images into pdf file using PDFlib
    By Jan in forum PHP Development
    Replies: 0
    Last Post: August 13th, 10:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139