# bitmapFill transparancy

**URL:** https://forum.kirupa.com/t/bitmapfill-transparancy/265738
**Category:** flash
**Created:** [July 11, 2008, 7:33pm UTC](https://forum.kirupa.com/t/bitmapfill-transparancy/265738 "2008-07-11T19:33:58Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![grandpaw\_broon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/grandpaw_broon/32/3985_2.png) [@grandpaw\_broon](https://forum.kirupa.com/u/grandpaw_broon)
#### Post date: [July 11, 2008, 7:33pm UTC](https://forum.kirupa.com/t/bitmapfill-transparancy/265738/1 "2008-07-11T19:33:58Z")

</div>

Hey all,

Im attempting to create my game graphics using bitmapfill…

From the Loader instance…

```auto

[LEFT]var img:Bitmap = e.target.content as Bitmap;
var bd:BitmapData = new BitmapData(img.width, img.height);
bd.draw(img);[/LEFT]
 
 
[LEFT]_grassSprite = new Sprite();
_grassSprite.graphics.beginBitmapFill(bd);
_grassSprite.graphics.drawRect(-(_width/2), -(_height/2), _width, img.height);
_grassSprite.graphics.endFill();[/LEFT]
 
addChild(_grassSprite);
 

```

I am trying to load in a transparent gif (orginally it was a png and originally i tried to embed it) but none of these work. I cant get transparancy in my fill.

Is this even possible? Am i doing something wrong?

Any help would be great.

Thanks,

---

<div class="post-metadata">

### Author: ![grandpaw\_broon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/grandpaw_broon/32/3985_2.png) [@grandpaw\_broon](https://forum.kirupa.com/u/grandpaw_broon)
#### Post date: [July 11, 2008, 8:34pm UTC](https://forum.kirupa.com/t/bitmapfill-transparancy/265738/2 "2008-07-11T20:34:38Z")

</div>

I just tried this and it works but it does not really address the loss of transparacy to begin with.

It looks through the image for the non alpha white pixels and converts them into full alpha… I think thats what its used for!

```auto
var img:Bitmap = e.target.content as Bitmap;
var bd:BitmapData = new BitmapData(img.width, img.height);
**bd.threshold(bd, new Rectangle(0, 0, img.width, img.height), new Point(0, 0), "==", 0xFFFFFFFF, 0x00000000);**
bd.draw(img);
 
_grassSprite = new Sprite();
_grassSprite.graphics.beginBitmapFill(bd);
_grassSprite.graphics.drawRect(-(_width/2), -(_height/2), _width, img.height);
_grassSprite.graphics.endFill();
 
addChild(_grassSprite);

```

---

<div class="post-metadata">

### Author: ![devonair](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@devonair](https://forum.kirupa.com/u/devonair)
#### Post date: [July 11, 2008, 8:35pm UTC](https://forum.kirupa.com/t/bitmapfill-transparancy/265738/3 "2008-07-11T20:35:41Z")

</div>

Check out the BitmapData constructor documentation…

---

<div class="post-metadata">

### Author: ![grandpaw\_broon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/grandpaw_broon/32/3985_2.png) [@grandpaw\_broon](https://forum.kirupa.com/u/grandpaw_broon)
#### Post date: [July 11, 2008, 10:25pm UTC](https://forum.kirupa.com/t/bitmapfill-transparancy/265738/4 "2008-07-11T22:25:03Z")

</div>

Ahh man im so stupid.

i been setting the width and height and completely neglected the transparent flag.

var bd:BitmapData = new BitmapData(img.width, img.height, **true** );

Thanks 😃

EDIT.

This dont work if you embed the image with metatag but it seems to work if you use a Loader() instance.

Strange eh?

---

<div class="post-metadata">

### Author: ![devonair](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@devonair](https://forum.kirupa.com/u/devonair)
#### Post date: [July 11, 2008, 11:38pm UTC](https://forum.kirupa.com/t/bitmapfill-transparancy/265738/5 "2008-07-11T23:38:51Z")

</div>

Also make sure you set the background color - the fourth argument. It’s in ARGB format (“A” for alpha). It defaults to 0xFFFFFFFF which is solid white (100% alpha)… Try 0x00FFFFFF for transparent white (of course the color doesn’t really matter when the alpha is set to 0)…

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [July 11, 2008, 11:40pm UTC](https://forum.kirupa.com/t/bitmapfill-transparancy/265738/6 "2008-07-11T23:40:11Z")

</div>

[QUOTE=devonair;2357206]Also make sure you set the background color - the fourth argument. It’s in ARGB format (“A” for alpha). It defaults to 0xFFFFFFFF which is solid white (100% alpha)… Try 0x00FFFFFF for transparent white (of course the color doesn’t really matter when the alpha is set to 0)…[/QUOTE]  
Just set it to 0 for transparent.

0 = 0x00000000 = transparent black.

---

<div class="post-metadata">

### Author: ![devonair](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@devonair](https://forum.kirupa.com/u/devonair)
#### Post date: [July 11, 2008, 11:46pm UTC](https://forum.kirupa.com/t/bitmapfill-transparancy/265738/7 "2008-07-11T23:46:23Z")

</div>

True, but lazy as I am, I can’t bring myself to do that… I code all color hex values in all caps and 6 - 8 alphanumerics… Can’t help myself… of course you’re right though - it’s the same thing…

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [July 11, 2008, 11:49pm UTC](https://forum.kirupa.com/t/bitmapfill-transparancy/265738/8 "2008-07-11T23:49:13Z")

</div>

Haha, well that is more consistent.
