[转]求解!如何将JPG图片的黑底去掉换成透明底?

[url]http://bbs.9ria.com/viewthread.php?tid=76207&extra=page%3D2%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000[/url]


[img]http://dl.iteye.com/upload/attachment/439738/fab50ecc-7075-3229-b5d1-d11be4f58132.jpg[/img]
求解!如何将JPG图片的黑底去掉换成透明底?

在线等答案~ 请各路大侠们帮忙哈!

package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.ByteArray;

/**
* ...
* @author sailor
*/
[SWF(backgroundColor=0x550055)]
public class Main extends Sprite
{

[Embed(source = '../lib/2.jpg')]

public var bmp:Class;
public function Main():void
{
var bmpd:BitmapData = Bitmap(new bmp()).bitmapData;

var newbmpd:BitmapData = new BitmapData(bmpd.width, bmpd.height, true, 0);
var buffer:ByteArray = bmpd.getPixels(bmpd.rect);

buffer.position = 0;
for (var i:int = 0, len:int = buffer.length ; i < len; i += 4 )
buffer[i] = (buffer[i + 1] + buffer[i + 2] + buffer[i + 3]) / 3;

newbmpd.setPixels(bmpd.rect, buffer);

addChild(new Bitmap(newbmpd));

}


}

}

你可能感兴趣的:(AS3收集)