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 grab IconRef from a .tiff file.



On 8/21/03 1:01 PM, Mike Kluev didst favor us with:

> On 21/08/2003 15:36, Mike Kluev wrote:
>
>> On 21/08/2003 05:35, Laurence Harris wrote:
>>
>>> On 8/20/03 7:38 PM, Mike Kluev didst favor us with:
>>>
>>>> err = GraphicsImportSetGraphicsMode(component,
>>>> graphicsModeStraightAlpha, NULL);
>>>
>>> What does this line do? In my tests, this has no effect on the resulting
>>> icon. For me, SetIconFamilyData always creates a solid black mask no matter
>>> what I do. Am I missing something?
>>
>> It is supposed to preserve alpha channel information. In fact it
>> does, so the picture created with GraphicsImportGetAsPicture still
>> contain alpha. Unfortunately it is of no use here, because when
>> picture is converted to icon with SetIconFamilyData the icon is
>> created without proper mask. As of now I do not know how to create
>> an icon with proper mask from translucent picture.
>
> I didn't know as of *then*, I do know as of *now* :)
> Below is source fragment that converts translucent image file to
> translucent iconRef. Now I add the mask information to iconFamily
> as well as picture. The tricky part was to get this alpha mask
> from image. The way I do it in GetThumbnailMaskHandle could be
> called "reverse constructing". If anybody knows better way to do
> it please let me know.

Awsome, Mike! Thanks.

BTW, shouldn't that be LockPixels();

instead of

HLock((Handle)GetGWorldPixMap());

?

Larry
>
> The full source is below. I omit error checking for simplicity.
>


> #warning "Check for errors!!!"
> Handle GetThumbnailMaskHandle(PicHandle pict)
> {
> GWorldPtr offscreen, offscreen2;
> CGrafPtr savedPort;
> GDHandle savedDevice;
> Handle h;
> CTabHandle cTab;
> OSErr err;
> Rect r;
>
> SetRect(&r, 0, 0, 128, 128);
> cTab = GetCTable(8 + 32);
>
> GetGWorld(&savedPort, &savedDevice);
>
> err = NewGWorld(&offscreen, 8, &r, cTab, NULL, 0);
> HLock((Handle)GetGWorldPixMap(offscreen));
> SetGWorld(offscreen, NULL);
> PaintRect(&r);
> DrawPicture(pict, &r);
>
> h = NewHandle(128*128);
> HLock(h);
> err = NewGWorldFromPtr(&offscreen2, 8, &r, cTab, NULL, 0,
> *h, 128);
> HLock((Handle)GetGWorldPixMap(offscreen2));
> SetGWorld(offscreen2, NULL);
> EraseRect(&r);
> DrawPicture(pict, &r);
>
> CopyBits(GetPortBitMapForCopyBits(offscreen),
> GetPortBitMapForCopyBits(offscreen2), &r, &r, subOver, NULL);
>
> SetGWorld(savedPort, savedDevice);
>
> DisposeGWorld(offscreen);
> DisposeGWorld(offscreen2);
> DisposeCTable(cTab);
>
> return h;
> }
>
> --- Cut Here ---
>
> Mike
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: How to grab IconRef from a .tiff file. (From: Mike Kluev <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.