在线签名,并保存到本地

saveImgGroup的大小由里面的图片决定。

<s:Group  top="75" width="1440" height="830" horizontalCenter="0">
   <!--相片-->
   <s:Group id="saveImgGroup" horizontalCenter="0" verticalCenter="0">
    <s:BitmapImage id="signPhoto" maxWidth="1440" maxHeight="830" horizontalCenter="0"
       scaleMode="letterbox" source="http://121.0.0.1/baozhi/2.png" verticalCenter="0"/>
    <s:Group id="drawWords" width="{signPhoto.width}" height="{signPhoto.height}"
       horizontalCenter="0" verticalCenter="0"/>
   </s:Group>
   
  </s:Group>

 

 

注:saveBitmapData=new BitmapData(saveImgGroup.width,saveImgGroup.height,true,0);
   saveBitmapData.draw(saveImgGroup);

最后保存的图片的大小是由saveImgGroup.width,saveImgGroup.height决定的,而saveBitmapData.draw()会在saveImgGroup的左上角截取大小为

saveImgGroup.width,saveImgGroup.height的区域。

 

/**
   *在线保存图片
   * */
  private var saveBitmapData:BitmapData;
  private function saveBtnClickHandler(evt:MouseEvent):void
  {
   saveBitmapData=new BitmapData(saveImgGroup.width,saveImgGroup.height,true,0);
   saveBitmapData.draw(saveImgGroup);
   var imgByteArray:ByteArray=PNGEncoder.encode(saveBitmapData);
   var file:File=new File("E:\\PhotoAndSignature\\signImg\\100.png");
   var fs:FileStream=new FileStream();
   try
   {
    fs.open(file, FileMode.WRITE);
    fs.writeBytes(imgByteArray);
    fs.close();
   }
   catch (e:Error)
   {
    trace(e.message);
   }
  }

posted @ 2014-06-06 18:30  dongyl  Views(535)  Comments(0Edit  收藏  举报