Professional Web Applications Themes

Converting a GWorld to a Picture Handle - Mac Programming

In Article [email]01HW.BB6D05170007A03E16E34AC0news.dsl.pipex.com[/email], David Burgun wrote: > Could anyone tell me the best way to turn a GWorld into a Picture Handle (not > a file)??? It's FAQ. OpenPicture/CopyBits/ClosePicture. -- Mike Kluev PS. Remove "-DELETE-." part of my e-mail address to reply....

  1. #1

    Default Re: Converting a GWorld to a Picture Handle

    In Article [email]01HW.BB6D05170007A03E16E34AC0news.dsl.pipex.com[/email], David Burgun
    wrote:
    > Could anyone tell me the best way to turn a GWorld into a Picture Handle (not
    > a file)???
    It's FAQ. OpenPicture/CopyBits/ClosePicture.

    --
    Mike Kluev

    PS. Remove "-DELETE-." part of my e-mail address to reply.

    Mike Kluev Guest

  2. #2

    Default Re: Converting a GWorld to a Picture Handle

    David Burgun <NOdburgunSPAMearthlink.net> wrote in message news:<01HW.BB6D05170007A03E16E34AC0news.dsl.pipex .com>...
    > Could anyone tell me the best way to turn a GWorld into a Picture Handle
    PicHandle GWorldToPicture(GWorldPtr gworld, SInt16 mode)
    {
    PicHandle picture = nil;

    GWorldPtr saveGWorld;
    GDHandle saveDevice;
    Rect pictureFrame;
    OpenCPicParams pictureParams;
    PixMapHandle pixels;


    GetGWorld(&saveGWorld, &saveDevice);
    SetGWorld(gworld, nil);

    pixels = GetGWorldPixMap(gworld);


    bool wasUnlocked = ((GetPixelsState(pixels) & pixelsLocked) == 0);

    LockPixels(pixels);

    GetPortBounds(gworld, &pictureFrame);

    pictureParams.srcRect = pictureFrame;
    pictureParams.hRes = 0x00480000;
    pictureParams.vRes = 0x00480000;
    pictureParams.version = -2;

    picture = OpenCPicture(&pictureParams);

    if (picture != nil)
    {
    const BitMap * bits = GetPortBitMapForCopyBits(gworld);

    // copy the data on top of itself

    CopyBits(bits, bits, &pictureFrame, &pictureFrame, mode, nil);
    ClosePicture();
    }

    if (wasUnlocked)
    UnlockPixels(pixels);

    SetGWorld(saveGWorld, saveDevice);

    return picture;
    }


    Hope it helps

    Bryan
    Bryan Pietrzak Guest

  3. #3

    Default Re: Converting a GWorld to a Picture Handle

    In Article [email]74288c70.0308232120.270dbeeposting.google.com[/email], Bryan Pietrzak
    wrote:
    > PicHandle GWorldToPicture(GWorldPtr gworld, SInt16 mode)
    > {
    > PicHandle picture = nil;
    >
    > GWorldPtr saveGWorld;
    > GDHandle saveDevice;
    > Rect pictureFrame;
    > OpenCPicParams pictureParams;
    > PixMapHandle pixels;
    >
    >
    > GetGWorld(&saveGWorld, &saveDevice);
    > SetGWorld(gworld, nil);
    >
    > pixels = GetGWorldPixMap(gworld);
    >
    >
    > bool wasUnlocked = ((GetPixelsState(pixels) & pixelsLocked) == 0);
    >
    > LockPixels(pixels);
    >
    > GetPortBounds(gworld, &pictureFrame);
    >
    > pictureParams.srcRect = pictureFrame;
    > pictureParams.hRes = 0x00480000;
    > pictureParams.vRes = 0x00480000;
    > pictureParams.version = -2;
    >
    > picture = OpenCPicture(&pictureParams);
    >
    > if (picture != nil)
    > {
    > const BitMap * bits = GetPortBitMapForCopyBits(gworld);
    >
    > // copy the data on top of itself
    >
    > CopyBits(bits, bits, &pictureFrame, &pictureFrame, mode, nil);
    > ClosePicture();
    > }
    >
    > if (wasUnlocked)
    > UnlockPixels(pixels);
    >
    > SetGWorld(saveGWorld, saveDevice);
    >
    > return picture;
    > }
    Brian,

    It lacks HLock((Handle)pixels). My experiments show that this
    is required on 9 (due to bug in CopyBits & co) especially with
    picture recording.

    Then I would say LockPixels is not necessary because QuickDraw
    will do it internally within CopyBits. The only time explicit
    LockPixels call is required is when it can fail (and it can only
    fail if pixels are purgeable) (so you can recover from its failure
    prior to calling QuickDraw), but if to not check LockPixels
    success/failure (and not recover from its failure) there is
    little point to call it explicitly. If to remove LockPixels all
    the above logic of saving/restoring pixels state could be removed.

    Then why not to use simpler OpenPicture call? I believe OpenCPicture
    is for advanced usage when you want to specify non standard resolution.

    Then, assuming we know nothing about GWorld I would set foreground
    and background colors if the is no intention to use CopyBits's
    colorization.

    Also, I'd set clip region to picture bounds: if we leave it as it
    is and it is wide open that would cause problems if picture is
    ever displayed with scaling.

    Three of above corrections are essential. I could continue (like:
    .... If we know nothing about GWorld what if it has pen level < 0,
    so picture will not be recorded? What if it is already in picture
    recording mode, so you can't just say OpenPicture without ruining
    the currently recorded picture? ...), but we need to stop somewhere :)

    --
    Mike Kluev

    PS. Remove "-DELETE-." part of my e-mail address to reply.

    Mike Kluev Guest

Similar Threads

  1. Converting Quicktime movie to flash .swf with Flix -> No picture
    By Martin Nørgaard in forum Macromedia Flash
    Replies: 4
    Last Post: November 4th, 03:28 AM
  2. Converting immage to picture for Filemaker Containor field
    By Gregory_Wlodarski@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 2
    Last Post: September 29th, 09:25 PM
  3. handle the IE.
    By Mr. x in forum Macromedia Flash
    Replies: 1
    Last Post: October 8th, 09:33 PM
  4. Replies: 1
    Last Post: October 4th, 10:04 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