2013-03-27 78 views
0

請幫我ㅠㅠFLEX:調整圖像大小後,imageRotate無法正常工作

我正在製作ImageEditor。但我有一個圖像旋轉功能的問題。

當我加載圖像,然後旋轉它,旋轉功能工作得很好。

但調整大小(寬,高)加載圖片後,旋轉工作可笑...

Pixed圖像的寬度,高度,它只能旋轉圖片的內容..

其結果是,圖像質量去down ...

這是一個屏幕截圖。

哦..我不能發佈圖片..因爲聲譽限制...: - <

http://blog.naver.com/hago89n/150164439917

請訪問我的博客,並確認截圖..

你能理解我問題?

嗯..代碼是在這裏

//調整按鈕單擊處理

private function btn_resize_clickHandler(event:MouseEvent):void 
{ 
     image.width = parseInt(ti_width.text.toString()); 
    image.height = parseInt(ti_height.text.toString()); 
} 

//旋轉按鈕單擊處理

private function btn_rotateCCW_clickHandler(event:MouseEvent):void 
{//Rotate Counter ClockWise 
    var o_rotateimage:RotateImage = new RotateImage(); 
    o_rotateimage.rotateCCW(image); 
} 

//旋轉功能RotateImage.as

public function rotateCCW(image:Image):void 
{ 
    m = new Matrix();  
    m.rotate(Math.PI/2); 
    m.tx = image.height; 
    var bd:BitmapData = new BitmapData(image.height as int, image.width as int); 
    bd.draw(image, m); 
    image.source = new Bitmap(bd); 
} 
+0

嗨,我不知道我明白你的問題很好。看看我的例子。這是你想要的嗎? http://it-skills.su/sosamples/webspark46/imageeditor/SO_ImageEditor.html – Anton 2013-03-31 23:34:02

回答

0

我認爲你應該爲兩個操作做一個矩陣變換。 如果你只是改變你的圖像對象的大小,它在任何情況下都不能正常工作。

這裏是我的代碼this的例子。

//應用

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      minWidth="955" minHeight="600"> 

<fx:Script> 
    <![CDATA[ 
     import com.imageeditor.RotateImage; 

     [Embed(source="/assets/img/chart.png")] 
     [Bindable] 
     public var chartPng:Class; 

     private var o_rotateimage:RotateImage = new RotateImage(); 

     private function btn_resize_clickHandler(event:MouseEvent):void 
     { 
      o_rotateimage.scale(image, int(ti_width.text)/image.width, int(ti_height.text)/image.height); 
     } 

     private function btn_rotateCCW_clickHandler(event:MouseEvent):void 
     { 
      o_rotateimage.rotateCCW(image); 
     } 
    ]]> 
</fx:Script> 

<s:VGroup x="10" y="10"> 
    <s:HGroup> 
     <s:TextInput id="ti_width" text="300" width="40"/> 
     <s:TextInput id="ti_height" text="200" width="40"/> 

     <s:Button label="Resize" click="btn_resize_clickHandler(event)"/> 
     <s:Button label="Rotate" click="btn_rotateCCW_clickHandler(event)"/> 
    </s:HGroup> 
    <s:HGroup width="800" height="600" horizontalAlign="center" verticalAlign="middle"> 
     <s:Image id="image" source="{chartPng}" width="600" height="400"/> 
    </s:HGroup> 

</s:VGroup> 
</s:Application> 

//RotateImage.as

package com.imageeditor 
{ 
import flash.display.Bitmap; 
import flash.display.BitmapData; 
import flash.geom.Matrix; 

import spark.components.Image; 

public class RotateImage 
{ 
    private var m:Matrix; 

    public function rotateCCW(image:Image):void 
    { 
     var w:int = image.width; 
     var h:int = image.height; 

     m = new Matrix();  
     m.rotate(Math.PI/2); 
     m.tx = image.height; 
     var bd:BitmapData = new BitmapData(image.height as int, image.width as int); 
     bd.draw(image, m); 

     image.width = h; 
     image.height = w; 

     image.source = new Bitmap(bd); 
    } 

    public function scale(image:Image, kx:Number, ky:Number):void 
    { 
     var w:int = image.width; 
     var h:int = image.height; 

     m = new Matrix(); 
     m.scale(kx, ky); 

     var bd:BitmapData = new BitmapData(w*kx as int, h*ky as int); 
     bd.draw(image, m); 

     image.width = w*kx; 
     image.height = h*ky; 

     image.source = new Bitmap(bd); 
    } 
} 
} 
+0

thanx !!!你是我的天使! – phalanx89 2013-04-04 04:33:00

相關問題