ImageSnapshot でキャプチャ注意点
♥3 |
Line 47 |
Modified 2010-03-11 10:42:20 |
MIT License
archived:2017-03-09 08:16:14
ActionScript3 source code
/**
* Copyright matsu ( http://wonderfl.net/user/matsu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/udrZ
*/
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.core.IUIComponent;
import mx.graphics.ImageSnapshot;
private var _scale:Number = 1.2;
private function init():void
{
testList.dataProvider = myModel.item;
testList.scaleX = testList.scaleY = _scale; // ここでスケール変更しても元の大きさがキャプチャされる
}
private function imageSnapshotButtonClick(_obj:Object):void
{
var _source:IBitmapDrawable = _obj as IBitmapDrawable;
// ここでスケール変更しても元の大きさがキャプチャされる
var _testBitmapData:BitmapData = ImageSnapshot.captureBitmapData(_source);
var _testBitmap:Bitmap = new Bitmap(_testBitmapData);
testImage.addChild(_testBitmap);
// ちゃんと Matrix で設定する。
var _matrix:Matrix = new Matrix(_scale, 0, 0, _scale, 0, 0);
var _hogeBitmapData:BitmapData = ImageSnapshot.captureBitmapData(_source, _matrix);
var _hogeBitmap:Bitmap = new Bitmap(_hogeBitmapData);
hogeImage.addChild(_hogeBitmap);
}
]]>
</mx:Script>
<mx:Model id="myModel">
<items>
<item label="test1" data="hoge1"/>
<item label="test2" data="hoge2"/>
<item label="test3" data="hoge3"/>
<item label="test4" data="hoge4"/>
<item label="test5" data="hoge5"/>
</items>
</mx:Model>
<mx:ApplicationControlBar dock="false">
<mx:Button id="imageSnapshotButton" label="ImageSnapshot" click="imageSnapshotButtonClick(testList);" />
</mx:ApplicationControlBar>
<mx:HBox>
<mx:List id="testList" width="100"/>
<mx:Image id="testImage" width="100"/>
<mx:Image id="hogeImage" width="100"/>
</mx:HBox>
</mx:Application>