Vector Graphic to Transparent bitmap

Alejandro Tejada capellan2000 at yahoo.com
Wed Aug 6 17:33:02 EDT 2003


Hi Ken,

I try your code in "How to Export a Card Image 
(Not a Screenshot!)" to convert a black polygon 
vector graphic (put over a red background) in 
a bitmap image. The red area of this bitmap
image was made transparent using other code from 
your page. Finally, I set the windowsShape property
of the stack to this transparent image... but
everytime I got a CRASH. 

Could anybody try this secuence?

I don't have the files with me, but here
are the codes, from the Ken Ray's site.
Thanks Ken, for this useful resource and posting
the stack "Polygon Graphic Transformations" in your
site.  :))

Alejandro Tejada

------------------------------------------------------
There are many times you might want to export the
contents of a card to a JPG or PNG file, and
MetaCard/Revolution’s built in export snapshot command
takes a literal screenshot, so things like palettes
and
toolbars can get in the way of getting a clean image
of
the card. Additionally, you might have a stack window
which is larger than the current monitor, and need to 
export the card image; export snapshot just won’t cut
it in these cases. 

The following script allows you to export a card image
to disk: 

on ExportCard pStackPath,pExportPath,pImageType
-- pStackPath is the path to the stack whose card you
want to export
-- pExportPath is where you want the image to go
-- pImageType is one of the three formats supported by
the export
--   command: paint, png or jpeg
put the alwaysBuffer of stack pStackPath into
tOldBuffer
-- The next two lines force the current card image
into the offscreen buffer
set the alwaysBuffer of stack pStackPath to false
set the alwaysBuffer of stack pStackPath to true
create invisible image
-- Here's the 'meat' of the handler:
set the imagePixMapID of last image to (the pixMapID
of stack pStackPath)
select last image
set the alwaysBuffer of stack pStackPath to tOldBuffer
do "export" && pImageType && "to file pExportPath"
delete last image
choose browse tool
end ExportCard

Note that this will only export what is visible in the
stack window; that is, if you have a scrolling group
on
the card, you won't get everything inside the group
- you would need to resize the stack to accomodate
everything before you did an ExportCard. 

Posted 3/31/03 by Ken Ray, based on original code
by Brian Yennie (thanks, Brian!)
-------------------------------------------------------

This assumes you have a good understanding of how to
manipulate imageData and maskData. If you don’t, take
a
look at tip imag003 - Understanding ImageData,
MaskData
and AlphaData before continuing. 
The following is an example of creating a single-color
transparency of an image much like what is used in GIF
images. I have chosen to use pure red (RGB: 255,0,0)
as
the mask color. 

on mouseUp
put the imageData of image 1 into iData
put the width of image 1 into tW
put the height of image 1 into tH
put empty into mData
        
repeat with i = 1 to tH  -- iterate each row
repeat with j = 1 to tW   -- iterate each column
-- Get a pointer to the specific end byte of a pixel
-- Remember there are 4 bytes per pixel
put ((i-1)*tW*4)+(j*4) into tByte
-- Go backwards from the end byte to get your R, G and
B
put charToNum(char (tByte-2) of iData) into tR
put charToNum(char (tByte-1) of iData) into tG
put charToNum(char (tByte) of iData) into tB
if (tR = 255) and (tG = 0) and (tB = 0) then
-- pixel is red, mask it
put binaryEncode("C",0) after mData
else
put binaryEncode("C",255) after mData
end if
end repeat
end repeat
set the maskData of image 1 to mData
set the imageData of image 1 to iData
end mouseUp

Hope you find this as useful as I did. :-) 

Posted 7/2/2002 by Ken Ray
-------------------------------------------------------


=====
Useful sites:
http://www.sonsothunder.com/devres/metacard/tips/ and /revolution/tips/
http://lists.runrev.com/pipermail/metacard/ and /use-revolution/
http://wiki.macitworks.com/revdocs
http://www.google.com/advanced_search?q=site:lists.runrev.com

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com



More information about the use-livecode mailing list