开发者

Clipping an ImageSnapshot in Flex

I'm using the ImageSnapshot.captureImage() method to screen capture a map image which is 2305 pixels high and 1134 pixels wide. I'm then trying to clip that image to one which is 1100 pixels high and 775 pixels wide.

            public function grabScreenMapImage2():void {
            // use ppi of 100 for testing
            v开发者_运维知识库ar ppi = 100;
            var mapHeightInPixels = 1100
            var mapWidthInPixels = 775

            var snapImage:ImageSnapshot = ImageSnapshot.captureImage(myMap, ppi, new JPEGEncoder());

            var bitmapData:BitmapData = new BitmapData(mapWidthInPixels, mapHeightInPixels);    

            var pixels:ByteArray = new ByteArray();
            pixels = snapImage.data;
            pixels.position = 0; 

            var clipRect:Rectangle = new Rectangle(0,0,mapWidthInPixels, mapHeightInPixels);

            bitmapData.setPixels(clipRect, pixels);

        }

However, I'm getting an error #2030 - end of file was encountered on my call to setPixels(), and cannot for the life of me work out why.

Any help greatly appreciated!

Thanks,

DrBacchus


This works for me. I zoom in on the original bitmap, then crop it into a new image the same size as the old one.

var myScaleFactor:Number = 1/3;
var zoomArea:Rectangle = bitmapData.rect;
zoomArea.inflate(zoomArea.width * imageScale, zoomArea.height * myScaleFactor);
var croppedImage = new BitmapData(zoomArea.width ,zoomArea.height,false,0xCCCCCC);
croppedImage.copyPixels(imageData,zoomArea,new Point(0,0));
var newImage = new BitmapAsset(croppedImage);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜