Professional Web Applications Themes

Saving a buffer to file - Mac Programming

This is in reference to David Oster's code for saving an image to file: I've used your image saving code in an existing application. I had to change a few things to get it to work, such as having gSiz be 16 instead of 8, as I assume this refers to bit size.(?) I also made the PicHandle global. I replaced the checkerboard poly draw routine with a copybits routine. Nothing. So I did a simple drawing instead, which works. From this I deduce that a copybits routine doesn't get seen by this function and therefore this leads me to ...

  1. #1

    Default Saving a buffer to file

    This is in reference to David Oster's code for saving an image to file:

    I've used your image saving code in an existing application. I had to change
    a few things to get it to work, such as having gSiz be 16 instead of 8, as I
    assume this refers to bit size.(?) I also made the PicHandle global. I
    replaced the checkerboard poly draw routine with a copybits routine.
    Nothing. So I did a simple drawing instead, which works. From this I deduce
    that a copybits routine doesn't get seen by this function and therefore this
    leads me to believe that ONLY drawing is "caught" by the OpenPicture
    function. Is this correct?
    Now what I need to know is how to save an existing image in a window to
    file. Or from an offscreen GWorld.

    On a different issue, I have a problem with my dialog box for the "Save as"
    menu item. It shows as a white rectangle with no writing or buttons. I can
    save stuff by typing in a title when the i-beam cursor shows that I'm over
    the text box and I can pull down the file system menu in the dialog. This
    problem acts differently depending on whether I use a command key or the
    menu. If I use the command key the dialog acts as above. If I use the menu
    command, the dialog draws its information to my window, which shows up after
    I close the dialog. I have seen this behavior before in other applications
    I've written but I've never solved the problem. Is this something to do with
    which window is the focus? I thought the Dialog Manager would take care of
    this sort of thing. Any ideas?

    johnoco Guest

  2. #2

    Default Re: Saving a buffer to file

    In article <BBE19D4C.5686%net>,
    johnoco <net> wrote:
     

    gSiz just controls the granularity of the checkerboard in the simple
    sample code I posted.

    Normally, you use SetWRefCon() and GetWRefCon() to associate a pointer
    to a struct with each window, and put the window dependent stuff there.

    CopyBits() _is_ drawing that _is_ recorded in a PicHandle. The
    destination bitMap must be in the GrafPort that was current at the time
    of OpenPicture call.
     

    CopyBits() it to itself, using srcCopy mode, between the OpenPicture()
    ClosePicture() calls. In your project, make sure you've assigned enough
    memory in the Target's Setting's SIZE resource to have room for the
    PicHandle in memory.
     

    Sounds like you aren't properly handling update events in your _own_
    windows, so the update event for the dialog box is never getting a
    chance to be processed.

    -- David Phillip Oster
    David Guest

  3. #3

    Default Re: Saving a buffer to file

    in article sf.sbcglobal.net, David Phillip
    Oster at org wrote on 11/19/03 11:09 PM:
     
    >
    > gSiz just controls the granularity of the checkerboard in the simple
    > sample code I posted.
    >
    > Normally, you use SetWRefCon() and GetWRefCon() to associate a pointer
    > to a struct with each window, and put the window dependent stuff there.
    >
    > CopyBits() _is_ drawing that _is_ recorded in a PicHandle. The
    > destination bitMap must be in the GrafPort that was current at the time
    > of OpenPicture call.

    >
    > CopyBits() it to itself, using srcCopy mode, between the OpenPicture()
    > ClosePicture() calls. In your project, make sure you've assigned enough
    > memory in the Target's Setting's SIZE resource to have room for the
    > PicHandle in memory.

    >
    > Sounds like you aren't properly handling update events in your _own_
    > windows, so the update event for the dialog box is never getting a
    > chance to be processed.
    >
    > -- David Phillip Oster[/ref]

    OK, now we're gettin' somewhere! I drew the window to the window. It saves
    out and can be opened. Now, the Dialog problem is the sticking point. Same
    problem as before, only now the saved image has the Dialog rect saved on top
    of the image as a white rect. I've tried everything I can think of to handle
    my update differently. Could this be something else, like the wrong header
    <Dialogs.h> ? When I dismiss the dialog, my window updates just fine...

    Here's what I'm doing:

    void UpdateDrawWindow( WindowPtr theWindow )
    {

    SetPort( theWindow );

    BeginUpdate( theWindow );

    if( firstTimeThrough == 0 )//special handling, doesn't do this on opening
    //the program
    {
    CopybitsFunction();//this is my drawing routine
    }

    firstTimeThrough = 1;

    HandCursor = GetCursor( theHandCursor );
    HLock( (Handle)HandCursor );
    SetCursor( *HandCursor );
    HUnlock( (Handle)HandCursor );

    EndUpdate( theWindow );

    }


    I'm pretty happy that I've gotten as far as I have on this (Thank you!).
    I've been dabbling in Mac programming for a few years but until now I
    haven't ever gotten to communicate with any Mac programmers! So I have what
    probably appear to be kind of wierd habits, I suppose.

    johnoco Guest

  4. #4

    Default Re: Saving a buffer to file

    In article <BBE20859.5AD1%net>, johnoco
    <net> wrote:

    [snip] 


    (1) Make sure that firstTimeThrough is explicitly initialised to zero
    in your application startup code.

    (2) What kind of dialog is it: modal or modeless? Makes a difference
    in terms of how updating is done.
    David Guest

  5. #5

    Default Re: Saving a buffer to file

    in article 201120031338572459%com, David C. Stone at
    com wrote on 11/20/03 10:38 AM:
     
    >
    >
    > (1) Make sure that firstTimeThrough is explicitly initialised to zero
    > in your application startup code.[/ref]
     


    It's a call to StandardPutFile() so it's a modal dialog. How would this
    affect whether the contents of the dialog get drawn to the correct window?
    Very perplexing!

    johnoco Guest

  6. #6

    Default Re: Saving a buffer to file

    In article <BBE20859.5AD1%net>, johnoco
    <net> wrote:
     [/ref]

    After you dismiss the dialog, you should do a:

    while(WaitNextEvent(everyEvent, &e, NULL, 0)){
    HandleEvent(&e);
    }

    to make sure any pending update events are handled before you read from
    the screen.

    When you get more advanced, you can use NewGWorld() to create an
    offscreen drawing area, so you can save PICTs that are much larger than
    the screen.
    David Guest

  7. #7

    Default Re: Saving a buffer to file

    in article news.prodigy.com, David
    Phillip Oster at org wrote on 11/20/03 11:31 PM:
     [/ref]
    >
    > After you dismiss the dialog, you should do a:
    >
    > while(WaitNextEvent(everyEvent, &e, NULL, 0)){
    > HandleEvent(&e);
    > }
    >
    > to make sure any pending update events are handled before you read from
    > the screen.
    >
    > When you get more advanced, you can use NewGWorld() to create an
    > offscreen drawing area, so you can save PICTs that are much larger than
    > the screen.[/ref]


    Ah, the sweet smell of success! It works! Thank you, gentlemen.
    As it turned out, I was using SetPort() instead of using SetGWorld(). That
    solved the "blank Dialog" problem. David, your idea of updating after
    dismissing the dialog got rid of the white area on the saved image. The
    color picker works, too.
    I do use GWorlds already. So, to save a GWorld to file, I'll try using that
    instead of the window while doing my image creation, before saving it to
    file.
    Not only that, but since I can save using my Creator code, my doents
    have their own icons. That's a first, too.
    I'm really jazzed. If you'd like to see the results of this in my
    unfinished program I'll be glad to send a .sit file (it's small, like 80k)
    to you.
    Thanks,
    John

    johnoco Guest

Similar Threads

  1. Replies: 5
    Last Post: April 12th, 02:24 AM
  2. Problem in saving file using File io
    By wzwei webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 0
    Last Post: November 28th, 04:49 PM
  3. Replies: 0
    Last Post: August 23rd, 09:14 AM
  4. Replies: 0
    Last Post: July 5th, 04:31 PM

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