BitmapData.draw with different shape - actionscript-3

is it possible to change the Rectangle I use as fifth parameter of draw BitmapData class?
bitmapData.draw(image,null,null,null,rect,false);
I'm trying to draw and save a different shape (with the shape of a particular MovieClip).

If you look at the definition for the BitmapData's copyPixels method (adobe documentation), you'll see:
"If you include the alphaBitmap and alphaPoint parameters, you can use
a secondary image as an alpha source for the source image. If the
source image has alpha data, both sets of alpha data are used to
composite pixels from the source image to the destination image. The
alphaPoint parameter is the point in the alpha image that corresponds
to the upper-left corner of the source rectangle. Any pixels outside
the intersection of the source image and alpha image are not copied to
the destination image."
You can probably get this to do what you want.

Related

Libgdx, sprite batch and setColor to specific region

So I have a simple texture: one big green circle in the center and one small white circle also in the center of my texture. And now I want to change color of my white circle to yellow in my app. Is it possible and what is the best way to set color of my batch for specific region? I saw it is possible in other engines using the second texture with marked region which color will be changed.
Like that:
http://s9.postimg.org/qh7bbu5an/FINAL.png
My original texture
2nd texture with region which color i want to change
The result of my texture in app which will be working like batch.setcolor but only for specific region (pixels) in my texture
If you are looking for an example of masking textures together, you can check this tutorial.
https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson4
It also has a port to libGDX.

AS3 Bitmap black and white - for compression reasons

I have a field made up of BitmapData, which I use for pixel-precise hit detection.
However, BitmapData naturally stores 2^32 (or 2^24 with no alpha?) possibilities for each pixel. I only need 2 - black or white.
But I still need to use .draw to make other objects being drawn onto that BitmapData. It doesn't need to be visible.
Extracting a pixel for hit-detection does not seem too difficult - but drawing without cycling through each pixel seems hard. Is it possible?
What would the right approach for this problem be?
If you depend on having your bitmap data to be black or white only, you can employ BitmapData.threshold() after drawing a new mask over that bitmap. To turn your existing BitmapData to black and white with a threshold of half red channel do the following:
bd.threshold(bd,bd.rect,new Point(),"<",0x00800000,0x0,0x00ff0000,true);
bd.threshold(bd,bd.rect,new Point(),">=",0x00800000,0x00ffffff,0x00ff0000,true);
The first call with turn all points that have red below 0x80 black, the second will turn all the remaining points white. Change the mask and threshold value to use green or blue channels if you want. Consider applying a properly channeled ColorTransform object to your draw calls to make the mask correctly applied to a newly drawn object.

Actionscript 3 - Bitmaps and Symbols

I am working on flash professional cs5.5 and actionscript 3. I need to use symbols of customized sizes to test the hitTestOjbect() function. However, when i convert the bitmap to a symbol, by default it goes into a rectangular size and the empty space all around is also detected as part of the symbol.
Is there any way to keep the size of the symbol customized ?
That is the nature of a bitmap. Technically, bitmaps are always rectangular. Transparent areas are just fills with alpha-0. When you convert a bitmap to a symbol, the bitmap still exists, just inside the context of the symbol.
One of the fastest ways to fix this is to use a mask inside your MovieClip. Create a plain drawing object in the exact shape of the hit area you want. Then, place that on your timeline on it's own layer. Right-click the layer with the mask, click "Mask", and then drag the bitmap's layer under the mask one. Lock both layers, and exit symbol editing.
Now your hit area will be limited to only the masked area.
EDIT: I appear to be mistaken - hitTestArea is always rectangular. See the top answer to hitTestObject Collision Not Registering Correctly.

Error #2077: This filter operation cannot be performed with the specified input parameters

Error #2077: This filter operation cannot be performed with the specified input parameters.
at flash.display::BitmapData/applyFilter()
I got this error message trying to apply a BitmapFilter (specifically an inner DropShadowFilter) to a BitmapData via .applyFilter
I've never seen this message before and Googling did not immediately answer the question, and I saw someone confounded as to why it applied to JPEG and not PNG images. So hopefully this question will help someone else. I'll include my simple solution below.
Reading the BitmapData.applyFilter documentation, it's fairly obvious what the problem is. I tried to apply a DropShadowFilter to a BitmapData without transparency (aka, no alpha channel, only 24 bits per pixel.) The docs state which filters require transparency (replicated here for convenience):
Each type of filter has certain requirements, as follows:
BlurFilter — This filter can use source and destination images that are either opaque or transparent. If the formats of the images do not match, the copy of the source image that is made during the filtering matches the format of the destination image.
BevelFilter, DropShadowFilter, GlowFilter, ChromeFilter — The destination image of these filters must be a transparent image. Calling DropShadowFilter or GlowFilter creates an image that contains the alpha channel data of the drop shadow or glow. It does not create the drop shadow onto the destination image. If you use any of these filters with an opaque destination image, an exception is thrown.
ConvolutionFilter — This filter can use source and destination images that are either opaque or transparent.
ColorMatrixFilter — This filter can use source and destination images that are either opaque or transparent.
DisplacementMapFilter — This filter can use source and destination images that are either opaque or transparent, but the source and destination image formats must be the same.
Creating a BitmapData with transparency is easy - it's the 3rd parameter to the constructor:
// args are: width, height, is_transparent, default_color
var bd:BitmapData = new BitmapData(1024, 768, true, 0xff000000);
Note that when you create a transparent BitmapData, you must specify a 32-bit integer for the default color (the 4th parameter). If you merely specify 0xffffff (24-bit white), you'll get a blank image as the alpha value (the highest 8 bits) are 0.

GetPixel for a bitmap under another?

Any help on this would be much appreciated.
I am creating an interactive map in flash / actionscript 3.0 and would like to allow a user to click on a location in the map in order to find the elevation at that point. In the stage, I have a base map of the area sitting on top of a black and white image where the value of each pixel represents height in feet.
So far, using getPixel to retrieve the elevation works great, but when the base map is sitting on top of the black and white elevation surface, getPixel retrieves values for the base map, not the underlying image. Is there a way to display the base map to the user while still using getPixel to retrieve values from the underlying image?
Many thanks,
Matt
Simply use getPixel() on the black / white image, not the container.
I assume you have a container Sprite and 2 children, the black / white image and on top the base map. Attach the click listener to the container Sprite and retrieve the first child with getChildAt(0). Get the BitmapData of that child and call getPixel(x, y) on it.
If the underlying image is not being shown to the user, it need not even be in the display list; it can exist in memory only as a BitmapData.
Add your MouseEvent.CLICK listener function to the base map users can click on, and in that function use the event x and y to do a BitmapData.getPixel(x,y) on your elevation map (greyscale image) BitmapData object.