Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 什么';这段代码怎么了?_Apache Flex_Actionscript 3_Flex4_Flex4.5 - Fatal编程技术网

Apache flex 什么';这段代码怎么了?

Apache flex 什么';这段代码怎么了?,apache-flex,actionscript-3,flex4,flex4.5,Apache Flex,Actionscript 3,Flex4,Flex4.5,我正在尝试用Flex4.5制作一个图像编辑器 然而,有一件小事情并不合适。这是我的密码: private function returnCropIndicatorBmpDataForTopLeft():BitmapData{ var topLeftX:int = 0; var topLeftY:int = 0; var topRightX:int = _bmpData.wid

我正在尝试用Flex4.5制作一个图像编辑器

然而,有一件小事情并不合适。这是我的密码:

            private function returnCropIndicatorBmpDataForTopLeft():BitmapData{

            var topLeftX:int     = 0;
            var topLeftY:int     = 0;

            var topRightX:int    = _bmpData.width;
            var topRightY:int    = 0;

            var bottomRightX:int = _bmpData.width;
            var bottomRightY:int = _bmpData.height;

            var bottomLeftX:int  = 0;
            var bottomLeftY:int  = _bmpData.height;

            var cropIconX:int    = _mouseX;
            var cropIconY:int    = _mouseY;

            var temporaryBitmapData:BitmapData = _bmpData;

            var originalColor:uint;
            var dimmedColor:uint = 0x202020;

            for (var i:int = 0; i < _bmpData.width; i++) 
            {
                for (var j:int = 0; j < _bmpData.height; j++) 
                {
                    originalColor = _bmpData.getPixel(i,j);

                    if(i>cropIconX && j>cropIconY){
                        temporaryBitmapData.setPixel(i,j,originalColor);
                    }else{
                        temporaryBitmapData.setPixel(i,j,dimmedColor);
                    }
                }
            }
            /*
            *by the end of this loop, we have, in the temporaryBitmapData variable, a version of the _bmpData,
            *the area to be cropped out dimmed a little bit.
            */

            return temporaryBitmapData;
        }
private函数returncropindicator或mpdatafortopleft():位图数据{
var topLeftX:int=0;
变量topLeftY:int=0;
var topRightX:int=_bmpData.width;
var-topRightY:int=0;
var bottomRightX:int=_bmpData.width;
var bottomRightY:int=_bmpData.height;
var bottomLeftX:int=0;
var bottomLeftY:int=_bmpData.height;
var cropIconX:int=_mouseX;
变量cropIconY:int=\u mouseY;
var temporaryBitmapData:BitmapData=\u bmpData;
原色变种:uint;
var dimmedColor:uint=0x202020;
对于(变量i:int=0;i<\u bmpData.width;i++)
{
对于(变量j:int=0;j<_bmpData.height;j++)
{
原始颜色=_bmpData.getPixel(i,j);
如果(i>cropIconX&&j>cropIconY){
时间位图数据。设置像素(i,j,原始颜色);
}否则{
时间位图数据。设置像素(i,j,暗显颜色);
}
}
}
/*
*在这个循环结束时,我们在temporaryBitmapData变量中有一个版本的_bmpData,
*要裁剪的区域有点暗了。
*/
返回临时位图数据;
}
如果仔细查看最里面的for循环中的第一个if语句

temporaryBitmapData.setPixel(i,j,原色)

该代码位应执行以下操作:

如果该(i,j)像素位于“待裁剪区域”之外,则使用原始像素颜色重新绘制

这似乎无法让它发挥作用

我用一些硬编码的值(比如,0xFFFFFF代表白色)替换了那一行,它确实起了作用,所以问题不在那里

希望你们能帮助我,我已经花了4个多小时在这上面,已经尝试了很多不同的方法

我在FB4.5中调试了这段代码,并在if语句中设置了一个断点。出于某种原因,_bmpData变量(我想从中获取原始像素颜色)旁边显示了一个小红方块。。。。也许这是某种暗示。。也许它是某种线程“锁定”的??我不知道,希望有人能弄明白


编辑我遇到的问题是:图像的暗显效果很好,但如果我随后将鼠标光标移回暗显的区域,则原始图像不会像预期的那样重新绘制。

那里一定发生了其他事情。。。我刚刚测试了你的代码,对我来说效果很好

package  {

    import flash.display.MovieClip;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.net.*;
    import flash.display.Loader;
    import flash.events.Event;

    public class ImageCropper extends MovieClip {

        protected var _bmpData:BitmapData;
        protected var _mouseX:int;
        protected var _mouseY:int;
        var imageLoader:Loader;

        public function ImageCropper() {
            _mouseX = 80;
            _mouseY = 50;
            imageLoader = new Loader();
            var image:URLRequest = new URLRequest("http://www.travelooce.com/pics/bear_picnic_table.jpg");
            imageLoader.load(image);
            imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, _imageLoaded);
            imageLoader.x = 0;
            imageLoader.y = 0;

        }

        public function _imageLoaded($evt:Event):void {
            _bmpData = new BitmapData(imageLoader.width, imageLoader.height, false);
            _bmpData.draw(imageLoader);
            var bmp2:BitmapData = returnCropIndicatorBmpDataForTopLeft();
            var bmp:Bitmap = new Bitmap(bmp2);
            addChild(bmp);
        }

        private function returnCropIndicatorBmpDataForTopLeft():BitmapData{

            var topLeftX:int     = 0;
            var topLeftY:int     = 0;

            var topRightX:int    = _bmpData.width;
            var topRightY:int    = 0;

            var bottomRightX:int = _bmpData.width;
            var bottomRightY:int = _bmpData.height;

            var bottomLeftX:int  = 0;
            var bottomLeftY:int  = _bmpData.height;

            var cropIconX:int    = _mouseX;
            var cropIconY:int    = _mouseY;

            // This is the important line to change.
            var temporaryBitmapData:BitmapData = _bmpData.clone();

            var originalColor:uint;
            var dimmedColor:uint = 0x202020;

            for (var i:int = 0; i < _bmpData.width; i++) 
            {
                for (var j:int = 0; j < _bmpData.height; j++) 
                {
                    originalColor = _bmpData.getPixel(i,j);

                    if(i>cropIconX && j>cropIconY){
                        temporaryBitmapData.setPixel(i,j,originalColor);
                    }else{
                        temporaryBitmapData.setPixel(i,j,dimmedColor);
                    }
                }
            }
            /*
            *by the end of this loop, we have, in the temporaryBitmapData variable, a version of the _bmpData,
            *the area to be cropped out dimmed a little bit.
            */

            return temporaryBitmapData;
        }
    }

}
包{
导入flash.display.MovieClip;
导入flash.display.BitmapData;
导入flash.display.Bitmap;
导入flash.net。*;
导入flash.display.Loader;
导入flash.events.Event;
公共类ImageCropper扩展了MovieClip{
受保护的变量bmpData:BitmapData;
受保护变量_mouseX:int;
受保护变量_mouseY:int;
var-imageLoader:Loader;
公共函数ImageCropper(){
_mouseX=80;
_老鼠=50;
imageLoader=新加载器();
变量映像:URLRequest=新的URLRequest(“http://www.travelooce.com/pics/bear_picnic_table.jpg");
加载(图像);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,_imageLoaded);
imageLoader.x=0;
imageLoader.y=0;
}
公共函数\u imageLoaded($evt:Event):无效{
_bmpData=新位图数据(imageLoader.width、imageLoader.height、false);
_bmpData.draw(图像加载器);
var bmp2:BitmapData=returnCropIndicatorBmpDataForTopLeft();
var bmp:Bitmap=新位图(bmp2);
addChild(bmp);
}
私有函数returnCropIndicatorBmpDataForTopLeft():BitmapData{
var topLeftX:int=0;
变量topLeftY:int=0;
var topRightX:int=_bmpData.width;
var-topRightY:int=0;
var bottomRightX:int=_bmpData.width;
var bottomRightY:int=_bmpData.height;
var bottomLeftX:int=0;
var bottomLeftY:int=_bmpData.height;
var cropIconX:int=_mouseX;
变量cropIconY:int=\u mouseY;
//这是需要改变的重要路线。
var temporaryBitmapData:BitmapData=_bmpData.clone();
原色变种:uint;
var dimmedColor:uint=0x202020;
对于(变量i:int=0;i<\u bmpData.width;i++)
{
对于(变量j:int=0;j<_bmpData.height;j++)
{
原始颜色=_bmpData.getPixel(i,j);
如果(i>cropIconX&&j>cropIconY){
时间位图数据。设置像素(i,j,原始颜色);
}否则{
时间位图数据。设置像素(i,j,暗显颜色);
}
}
}
/*
*在这个循环结束时,我们在temporaryBitmapData变量中有一个版本的_bmpData,
*要裁剪的区域有点暗了。
*/
返回临时位图数据;
}
}
}
输出:


嗯……调光对我来说也很好。。。但是如果你将鼠标光标移回一个暗显的区域,你的原始图像会被重新绘制吗?@Felipe:Ah-ham我明白你的问题了。您需要更改以更改此
var temporaryBitmapData:BitmapData=\u bmpData
变量te