0

请帮帮我ㅠㅠ

我正在制作 ImageEditor。但我对图像旋转功能有疑问。

当我加载图像然后旋转它时,旋转功能工作得很好。

但是在调整大小(宽度,高度)加载图像后,旋转工作可笑......

像素图像的宽度,高度,它只旋转图像的内容..

结果画质下降...

这是截图。

哦..我不能发布图片..因为声誉限制... :-<

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);
}
4

1 回答 1

0

我认为您应该对这两种操作进行矩阵转换。如果您只是更改 Image 对象的大小,则并非在所有情况下都可以正常工作。

这是我的这个例子的代码。

//应用

<?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>

//旋转图像.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);
    }
}
}
于 2013-04-02T10:05:31.793 回答