2009/06/22 | 17:06 pm
ZipされたJPEGを扱う
Spark Project にコミットされてる tarotarorg さんの ZipLoader 使って zip ファイルをロードして、そのなかにある JPEG ファイルを表示するサンプル
↓ とりあえず、コミットされてるサンプルをそのまま改造したヤツです。
同階層に sample_image.jpg って画像を格納した uploads という zip されたフォルダがあるのが想定です。
/*
* Copyright 2008 tarotarorg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.IOErrorEvent;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.events.Event;
import org.tarotaro.flash.pv3d.ZipLoader;
[SWF(width="640", height="480", backgroundColor="#ffffff")]
/**
* ZipLoaderの使用例
* @see org.tarotro.flash.pv3d.ZipLoader
* @author 太郎
*/
public class ZipLoaderSample extends Sprite
{
private var byteArray:ByteArray;
private var loader:Loader;
private var bmpd:BitmapData;
public function ZipLoaderSample()
{
var zipLoader:ZipLoader = new ZipLoader();
zipLoader.addEventListener(Event.COMPLETE, zipLoadComplete);
zipLoader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void {
trace("IOエラー:", e);
});
zipLoader.dataFormat = URLLoaderDataFormat.BINARY;
zipLoader.load(new URLRequest("uploads.zip://uploads/sample_image.jpg"));
}
private function zipLoadComplete(e:Event):void
{
trace("zipファイルのロード完了");
byteArray = e.target.data;
loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, getBitmapData );
// ここで取得した ByteArray を loadBytes() にぶち込む
loader.loadBytes( byteArray );
};
private function getBitmapData( e:Event ):void
{
trace("ByteArrayファイルのロード完了");
bmpd = Bitmap( e.target.content ).bitmapData;
addChild( new Bitmap( bmpd ) );
}
}
}
あぁ、なんてステキライブラリ!
でも、このままだと、画像の名前とかを自分で指定しないといけないので、要改造ですね。
papervision3d で使われてる nochump.utils.zip.*; とかを見てみたら分かりそうな気がしますです。
CATEGORY
POSTED
jam


COMMENT
0 Comment