2014-03-06 21 views
0

這是我在Adobe論壇上發了一個帖子......文字鋸齒/破 - 的Adobe Flash

我新望閃爍,我做了演示文稿作爲的一部分大學任務。

我的問題基本上是這樣的。作爲我的演示文稿的一部分,我有一個照片庫,它使用縮略圖作爲按鈕,然後用UI加載器從我的網絡服務器加載較大圖像的彈出式版本 - 根據https://www.youtube.com/watch?v=Peo_nT9HHa0

該圖像是在photoshop上創建的。它是一個.jpg,在圖像中有文字,在文字下面描述圖像的全部內容。 Photoshop中的文本被設置爲抗鋸齒「平滑」,當我在閃光燈下測試電影時,圖像下方的文字看起來很好 - 就像在Photoshop中一樣。

然而,當我發佈和上傳.swf文件到我的網絡服務器,並通過瀏覽器中查看圖像,文字看起來可怕的 - 所有的鋸齒,如果這是很有意義的打破。

任何想法爲什麼?

他們給我的答覆...

如果您加載的動態圖像,那麼你將不得不平滑屬性真正設置文件(S)已被加載後。因此,如果當前沒有用於完成加載的圖像的偵聽器,則需要一個偵聽器,並使用事件處理函數將smoothing屬性分配給它們中的每一個。

任何人都可以幫助創建此偵聽器和事件處理函數的動作? 我基本上有一個畫廊電影剪輯與按鈕作爲可點擊縮略圖。造成這種情況的動作是...

btnImage1.addEventListener(MouseEvent.CLICK, loadimage1); 

function loadimage1 (event:MouseEvent):void{ 
imagetxt.text = "a"; 
togglewindow.gotoAndPlay(2) 
} 

,然後顯示被點擊縮略圖時,較大的圖像的UI裝載機

if (MovieClip(this.parent).imagetxt.text == "a"){ 
var imgurl:String ="IMAGE URL"; 
var myrequest:URLRequest = new URLRequest(imgurl); 
myloader.load(myrequest); 
} 

回答

0

如圖所示,你應該始終如果平滑上圖像將被縮放。它使用不同的縮放算法,模糊像素而不是刪除它們。請注意,平滑過程要慢得多,但在現代機器上,您不應該注意到它們之間的差異,除非您一次完成數千幅圖像。

實例化後,加入Event.COMPLETE處理程序Loader.contentLoaderInfo

var myLoader = new Loader(); 
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler); 

然後在處理程序中,您可以訪問Bitmap並打開平滑。

function loaderCompleteHandler(e:Event):void { 
    var image:Bitmap = myLoader.content as Bitmap; //Loader.content is typed as a DisplayObject, so we need to cast it as a Bitmap 
    image.smoothing = true; 
} 

而且應該解決這個問題。您可能需要將image對象添加到舞臺而不是myLoader對象。我不認爲你必須這樣做,但我不記得了。

+0

感謝您的答覆。我對這種事情毫無用處,所以請耐心等待。您在上面輸入的動作腳本是在加載圖像的同一幀中進行的?我已將兩行代碼粘貼到最後一張圖像下面的那一行,但問題仍然存在。謝謝 – markthornton90

+0

它應該在同一幀中完成,是的。但是,如果不能分析項目,我認爲我無法進一步幫助你。這是您需要使用的方法。爲了記錄,最好的做法是將所有代碼放在一個圖層中的單個幀上。它不應該分開。 –

0

只需將事件偵聽器添加到加載器。就像這樣:

load.addEventListener(Event.COMPLETE,doneLoad); 

然後在doneLoad功能得到event.data並投它爲位圖,並設置位圖平滑爲true:

var myBitmap:Bitmap= e.target.data as Bitmap; 
myBitmap.smoothing=true; 
//add bitmap to parent .... 
0

我寫給你的通用方法加載圖像,你應該向方法傳遞3個參數:保存大圖像,圖像路徑和矩形以限制圖像邊界並調整它們的大小。這種方法應該足以滿足您的任務。

private function loadImage(holder:DisplayObjectContainer, path:String, bounds:Rectangle):void { 
    var loader:Loader = new Loader(); 
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (e:Event):void { 
     var bitmap:Bitmap = loader.content as Bitmap; 
     if (bitmap != null) { 
      bitmap.smoothing = true; 

      //Resize bitmap to fit bounds 
      var availableRatio:Number = bounds.width/bounds.height; 
      var componentRatio:Number = bitmap.width/bitmap.height; 
      if (componentRatio > availableRatio) { 
       bitmap.width = bounds.width; 
       bitmap.height = bounds.width/componentRatio; 
      } else { 
       bitmap.width = bounds.height * componentRatio; 
       bitmap.height = bounds.height; 
      } 

      //Clear previous 
      var i:uint, len: uint = holder.numChildren, old: Bitmap; 
      for(i; i < len; ++i){ 
       old = holder.removeChildAt(0) as Bitmap; 
       old.bitmapData.dispose(); 
      } 

      //Here you can add some appear animation 
      bitmap.x = bounds.x + ((bounds.width - bitmap.width) >> 1); 
      bitmap.y = bounds.y + ((bounds.height - bitmap.height) >> 1); 
      holder.addChild(bitmap); 
     } 
    }); 
    loader.load(new URLRequest(path)); 
} 

用法:

loadImage(myContainer, "Path-to-Image", new Rectangle(20, 20, 400, 200));