用FLEX做可放大缩小,旋转的相册。可与java,net通信。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
verticalAlign="top" paddingLeft="0" paddingBottom="0" paddingRight="0" width="100%" height="100%"
backgroundColor="white" initialize="GetQueryStringValue()" horizontalAlign="left" backgroundImage="@Embed(source='bar.png')">
<mx:String id="deg">°</mx:String>
<mx:Style source="showpic_css.css" />
<mx:Style>
Alert
{
font-size: 18pt;
font-weight: bold;
}
AlertMessage
{
font-size: 18pt;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.containers.Tile;
import mx.messaging.messages.ErrorMessage;
import mx.core.UIComponent;
import mx.managers.DragManager;
import mx.core.DragSource;
import flash.net.URLRequest;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.printing.*;
import mx.events.CloseEvent;
import flash.printing.PrintJob;
import mx.controls.Image;
public var offsetX:Number;
public var offsetY:Number;
public var rpXml:XML=<newxml/>;
public var ScanID:String;
public var History:String;
public var Origin:String;
public var Operator:String;
public var imgWidth:Number;
private function GetQueryStringValue():void
{
try{
var strUrl:String=flash.external.ExternalInterface.call("GetPatientID", ["ScanID"]).toString();
ScanID=strUrl.substring(strUrl.indexOf("?")+8,strUrl.indexOf("#"));
History=strUrl.substring(strUrl.indexOf("#")+9,strUrl.indexOf("*"));
Operator=strUrl.substring(strUrl.indexOf("*")+10,strUrl.indexOf("&"));
Origin=strUrl.substring(strUrl.indexOf("&")+8,strUrl.length);
if(ScanID.length>0){
addHandle(ScanID);
}
}catch(e:Error){
Alert.show("没有图片信息!请重新选择。");
}
//javascript代码
// function GetPatientID(queryStr)
// { var showmenu=document.getElementById("ShowImage");
// showmenu.Menu=false;
// var url = window.top.location.toString();
// return url;
// }
}
private function addHandle(scanId:String):void
{
try{
mysercrice.url="../ImageSearch/MakeImageV2.aspx";
mysercrice.url+="?scanId="+scanId+"&History="+History;
mysercrice.send();
}catch(e:ErrorMessage){
Alert.show("服务器异常"+e.toString());
}
}
private function httpHandle(e:ResultEvent):void
{
try{
var x:int=e.result.newxml.imgitme.length as int;
if(x>0)
{
for(var i:int=0;i<x;i++){
var rp2Xml:XML=<imgitme/>;
rp2Xml.id = e.result.newxml.imgitme[i].id;
rp2Xml.imageId=e.result.newxml.imgitme[i].imgId;
rp2Xml.least = e.result.newxml.imgitme[i].least;
rp2Xml.most = e.result.newxml.imgitme[i].most;
rp2Xml.postil = e.result.newxml.imgitme[i].postil;
rpXml.appendChild(rp2Xml);
}
}else{
var rp2Xml:XML=<imgitme/>;
rp2Xml.id = e.result.newxml.imgitme.id;
rp2Xml.imageId=e.result.newxml.imgitme.imgId;
rp2Xml.least = e.result.newxml.imgitme.least;
rp2Xml.most = e.result.newxml.imgitme.most;
rp2Xml.postil = e.result.newxml.imgitme.postil;
rpXml.appendChild(rp2Xml);
}
//rp.dataProvider=rpXml.imgitme;
firstImg();
}catch(e:ErrorMessage){
Alert.show("没有影像信息"+e.toString());
}
}
private function radiansToDegrees(radians:Number):Number {
return (radians * (180 / Math.PI));
}
private function degreesToRadians(degrees:Number):Number {
return (degrees * (Math.PI / 180));
}
public function zoom_in():void{
img1.width+=100;
img1.height+=100;
}
public function zoom_out():void{
if(img1.width>200)
{
img1.width-=100;
img1.height-=100;
}
}
public function img_rotation_deasil():void{
img1.rotation+=90;
if(img1.rotation==90){
img1.y=0;
if(img1.x<this.width)
img1.x=img1.height+(this.width-img1.height)-170;
else
img1.x=this.width-(this.width-img1.height);
}
if(img1.rotation==180){
img1.x=img1.width;
img1.y=this.height/2+200;
}
if(img1.rotation==-90){
img1.x=100;
img1.y=this.height-100;
}
if(img1.rotation==0){
img1.x=200;img1.y=10;
}
}
public function img_anticlockwise():void{
img1.rotation-=90;
if(img1.rotation==90){
img1.y=0;
if(img1.x<this.width)
img1.x=img1.height+(this.width-img1.height)-170;
else
img1.x=this.width-(this.width-img1.height);
}
if(img1.rotation==-180){
img1.x=img1.width;
img1.y=this.height/2+200;
}
if(img1.rotation==-90){
img1.x=100;
img1.y=this.height-100;
}
if(img1.rotation==0){
img1.x=5;img1.y=10;
}
}
public function img_down_Drag(event:MouseEvent, value:uint):void{
img1.buttonMode=true;
img1.useHandCursor=false;
imgWidth=img1.width;
offsetX = event.stageX - img1.x;
offsetY = event.stageY - img1.y;
this.img_move(event);
}
public function img_move(event:MouseEvent):void{
img1.x = event.stageX - offsetX;
img1.y = event.stageY - offsetY;
img1.startDrag(false,null);
}
private function img_Up_stop(event:MouseEvent):void{
img1.stopDrag();
img1.width=imgWidth;
}
public function sendImagUrl(event:Event):void{
var imgXml:XML=event.currentTarget.getRepeaterItem()as XML;
img1.source=imgXml.child("most");
imgId.text=imgXml.child("id");
setPostil(imgXml.child("postil"));
imageId.text=imgXml.child("imageId");
img1.rotation=0;
//Alert.show(imgXml.child("most"));
}
public function setPostil(text:String):void{
img1.x=5;img1.y=5;
if(text.length>0){
//postil.text=text;
}else{
//postil.text="当前影像没有批注";
}
}
public function supImg():void{
var supNode:XMLList=rpXml.children();
var node:XML;
var sup:int=int(imgId.text);
for each(node in supNode){
if(node.id==(sup-1).toString()){
img1.source=node.most;
imgId.text=node.id;
setPostil(node.postil);
img1.rotation=0;
}
}
}
public function nextImg():void{
var nextNode:XMLList=rpXml.children();
var node:XML;
var next:int=int(imgId.text);
for each(node in nextNode){
if(node.id==(next+1).toString()){
img1.source=node.most;
imgId.text=node.id;
setPostil(node.postil);
img1.rotation=0;
}
}
}
public function firstImg():void{
var firstNode:XMLList=rpXml.children();
var node:XML;
for each(node in firstNode){
if(node.id=="1"){
img1.source=node.most;
imgId.text=node.id;
setPostil(node.postil);
imageId.text=node.imageId;
img1.rotation=0;
}
}
}
public function lastlyImg():void{
var lastlyNode:XMLList=rpXml.children();
var node:XML;
for each(node in lastlyNode){
if(node.id==lastlyNode.length().toString()){
img1.source=node.most;
imgId.text=node.id;
setPostil(node.postil);
imageId.text=node.imageId;
img1.rotation=0;
}
}
}
public function link_remark():void{
var urlid:int=int(imgId.text);
var url:String="../Evaluate/Add.aspx?ID="+imageId.text+"&SCANID="+ScanID+"&ORIGIN="+Origin+"&Operator="+Operator;
navigateToURL(new URLRequest(url), "_blank");
}
public function link_entry():void{
var urlid:int=int(imgId.text);
var url:String="../Evaluate/ScanIdEvaluate.aspx?ScanID="+ScanID+"&ORIGIN="+Origin+"&Operator="+Operator;
navigateToURL(new URLRequest(url), "_blank");
}
private function secondClickHandler():void {
Alert.yesLabel="单张打印";
Alert.okLabel="批量打印";
Alert.noLabel="取消";
Alert.buttonWidth=100;
Alert.buttonHeight=50;
Alert.show("请选择操作","影像打印",7,this,doPrint);
}
public function doPrint(event:CloseEvent):void {//打印
if(event.detail==Alert.YES){
var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start()) {
// printJob.pageWidth=;
//printJob.pageHeight=;
printJob.addObject(img1);
}
printJob.send();
}
if(event.detail==Alert.OK){
var supNode:XMLList=rpXml.children();
var node:XML;
// for each(node in supNode){
var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start()) {
// img1.source=node.most;;
// img1.rotation=0;
try {
printJob.addObject(img1,"600");
}catch(e:Error){
Alert.show("打印错误!");
}
}
printJob.send();
// }
}
}
]]>
</mx:Script>
<mx:HTTPService id="mysercrice" showBusyCursor="true" result="httpHandle(event);" useProxy="false"/>
<mx:Canvas bottom="0" top="0" right="0" label="Canvas2" width="100%" height="100%" backgroundColor="#FCFDFE" horizontalScrollPolicy="off" includeInLayout="true" autoLayout="true" borderColor="#CDD1D4" >
<mx:VBox height="100%" width="100%" paddingLeft="0" paddingRight="0" paddingBottom="0" left="0" right="0" top="0">
<mx:Canvas id="imgCanvas" left="0" right="0" height="100%" width="100%" color="#FBFDFD" backgroundColor="#83ACE4" >
<mx:Image id="img1" mouseUp="img_Up_stop(event)"
width="100%" autoLoad="true" mouseDown="img_down_Drag(event, 1)" x="5" y="5"/>
<mx:Grid id="gr"></mx:Grid>
</mx:Canvas>
</mx:VBox>
</mx:Canvas>
<mx:ApplicationControlBar dock="true" >
<mx:Label id="lbl1" text="影像显示" fontSize="12" fontFamily="Georgia" fontWeight="bold" color="#E3461C"/>
<mx:Label text="当前第" color="#F42B0B" fontSize="12"/>
<mx:Label id="imgId" text="1" color="#F42B0B" fontSize="12"/>
<mx:Label text="张影像" color="#F42B0B" fontSize="12"/>
<mx:Button label="放大" buttonDown="zoom_in()"/>
<mx:Button label="缩小" buttonDown="zoom_out()"/>
<mx:Button label="顺时针" buttonDown="img_rotation_deasil()"/>
<mx:Button label="逆时针" buttonDown="img_anticlockwise()"/>
<mx:Button label="上一张" buttonDown="supImg()"/>
<mx:Button label="下一张" buttonDown="nextImg()"/>
<mx:Button label="第一张" buttonDown="firstImg()"/>
<mx:Button label="最后一张" buttonDown="lastlyImg()"/>
<mx:Button label="打印" buttonDown="secondClickHandler()"/>
<mx:Button label="影像评论" buttonDown="link_remark()"/>
<mx:Button label="条码评论" buttonDown="link_entry()"/>
<mx:Label id="imageId" visible="false"/>
<mx:Label id="lbl2" />
</mx:ApplicationControlBar>
<!-- <mx:Tile id="myTile" direction="horizontal" borderStyle="solid" horizontalGap="0" verticalGap="0" height="100%" visible="false"
paddingLeft="0" paddingTop="0" paddingBottom="0" paddingRight="0" horizontalAlign="left" verticalAlign="top" bottom="0" left="0" right="0" top="0" tileHeight="80" tileWidth="80" color="#E31212" backgroundColor="#83ACE4">
<mx:Repeater id="rp" width="100%" height="100%" dataProvider="" >
<mx:Image id="imgList" source="{rp.currentItem.most}" click="sendImagUrl(event)" width="140" height="140"
bottom="0" />
<mx:Label text="第{rp.currentItem.id}张" paddingBottom="0" paddingRight="2" paddingLeft="5" height="20"/>
</mx:Repeater>
</mx:Tile>-->
</mx:Application>