On 6/1/05 5:15 PM, "Kerry Thompson" <[EMAIL PROTECTED]> wrote:
> Is there a way to get the image of a sprite?
> 
> I have the DirectImage Xtra, but it looks like I can only get the image
> of the stage or a member. I need to get a sprite's image, with its
> rotation, transparency, scaling--all the tricks you can do with sprites.
> 
> Oh, yes, I need to preserve the alpha as well.

Hi Kerry,

Yes, but you need to set the stage's bgColor momentarily to black and then
to white, so a flash may occur.

Basically, you set the visibility of any overlapping sprite to FALSE, then
use the handler below to generate an alpha-enabled image of the stage area
corresponding to the rect of the sprite.

Perhaps if you explained the circumstances in which you need to grab a
sprite's image, I might be able to come up with an alternative.

Bon courage,

James


on getStageImageWithAlpha(aStageRect) --------------------------------
  -- INPUT: <aStageRect> must be a rect within the stage
  -- OUTPUT: a 32-bit image equivalent to the image of the stage
  --         within the given rect, where the alpha channel correctly
  --         removes the background color of the stage.  Antialiasing
  --         between the stage and vectorized sprites is preserved.
  -- NOTE:   The colorDepth must be set to 32 for this to work
  -- Thanks to S�bastien Portebois for pointing out the need to start
  -- with a black image.
  --------------------------------------------------------------------
  
  tWidth  = aStageRect.width
  tHeight = aStageRect.height
  tRect   = rect(0, 0, tWidth, tHeight)
  
  tStageColor = (the stage).bgColor
  
  -- Create the output image (32-bit with active alpha channel)
  tImage  = image(tWidth, tHeight, 32, 8)
  tImage.fill(tRect, rgb(0, 0, 0))
  
  -- Grab the image of the stage with a red background
  (the stage).bgColor = rgb(255, 0, 0)
  updateStage
  tTemp = (the stage).image.crop(aStageRect)
  
  -- Isolate the red channel of the stage image
  tLayer = image(tWidth, tHeight, 32)
  tLayer.fill(tRect, rgb(255, 0, 0))
  tLayer.copyPixels(tTemp, tRect, tRect, [#ink: #transparent])
  -- #transparent ink (d = d AND s) removes colors other than red
  --new(#bitmap).image = tLayer
  
  -- Add red channel to image
  tImage.copyPixels(tLayer, tRect, tRect, [#ink: #add])
  --new(#bitmap).image = tImage
  
  -- Grab the image of the stage with a green background
  (the stage).bgColor = rgb(0, 255, 0)
  updateStage
  tTemp = (the stage).image.crop(aStageRect)
  
  -- Isolate the green channel of the stage image
  tLayer.fill(tRect, rgb(0, 255, 0))
  tLayer.copyPixels(tTemp, tRect, tRect, [#ink: #transparent])
  --new(#bitmap).image = tLayer
  
  -- Add green channel to image
  tImage.copyPixels(tLayer, tRect, tRect, [#ink: #add])
  
  -- Grab the image of the stage with a blue background
  (the stage).bgColor = rgb(0, 0, 255)
  updateStage
  tTemp = (the stage).image.crop(aStageRect)
  
  -- Isolate the blue channel of the stage image
  tLayer.fill(tRect, rgb(0, 0, 255))
  tLayer.copyPixels(tTemp, tRect, tRect, [#ink: #transparent])
  --new(#bitmap).image = tLayer
  
  -- Add blue channel to image
  tImage.copyPixels(tLayer, tRect, tRect, [#ink: #add])
  
  -- Isolate the background and the antialiasing halo
  (the stage).bgColor = rgb(0, 0, 0)
  updateStage
  tLayer = (the stage).image.crop(aStageRect)
  --new(#bitmap).image = tLayer
  
  (the stage).bgColor = rgb(255, 255, 255)
  updateStage
  tTemp = (the stage).image.crop(aStageRect)
  --new(#bitmap).image = tTemp
  
  tTemp.copyPixels(tLayer, tRect, tRect, [#ink: #subtract])
  
  -- Create the alpha channel as an 8-bit version of tTemp
  tAlpha = image(tWidth, tHeight, 8, #grayScale)
  tAlpha.copyPixels(tTemp, tRect, tRect)
  --new(#bitmap).image = tAlpha
  tImage.setAlpha(tAlpha)
  
  -- Restore the original stage color
  (the stage).bgColor = tStageColor
  updateStage
  
  return tImage
end getStageImageWithAlpha 


[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[email protected]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to