(PHP 4 >= 4.0.5)

SWFBitmap -- Loads Bitmap object


SWFBitmap swfbitmap ( mixed file [, mixed alphafile] )


本函数是实验性的。本函数的行为,包括函数名称以及其它任何关于本函数的文档可能会在没有通知的情况下随 PHP 以后的发布而改变。使用本函数风险自担。

swfbitmap() creates a new SWFBitmap object from the Jpeg or DBL file in file. alphafile is a MSK file to be used as an alpha mask for a Jpeg image. Both parameters can be fopen() resources or binary strings.

注: We can only deal with baseline (frame 0) jpegs, no baseline optimized or progressive scan jpegs!

SWFBitmap has the following methods : swfbitmap->getwidth() and swfbitmap->getheight().

You can't import png images directly, though- have to use the png2dbl utility to make a dbl ("define bits lossless") file from the png. The reason for this is that I don't want a dependency on the png library in ming- autoconf should solve this, but that's not set up yet.

例子 1. Import PNG files

= new SWFShape();
$f = $s->addFill(new SWFBitmap(file_get_contents("png.dbl")));

$s->drawLine(32, 0);
$s->drawLine(0, 32);
$s->drawLine(-32, 0);
$s->drawLine(0, -32);

$m = new SWFMovie();
$m->setDimension(32, 32);

header('Content-type: application/x-shockwave-flash');

And you can put an alpha mask on a jpeg fill.

例子 2. swfbitmap() example


= new SWFShape();

// .msk file generated with "gif2mask" utility
$f = $s->addFill(new SWFBitmap(file_get_contents("alphafill.jpg"), file_get_contents("alphafill.msk")));

$s->drawLine(640, 0);
$s->drawLine(0, 480);
$s->drawLine(-640, 0);
$s->drawLine(0, -480);

$c = new SWFShape();
$c->setRightFill($c->addFill(0x99, 0x99, 0x99));
$c->drawLine(40, 0);
$c->drawLine(0, 40);
$c->drawLine(-40, 0);
$c->drawLine(0, -40);

$m = new SWFMovie();
$m->setDimension(640, 480);
$m->setBackground(0xcc, 0xcc, 0xcc);

// draw checkerboard background
for ($y=0; $y<480; $y+=40) {
    for (
$x=0; $x<640; $x+=80) {
$i = $m->add($c);
$i->moveTo($x, $y);


    for (
$x=40; $x<640; $x+=80) {
$i = $m->add($c);
$i->moveTo($x, $y);


header('Content-type: application/x-shockwave-flash');

add a note add a note User Contributed Notes
julien / at / theoconcept.com
30-Jan-2006 06:36
If you're trying to use an image generated by PHP, remember that imagejpeg outputs an interlaced image by default, which is NOT accepted by SWFBitmap.

You have to use imageinterlace($ImageHandle, 0); to make it compatible.
ukocolu at yahoo dot com
09-Apr-2002 03:45
You may want to use flashwriter that is written by Stefan Schler an excellent image2swf converter.
lievenstandaert at hotmail dot com
16-Aug-2001 02:45
... that is, unless you're using the version of the ming library distributed with php 4.0.6, in that case go with the manual
hotkey at hehe dot com
22-May-2001 02:52
To insert bitmaps, don't use the as syntax given in this documentation, due to OPAQUE changed the usage of SWFBitmaps: You need to give binary data as argument! In addition to that, you can now just "swf->add()" Bitmaps; you don't need to create a rect-shape and fill it.

So just try this:
$fp = fopen($filename,"r");
$i = fread($fp,999999);
$img = new SWFBitmap($i); #don't give "fread(...)" as argument, but buffer it.

$swf->add($img);  #this will create a shape with perfect proportions and fills it

Hope, that will prevent some suicides of desperate coders...  ;)

HotKey - http://www.SPR.AT