2010-06-10 5 views

Répondre

1

Je pense que ce que vous voulez dire est comme l'exemple suivant: Multi color image Dans cet exemple, j'ai pris une image et fait en niveaux de gris (supérieur gauche) en haut à droite est le même niveau de gris image mais ensuite avec une superposition rouge et définir le mode de fusion pour assombrir. Samen avec le bleu et le jaune. Pour créer une image en niveaux de gris en flash, vous devez définir les mêmes valeurs pour les canaux Red Blue et Green. Vous pouvez le faire facilement en flash. D'abord vous devez avoir un objet bitmapData avec l'image dedans. Ensuite, faites-le en niveaux de gris et enfin faire la superposition et le mélanger ensemble.

Pour obtenir BitmapData avec l'image que vous pouvez suivre l'exemple @adobe reference

J'ai fait une classe par exemple (travaillé à partir de l'exemple @ adobe) qui fait exactement ce que je disais plus haut:

package { 
    import flash.display.Bitmap; 
    import flash.display.BitmapData; 
    import flash.display.Loader; 
    import flash.display.Sprite; 
    import flash.display.BitmapDataChannel; 
    import flash.display.BlendMode; 

    import flash.events.*; 

    import flash.geom.Point; 
    import flash.geom.Rectangle; 

    import flash.net.URLRequest; 

    [SWF(width='900', height='481', backgroundColor='#FFFFFF', frameRate='30')] 
    public class BitmapExample extends Sprite { 
     private var url:String = "test.jpg"; 
     private var fillColor:uint = 0xFF0000; //0xFF0000 = Red 

     public function BitmapExample() { 
      configureAssets(); 
     } 

     private function configureAssets():void { 
      var loader:Loader = new Loader(); 
      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); 
      loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); 

      var request:URLRequest = new URLRequest(url); 
      loader.load(request); 
     } 

     private function completeHandler(event:Event):void { 
      var loader:Loader = Loader(event.target.loader); 
      var image:Bitmap = Bitmap(loader.content); 
      var bitmapData:BitmapData = image.bitmapData.clone(); 

      //Now we have the bitmapData we can make it grayscale. 
      //First lock the data so it shows no changes while we are doing the changes. 
      bitmapData.lock(); 
      //We now copy the red channel to the blue and the green channel. 
      bitmapData.copyChannel(bitmapData,bitmapData.rect,new Point(),BitmapDataChannel.RED,BitmapDataChannel.BLUE); 
      bitmapData.copyChannel(bitmapData,bitmapData.rect,new Point(),BitmapDataChannel.RED,BitmapDataChannel.GREEN); 
      //After the change we can unlock the bitmapData. 
      bitmapData.unlock(); 


      //Create the overlay with the color set in the private var fillColor 
      var overlay:Bitmap = this.makeOverlayBitMap(bitmapData.width, bitmapData.height, fillColor); 
      //Set the blendMode to darken so it will will be just like the picture in the post. 
      overlay.blendMode = BlendMode.DARKEN; 

      //Add original to the stage 
      image.x = 0; 
      image.y = 0; 
      addChild(image); 

      //Add a copy next to it with the grayscale data 
      var image2:Bitmap = new Bitmap(bitmapData); 
      image2.x = image.width; 
      image2.y = 0; 
      addChild(image2); 

      //Add the overlay to the stage at position of the grayscale 
      overlay.x = image2.x; 
      overlay.y = image2.y; 
      addChild(overlay); 

     } 

     private function makeOverlayBitMap(theWidth:int, theHeight:int, theColor:uint):Bitmap{ 
      var bitmapData:BitmapData = new BitmapData(theWidth,theHeight,false, theColor); 
      var returnBit:Bitmap = new Bitmap(bitmapData); 
      return returnBit; 
     } 

     private function ioErrorHandler(event:IOErrorEvent):void { 
      trace("Unable to load image: " + url); 
     } 
    } 
} 

I espérons que le code et les commentaires dans le feront l'affaire. Si vous avez des questions, demandez-leur. En ignorant l'AS3 un instant, qu'est-ce que cela signifie?