BLACK:0x000000の色を透明に設定するにはどうすればよいですか。通常、マジックピンクは透明ですが、BLACKをに設定したいと思います。
わからない場合:http: //j.imagehost.org/0829/WoodyGX_0.jpg
私はその画像を持っています。80x80スプライトを変換するときは、背景を透明にします。つまり、背景はなく、文字だけです。
BLACK:0x000000の色を透明に設定するにはどうすればよいですか。通常、マジックピンクは透明ですが、BLACKをに設定したいと思います。
わからない場合:http: //j.imagehost.org/0829/WoodyGX_0.jpg
私はその画像を持っています。80x80スプライトを変換するときは、背景を透明にします。つまり、背景はなく、文字だけです。
この時点で、Fireworks に取り込んで、魔法の杖を使用して黒いピクセルを選択し、それらを削除して、透明な png として保存する方がよいでしょう。それからそれを使用します。
ただし、ライフライトを必要以上に難しくしたい場合は、getPixel を使用してすべての黒いピクセルを取得し、setPixel を使用して透明に設定することができます。しかし、ブリッティングの要点は速度であり、ピクセル単位の操作が遅いことではありません。
注意: これは、ActionScript 3 に移行することを決定した場合の ActionScript 3 での回答ですが、他の人や一般的な情報についても同様です。
黒いピクセルが削除された (アルファ チャネルに変換されBitmapData
た) ソースから
新しいものを作成できます。BitmapData
私はあなたのためにこの関数を作成しました:
// Takes a source BitmapData and converts it to a new BitmapData, ignoring
// dark pixels below the specified sensitivity.
function removeDarkness(source:BitmapData, sensitivity:uint = 10000):BitmapData
{
// Define new BitmapData, with some size constraints to ensure the loop
// doesn't time out / crash.
// This is for demonstration only, consider creating a class that manages
// portions of the BitmapData at a time (up to say 50,000 iterations per
// frame) and then dispatches an event with the new BitmapData when done.
var fresh:BitmapData = new BitmapData(
Math.min(600, source.width),
Math.min(400, source.height),
true, 0xFFFFFFFF
);
fresh.lock();
// Remove listed colors.
for(var v:int = 0; v < fresh.height; v++)
{
for(var h:int = 0; h < fresh.width; h++)
{
// Select relevant pixel for this iteration.
var pixel:uint = source.getPixel(h, v);
// Check against colors to remove.
if(pixel <= sensitivity)
{
// Match - delete pixel (fill with transparent pixel).
fresh.setPixel32(h, v, 0x00000000);
continue;
}
// No match, fill with expected color.
fresh.setPixel(h, v, pixel);
}
}
// We're done modifying the new BitmapData.
fresh.unlock();
return fresh;
}
ご覧のとおり、次のものが必要です。
ソース画像を使用したデモは次のとおりです。
var original:Loader = new Loader();
original.load( new URLRequest("http://j.imagehost.org/0829/WoodyGX_0.jpg") );
original.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
// Original image has loaded, continue.
function imageLoaded(e:Event):void
{
// Capture pixels from loaded Bitmap.
var obmd:BitmapData = new BitmapData(original.width, original.height, false, 0);
obmd.draw(original);
// Create new BitmapData without black pixels.
var heroSheet:BitmapData = removeDarkness(obmd, 1200000);
addChild( new Bitmap(heroSheet) );
}