Примечание. Это ответ в 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;
}
Как видите, требуется:
- BitmapData, из которого вы хотите удалить более темные пиксели.
- uint, представляющий, сколько оттенков черного/серого вы хотите удалить.
И вот демонстрация с использованием вашего исходного изображения:
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) );
}
person
Marty
schedule
05.06.2012
http://j.imagehost.org/download/0829/WoodyGX_0 http://j.imagehost.org/download/0829/WoodyGX_1 http://j.imagehost.org/download/0829/WoodyGX_2
- person arttronics   schedule 05.06.2012