Zoeken…


Invoering

In dit onderwerp kunt u een beetje leren over het bewerken van bitmapgegevens en visuele verwerking, het werken met pixels en aan de slag gaan met effectfilters .

Drempel (monochroom) effect


verplicht:

  1. inzicht in bitmap- en bitmapgegevens

wat is drempel

Deze aanpassing neemt alle pixels in een afbeelding en ... duwt ze naar puur wit of puur zwart

wat we moeten doen

hier is een Live-demo van dit voorbeeld met enkele aanvullende wijzigingen, zoals het gebruik van een gebruikersinterface om het drempelniveau tijdens runtime te wijzigen.

voer hier de afbeeldingsbeschrijving in

drempelwaarde in actiescript 3 van officiële as3-documentatie

Test pixelwaarden in een afbeelding tegen een opgegeven drempelwaarde en stelt pixels die de test doorstaan in op nieuwe kleurwaarden. Met de methode drempel () kunt u kleurbereiken in een afbeelding isoleren en vervangen en andere logische bewerkingen uitvoeren op afbeeldingspixels.

De testlogica van de drempel () methode is als volgt:

  1. Als (bewerking (pixelwaarde & masker) (drempelwaarde & masker)), stelt u de pixel in op kleur;
  2. Anders, als copySource == true, stelt u de pixel in op de overeenkomstige pixelwaarde van sourceBitmap.

ik heb zojuist de volgende code becommentarieerd met precies namen als geciteerde beschrijving.

import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Point;

var bmd:BitmapData = new wildcat(); // instantied a bitmapdata from library a wildcat
var bmp:Bitmap = new Bitmap(bmd); // our display object to previewing bitmapdata on stage
addChild(bmp);
monochrome(bmd); // invoking threshold function

/**
    @param bmd, input bitmapData that should be monochromed
*/
function monochrome(bmd:BitmapData):void {
    var bmd_copy:BitmapData = bmd.clone(); // holding a pure copy of bitmapdata for comparation steps
    // this is our "threshold" in description above, source pixels will be compared with this value
    var level:uint = 0xFFAAAAAA; // #AARRGGBB. in this case i used RGB(170,170,170) with an alpha of 1. its not median but standard
    // A rectangle that defines the area of the source image to use as input.
    var rect:Rectangle = new Rectangle(0,0,bmd.width,bmd.height);
    // The point within the destination image (the current BitmapData instance) that corresponds to the upper-left corner of the source rectangle.
    var dest:Point = new Point();
    // thresholding will be done in two section
    // the last argument is "mask", which exists in both sides of comparation
    // first, modifying pixels which passed comparation and setting them all with "color" white (0xFFFFFFFF)
    bmd.bitmapData.threshold(bmd_copy, rect, dest, ">", level, 0xFFFFFFFF, 0xFFFFFFFF);
    // then, remaining pixels and make them all with "color" black (0xFF000000)
    bmd.bitmapData.threshold(bmd_copy, rect, dest, "<=", level, 0xFF000000, 0xFFFFFFFF);
    // Note: as we have no alpha channel in our default BitmapData (pixelValue), we left it to its full value, a white mask (0xffffffff)
}


Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow