Finding a pixel’s color value using the Bitmap classes and getPixel()

简介:
This example loads an image and then uses a combination of the Bitmap and BitmapData classes to determine the color value under the mouse cursor. Pretty basic, but kind of neat. Maybe? Sorta?
复制代码
<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2007/08/02/finding-a-pixels-color-value-using-the-bitmap-classes-and-getpixel/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white" >

    
< mx:Script >
        
<![CDATA[
            private var bm:Bitmap;
            private var bmd:BitmapData;

            private function image_complete(evt:Event):void {
                /* Create Bitmap from Image content. */
                bm = img.content as Bitmap;

                /* Create new BitmapData object. */
                bmd = new BitmapData(img.contentWidth, img.contentHeight);

                /* Draw Bitmap into BitmapData. */
                bmd.draw(bm.bitmapData);
            }

            private function image_mouseMove(evt:MouseEvent):void {
                /* Get the pixel currently under the mouse cursor. */
                var color:int = bmd.getPixel(evt.localX, evt.localY);

                /* Convert the color value from a number to Hex string. */
                var colorStr:String = color.toString(16).toUpperCase();

                /* Set the swatch Box instance's backgroundColor style to the color under the mouse cursor. */
                swatch.setStyle("backgroundColor", color);

                /* Make sure colorStr is at least 6 characters. */
                colorStr = "000000" + colorStr;

                /* Make sure colorStr is at MOST 6 characters. */
                lbl.text = "#" + colorStr.substr(colorStr.length - 6);
            }
        
]]>
    
</ mx:Script >

    
< mx:Zoom  id ="zoom"   />

    
< mx:VBox >
        
< mx:Image  id ="img"  source ="image1.jpg"  completeEffect ="{zoom}"  complete ="image_complete(event);"  mouseMove ="image_mouseMove(event)"   />

        
< mx:HBox >
            
< mx:Box  id ="swatch"  width ="{lbl.height} "  height ="{lbl.height}"   />
             < mx:Label  id ="lbl"  width ="100"  fontFamily ="_typewriter"  fontSize ="16"   />
        
</ mx:HBox >
    
</ mx:VBox >

</ mx:Application >
复制代码






相关文章
|
1月前
GEE错误——Layer error: Image.connectedPixelCount: Segment size calculation on floating point bands is n
GEE错误——Layer error: Image.connectedPixelCount: Segment size calculation on floating point bands is n
42 0
|
1月前
|
算法 光互联 计算机视觉
Locally Adaptive Color Correction for Underwater Image Dehazing and Matching
该文提出了一种新颖的水下图像处理方法,结合颜色转移和局部调整来校正颜色,以应对水下光照和散射造成的图像退化。传统颜色转移方法基于全局参数,不适应水下场景中颜色变化的局部性质。文章中,作者通过融合策略,利用光衰减水平估计来实现局部颜色校正。首先,通过暗通道先验恢复彩色补偿图像,然后估计光衰减图。接着,创建一个合成图像,该图像的统计特性代表高衰减区域,用于颜色转移。最后,通过加权融合初始图像和颜色转移图像,生成最终的颜色校正图像。这种方法旨在提高水下图像的对比度和颜色准确性,特别关注高衰减区域。
33 1
|
7月前
Limits: MIN_INFLATE_RATIO: 0.010000, Entry: word/media/image5.png
Limits: MIN_INFLATE_RATIO: 0.010000, Entry: word/media/image5.png
104 0
|
6月前
|
JavaScript
image-conversion
image-conversion
143 0
[Accessibility] Missing contentDescription attribute on image
[Accessibility] Missing contentDescription attribute on image
151 0
[Accessibility] Missing contentDescription attribute on image
|
机器学习/深度学习
Leetcode-Easy 887. Projection Area of 3D Shapes
Leetcode-Easy 887. Projection Area of 3D Shapes
112 0
Leetcode-Easy 887. Projection Area of 3D Shapes
|
XML JavaScript 前端开发
Tutorial: Generate BBox or Rectangle to locate the target obejct
Tutorial: Generate BBox or Rectangle to locate the target obejct      1 clc;close all;clear all; 2 Img=imread('/home/wangxiao/Documents/files/Vis...
1047 0