Suche…


Einführung

In diesem Thema erfahren Sie etwas über das Bearbeiten von Bitmapdaten und die visuelle Verarbeitung, das Arbeiten mit Pixeln und die ersten Schritte mit Effektfiltern.

Schwellenwert (Monochrom)


erforderlich:

  1. Verstehen von Bitmap- und Bitmap-Daten

was ist schwelle

Bei dieser Einstellung werden alle Pixel in einem Bild übernommen und… entweder auf reines Weiß oder reines Schwarz gesetzt

was wir tun müssen

Hier ist eine Live-Demo dieses Beispiels mit einigen zusätzlichen Änderungen, z. B. der Verwendung einer Benutzeroberfläche zum Ändern des Schwellenwerts zur Laufzeit.

Geben Sie hier die Bildbeschreibung ein

Schwellenwert in Aktionsskript 3 aus der offiziellen Dokumentation von As3

Testet Pixelwerte in einem Bild anhand eines angegebenen Schwellenwerts und setzt Pixel, die den Test bestehen, auf neue Farbwerte. Mit der Methode Schwellenwert () können Sie Farbbereiche in einem Bild isolieren und ersetzen und andere logische Operationen an Bildpixeln durchführen.

Die Testlogik der Schwellenwertmethode () lautet wie folgt:

  1. Wenn ((pixelValue & mask) -Operation (Schwelle & Maske)), dann setzen Sie das Pixel auf Farbe.
  2. Andernfalls, wenn copySource == true, dann setzen Sie das Pixel von sourceBitmap auf den entsprechenden Pixelwert.

Ich habe gerade den folgenden Code mit genauen Namen als zitierte Beschreibung kommentiert.

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
Lizenziert unter CC BY-SA 3.0
Nicht angeschlossen an Stack Overflow