Buscar..


Introducción

En este tema, puede aprender un poco sobre la manipulación de datos de mapas de bits y el procesamiento visual, trabajar con píxeles y comenzar a utilizar filtros de efectos.

Efecto umbral (monocromo)


necesario:

  1. entendiendo bitmap y bitmap data

que es el umbral

Este ajuste toma todos los píxeles de una imagen y ... los empuja a blanco puro o negro puro

Que tenemos que hacer

Aquí hay una demostración en vivo de este ejemplo con algunos cambios adicionales, como usar una interfaz de usuario para cambiar el nivel de umbral en tiempo de ejecución.

introduzca la descripción de la imagen aquí

umbral en el script de acción 3 de la documentación oficial as3

Prueba los valores de los píxeles en una imagen contra un umbral específico y establece los píxeles que pasan la prueba a nuevos valores de color. Usando el método de umbral (), puede aislar y reemplazar los rangos de color en una imagen y realizar otras operaciones lógicas en píxeles de imagen.

La lógica de prueba del método del umbral () es la siguiente:

  1. Si ((pixelValue & mask) operación (umbral & mask)), entonces configure el pixel en color;
  2. De lo contrario, si copySource == true, configure el píxel en el valor de píxel correspondiente de sourceBitmap.

Acabo de comentar el siguiente código con exactamente los nombres como descripción citada.

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
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow