ADOBE/ ActionScript

[AS] adobe air actionscript BMP 로드 하기 관련

AlrepondTech 2016. 7. 26. 00:20
반응형

 

 

=================================

=================================

=================================

 

 

 

 

 

 

출처: http://stackoverflow.com/questions/2106195/loading-bmp-bitmap-and-tiff-file-in-flash-10-using-a-loader

 

 

I am developing a Image uploader using Flash 10. I am using FileReference object to browse images and Loader to show the image:

Sample code:

var tempFileRef:FileReference = FileReference(ev.target); var oLoader:Loader = new Loader(); oLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoad); oLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError); oLoader.loadBytes(tempFileRef.data);

It works fine with .jpg and .gif files but when I browse .bmp or .tiff file, I am getting the error:

Error #2124: Loaded file is an unknown type.

Is there a way to load and display browsed .bmp images from desktop?

Thanks

---------------------------------------------------------------------------------------------------------------------------

 

BMPDecoder class from Spark lib:http://www.libspark.org/svn/as3/BMPDecoder/src/com/voidelement/images/BMPDecoder.as

Example of the usage: http://hi.baidu.com/leyhui/blog/item/d12be8b116ec915308230298.html

Regarding TIFFDecoder, it is still work in progress, but very promising one:

http://code.google.com/p/windowsbitmapdencoder/

 

 

=================================

=================================

=================================

 

 

 

출처: http://blog.flashplatform.kr/201

 

 

오랫만에 블로그로 인사드립니다. (__)

최근에 BMP 파일을 Flex 에서 읽어다 쓸 일이 생겼습니다. 
Flex에서 이미지를 보여주는 컴포넌트인 Image 컴포넌트는 JPEG, PNG, GIF, SWF, SVG 같은 확장자만을 지원하고 BMP은 지원하고 있지 않기 때문에 BMP을 바로 넣을 수는 없습니다.(웹에서 BMP 를 쓰는 무식한 짓을 하면 안되겠죠.. ㅜㅜ 크기도 큰데 말입니다.)  JPG 파일이면 Image 컴포넌트에서 바로 읽어다 쓸 수 있을텐데 참 난감합니다.

그럼 방법이 없느냐? 아닙니다. 
어떤 멋진 분께서 BMPDecoder 를 만들어놓으셨네요! :) 이미 FlexComponent 카페에서도 공유되었던 내용입니다.

http://ntt.cc/2008/10/01/using-bmpdecoder-class-to-load-an-external-bmp-file-rle-compression-support.html


위의 블로그에 들어가보시면 간단한 사용법에 대해서 나오고 BMPDecoder 라이브러리도 보입니다. 다만 BMPDecoder.as 파일이 다운로드가 안되네요. BMPDecoder.as 파일은 '삶의 향기'라는 블로그에  간단한 예제와 함께 업로드 되어 있으니 다운받아 사용하시면 되겠습니다. 

간단하게 FP10 에서 추가된 FileReference의 load() 메소드를 이용해, BMP파일을 불러다  Image 컴포넌트에 넣는 예제를 만들어봤습니다.  예제 구성은 위에서 소개해드린 '삶의 향기' 블로그에 소개된 코드를 이용했습니다.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="{init()}"   
  3.     backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #FFFFFF]">  
  4.     <mx:Script>  
  5.         <![CDATA[  
  6.             import mcmall.core.codec.BMPDecoder;  
  7.             private var fileRef:FileReference;  
  8.             private function init():void  
  9.             {  
  10.                 fileRef = new FileReference();  
  11.                 fileRef.addEventListener(Event.COMPLETE, completeHandler);  
  12.                 fileRef.addEventListener(Event.SELECT, selectHandler);  
  13.             }  
  14.               
  15.             private function bmpLoad():void  
  16.             {  
  17.                 fileRef.browse([new FileFilter("BMP""*.bmp")]);  
  18.             }  
  19.   
  20.             private function completeHandler(event:Event):void {  
  21.                 var byteArray:ByteArray = new ByteArray();  
  22.                 fileRef.data.readBytes(byteArray);  
  23.   
  24.                 var bmpDecoder:BMPDecoder = new BMPDecoder();  
  25.                 var tempBitmap:Bitmap = new Bitmap();  
  26.                 tempBitmap.bitmapData = bmpDecoder.decode( byteArray );   
  27.                 // byteArray BitmapData 로 디코딩     
  28.                   
  29.                 imgBmp.load(tempBitmap);  
  30.                 imgBmp.width = imgBmp.contentWidth;  
  31.                 imgBmp.height = imgBmp.contentHeight;              
  32.             }  
  33.       
  34.             private function selectHandler(event:Event):void {  
  35.                 var file:FileReference = FileReference(event.target);  
  36.                 file.load();  
  37.             }  
  38.   
  39.         ]]>  
  40.     </mx:Script>  
  41.     <mx:VBox height="100%" width="100%"   
  42.         horizontalCenter="0" verticalCenter="0"   
  43.         verticalAlign="middle" horizontalAlign="center" >  
  44.         <mx:Image width="101" height="145" id="imgBmp"/>  
  45.         <mx:Button label="BMP Load" click="{bmpLoad()}"/>  
  46.     </mx:VBox>  
  47. </mx:Application>  

 

BMPDecoder.as 보기

 


BMP 파일을 선택하시면  Image 컴포넌트에 깔끔하게 출력되는 것을 보실 수 있습니다.

하지만 다음과 같은 버그가 존재합니다. 




170픽셀 16bit BMP



171픽셀 16bit BMP 파일

위의 이미지에서 볼수 있는 것 처럼 BMP을 로드했을 때 이미지가 뒤틀려버리는 버그가 존재합니다.
왜 그럴까 한참을 고민했는데, 저희 팀장님이 힌트를 주시더군요. '윈도우어플에서도 비트맵 크기가 홀수일 경우 이미지가 저렇게 깨진다'고 말이죠. 실제로 테스트해보니 위와 같이 16bit이고 이미지의 너비가 홀수일 경우 위 처럼 이미지가 뒤틀려버리는 버그가 있습니다. (24bit, 32bit에서는 괜찮더군요)

이 버그에 해결책으로 저는 아래와 같이 decode() 메소드에서 이미지 너비를 결정해주는 로직 밑에 너비가 홀수일경우 강제로 1픽셀 늘리는 방법을 사용했습니다. 더 좋은 방법이 있을 것 같은데, 아시는 분은 알려주세요 :)
  1. // BMPDecoder 클래스 안의 decode 메소드  
  2. public function decode(data:ByteArray):BitmapData  
  3. {  
  4.     bytes = data;  
  5.     bytes.endian = Endian.LITTLE_ENDIAN;  
  6.     bytes.position = 0;  
  7.     readFileHeader();  
  8.     nInfoSize = bytes.readUnsignedInt();  
  9.     switch (nInfoSize)  
  10.     {  
  11.         case BITMAP_CORE_HEADER_SIZE:  
  12.             readCoreHeader();  
  13.             break;  
  14.         case BITMAP_INFO_HEADER_SIZE:  
  15.             readInfoHeader();  
  16.             break;  
  17.         default:  
  18.             readExtendedInfoHeader();  
  19.             break;  
  20.     }  
  21.   
  22.     if( (nWidth % 2) == 1 ) nWidth += 1;   
  23.     // 너비가 홀수일 경우 강제로 1픽셀 늘리기  
  24.     bd = new BitmapData(nWidth, nHeight);  
  25.     ...  


그럼 좋은 하루되세요!


예제파일 다운로드 :
 

 

 

=================================

=================================

=================================

 

 

 

 

출처: http://ntt.cc/2008/10/01/using-bmpdecoder-class-to-load-an-external-bmp-file-rle-compression-support.html

 

1 function loadBMPFile( url:String ):void {
2   var loader:URLLoader = new URLLoader();
3   loader.dataFormat = URLLoaderDataFormat.BINARY;
4   loader.addEventListener( Event.COMPLETE, onCompleteLoad );
5   loader.load( new URLRequest( url ) );
6 }
7 function onCompleteLoad( e:Event ):void {
8   var loader:URLLoader = e.target as URLLoader;
9   var decoder:BMPDecoder = new BMPDecoder();
10   var bd:BitmapData = decoder.decode( loader.data );
11 }

The following is source code of BMPDecoder class :

1 function loadBMPFile( url:String ):void {
2   var loader:URLLoader = new URLLoader();
3   loader.dataFormat = URLLoaderDataFormat.BINARY;
4   loader.addEventListener( Event.COMPLETE, onCompleteLoad );
5   loader.load( new URLRequest( url ) );
6 }
7 function onCompleteLoad( e:Event ):void {
8   var loader:URLLoader = e.target as URLLoader;
9   var decoder:BMPDecoder = new BMPDecoder();
10   var bd:BitmapData = decoder.decode( loader.data );
11 }
12  
13 The following is source code of BMPDecoder class :
14  
15 package com.voidelement.images {
16   import flash.display.BitmapData;
17   import flash.errors.IOError;
18   import flash.utils.ByteArray;
19   import flash.utils.Endian;
20   public class BMPDecoder {
21     //___________________________________________________________ const
22     private const BITMAP_HEADER_TYPE:String = "BM";
23     private const BITMAP_FILE_HEADER_SIZE:int = 14;
24     private const BITMAP_CORE_HEADER_SIZE:int = 12;
25     private const BITMAP_INFO_HEADER_SIZE:int = 40;
26     private const COMP_RGB      :int = 0;
27     private const COMP_RLE8     :int = 1;
28     private const COMP_RLE4     :int = 2;
29     private const COMP_BITFIELDS:int = 3;
30     private const BIT1 :int = 1;
31     private const BIT4 :int = 4;
32     private const BIT8 :int = 8;
33     private const BIT16:int = 16;
34     private const BIT24:int = 24;
35     private const BIT32:int = 32;
36     //___________________________________________________________ vars
37     private var bytes:ByteArray;
38     private var palette:Array;
39     private var bd:BitmapData;
40     private var nFileSize:uint;
41     private var nReserved1:uint;
42     private var nReserved2:uint;
43     private var nOffbits:uint;
44     private var nInfoSize:uint;
45     private var nWidth:int;
46     private var nHeight:int;
47     private var nPlains:uint;
48     private var nBitsPerPixel:uint;
49     private var nCompression:uint;
50     private var nSizeImage:uint;
51     private var nXPixPerMeter:int;
52     private var nYPixPerMeter:int;
53     private var nColorUsed:uint;
54     private var nColorImportant:uint;
55     private var nRMask:uint;
56     private var nGMask:uint;
57     private var nBMask:uint;
58     private var nRPos:uint;
59     private var nGPos:uint;
60     private var nBPos:uint;
61     private var nRMax:uint;
62     private var nGMax:uint;
63     private var nBMax:uint;
64     /**
65      * Constructor
66      */
67     public function BMPDecoder() {
68       nRPos = 0;
69       nGPos = 0;
70       nBPos = 0;
71     }
72     /**
73      * decoder
74      *
75      * @param BMP file ByteArray
76      */
77     public function decode( data:ByteArray ):BitmapData {
78       bytes = data;
79       bytes.endian = Endian.LITTLE_ENDIAN;
80       bytes.position = 0;
81       readFileHeader();
82       nInfoSize = bytes.readUnsignedInt();
83       switch ( nInfoSize ) {
84         case BITMAP_CORE_HEADER_SIZE:
85           readCoreHeader();
86           break;
87         case BITMAP_INFO_HEADER_SIZE:
88           readInfoHeader();
89           break;
90         default:
91           readExtendedInfoHeader();
92           break;
93       }
94       bd = new BitmapData( nWidth, nHeight );
95       switch ( nBitsPerPixel ){
96         case BIT1:
97           readColorPalette();
98           decode1BitBMP();
99           break;
100         case BIT4:
101           readColorPalette();
102           if ( nCompression == COMP_RLE4 ){
103             decode4bitRLE();
104           } else {
105             decode4BitBMP();
106           }
107           break;
108         case BIT8:
109           readColorPalette();
110           if ( nCompression == COMP_RLE8 ){
111             decode8BitRLE();
112           } else {
113             decode8BitBMP();
114           }
115           break;
116         case BIT16:
117           readBitFields();
118           checkColorMask();
119           decode16BitBMP();
120           break;
121         case BIT24:
122           decode24BitBMP();
123           break;
124         case BIT32:
125           readBitFields();
126           checkColorMask();
127           decode32BitBMP();
128           break;
129         default:
130           throw new VerifyError("invalid bits per pixel : " + nBitsPerPixel );
131       }
132       return bd;
133     }
134     /**
135      * read BITMAP FILE HEADER
136      */
137     private function readFileHeader():void {
138       var fileHeader:ByteArray = new ByteArray();
139       fileHeader.endian = Endian.LITTLE_ENDIAN;
140       try {
141         bytes.readBytes( fileHeader, 0, BITMAP_FILE_HEADER_SIZE );
142         if ( fileHeader.readUTFBytes( 2 ) != BITMAP_HEADER_TYPE ){
143           throw new VerifyError("invalid bitmap header type");
144         }
145         nFileSize  = fileHeader.readUnsignedInt();
146         nReserved1 = fileHeader.readUnsignedShort();
147         nReserved2 = fileHeader.readUnsignedShort();
148         nOffbits   = fileHeader.readUnsignedInt();
149       } catch ( e:IOError ) {
150         throw new VerifyError("invalid file header");
151       }
152     }
153     /**
154      * read BITMAP CORE HEADER
155      */
156     private function readCoreHeader():void {
157       var coreHeader:ByteArray = new ByteArray();
158       coreHeader.endian = Endian.LITTLE_ENDIAN;
159       try {
160         bytes.readBytes( coreHeader, 0, BITMAP_CORE_HEADER_SIZE - 4 );
161         nWidth  = coreHeader.readShort();
162         nHeight = coreHeader.readShort();
163         nPlains = coreHeader.readUnsignedShort();
164         nBitsPerPixel = coreHeader.readUnsignedShort();
165       } catch ( e:IOError ) {
166         throw new VerifyError("invalid core header");
167       }
168     }
169     /**
170      * read BITMAP INFO HEADER
171      */
172     private function readInfoHeader():void {
173       var infoHeader:ByteArray = new ByteArray();
174       infoHeader.endian = Endian.LITTLE_ENDIAN;
175       try {
176         bytes.readBytes( infoHeader, 0, BITMAP_INFO_HEADER_SIZE - 4 );
177         nWidth  = infoHeader.readInt();
178         nHeight = infoHeader.readInt();
179         nPlains = infoHeader.readUnsignedShort();
180         nBitsPerPixel = infoHeader.readUnsignedShort();
181         nCompression = infoHeader.readUnsignedInt();
182         nSizeImage = infoHeader.readUnsignedInt();
183         nXPixPerMeter = infoHeader.readInt();
184         nYPixPerMeter = infoHeader.readInt();
185         nColorUsed = infoHeader.readUnsignedInt();
186         nColorImportant = infoHeader.readUnsignedInt();
187       } catch ( e:IOError ) {
188         throw new VerifyError("invalid info header");
189       }
190     }
191     /**
192      * read the extend info of BITMAP INFO HEADER
193      */
194     private function readExtendedInfoHeader():void {
195       var infoHeader:ByteArray = new ByteArray();
196       infoHeader.endian = Endian.LITTLE_ENDIAN;
197       try {
198         bytes.readBytes( infoHeader, 0, nInfoSize - 4 );
199         nWidth  = infoHeader.readInt();
200         nHeight = infoHeader.readInt();
201         nPlains = infoHeader.readUnsignedShort();
202         nBitsPerPixel = infoHeader.readUnsignedShort();
203         nCompression = infoHeader.readUnsignedInt();
204         nSizeImage = infoHeader.readUnsignedInt();
205         nXPixPerMeter = infoHeader.readInt();
206         nYPixPerMeter = infoHeader.readInt();
207         nColorUsed = infoHeader.readUnsignedInt();
208         nColorImportant = infoHeader.readUnsignedInt();
209         if ( infoHeader.bytesAvailable >= 4 ) nRMask = infoHeader.readUnsignedInt();
210         if ( infoHeader.bytesAvailable >= 4 ) nGMask = infoHeader.readUnsignedInt();
211         if ( infoHeader.bytesAvailable >= 4 ) nBMask = infoHeader.readUnsignedInt();
212       } catch ( e:IOError ) {
213         throw new VerifyError("invalid info header");
214       }
215     }
216     /**
217      * read bitfields
218      */
219     private function readBitFields():void {
220       if ( nCompression == COMP_RGB ){
221         if ( nBitsPerPixel == BIT16 ){
222           // RGB555
223           nRMask = 0x00007c00;
224           nGMask = 0x000003e0;
225           nBMask = 0x0000001f;
226         } else {
227           //RGB888;
228           nRMask = 0x00ff0000;
229           nGMask = 0x0000ff00;
230           nBMask = 0x000000ff;
231         }
232       } else if ( ( nCompression == COMP_BITFIELDS ) && ( nInfoSize < 52 ) ){
233         try {
234           nRMask = bytes.readUnsignedInt();
235           nGMask = bytes.readUnsignedInt();
236           nBMask = bytes.readUnsignedInt();
237         } catch ( e:IOError ) {
238           throw new VerifyError("invalid bit fields");
239         }
240       }
241     }
242     /**
243      * read color palette
244      */
245     private function readColorPalette():void {
246       var i:int;
247       var len:int = ( nColorUsed > 0 ) ? nColorUsed : Math.pow( 2, nBitsPerPixel );
248       palette = new Array( len );
249       for ( i = 0; i < len; ++i ){
250         palette[ i ] = bytes.readUnsignedInt();
251       }
252     }
253     /**
254      * decode 1 bit BMP
255      */
256     private function decode1BitBMP():void {
257       var x:int;
258       var y:int;
259       var i:int;
260       var col:int;
261       var buf:ByteArray = new ByteArray();
262       var line:int = nWidth / 8;
263       if ( line % 4 > 0 ){
264         line = ( ( line / 4 | 0 ) + 1 ) * 4;
265       }
266       try {
267         for ( y = nHeight - 1; y >= 0; --y ){
268           buf.length = 0;
269           bytes.readBytes( buf, 0, line );
270           for ( x = 0; x < nWidth; x += 8 ){
271             col = buf.readUnsignedByte();
272             for ( i = 0; i < 8; ++i ){
273               bd.setPixel( x + i, y, palette[ col >> ( 7 - i ) & 0x01 ] );
274             }
275           }
276         }
277       } catch ( e:IOError ) {
278         throw new VerifyError("invalid image data");
279       }
280     }
281     /**
282      * decode 4bit RLE
283      */
284     private function decode4bitRLE():void {
285       var x:int;
286       var y:int;
287       var i:int;
288       var n:int;
289       var col:int;
290       var data:uint;
291       var buf:ByteArray = new ByteArray();
292       try {
293         for ( y = nHeight - 1; y >= 0; --y ){
294           buf.length = 0;
295           while ( bytes.bytesAvailable > 0 ){
296             n = bytes.readUnsignedByte();
297             if ( n > 0 ){
298               // encode data
299               data = bytes.readUnsignedByte();
300               for ( i = 0; i < n/2; ++i ){
301                 buf.writeByte( data );
302               }
303             } else {
304               n = bytes.readUnsignedByte();
305               if ( n > 0 ){
306                 // abs mode
307                 bytes.readBytes( buf, buf.length, n/2 );
308                 buf.position += n/2;
309                 if ( n/2 + 1 >> 1 << 1 != n/2 ){
310                   bytes.readUnsignedByte();
311                 }
312               } else {
313                 // EOL
314                 break;
315               }
316             }
317           }
318           buf.position = 0;
319           for ( x = 0; x < nWidth; x += 2 ){
320             col = buf.readUnsignedByte();
321             bd.setPixel( x, y, palette[ col >> 4 ] );
322             bd.setPixel( x + 1, y, palette[ col & 0x0f ] );
323           }
324         }
325       } catch ( e:IOError ) {
326         throw new VerifyError("invalid image data");
327       }
328     }
329     /**
330      * decode 4bit (no Compression)
331      */
332     private function decode4BitBMP():void {
333       var x:int;
334       var y:int;
335       var i:int;
336       var col:int;
337       var buf:ByteArray = new ByteArray();
338       var line:int = nWidth / 2;
339       if ( line % 4 > 0 ){
340         line = ( ( line / 4 | 0 ) + 1 ) * 4;
341       }
342       try {
343         for ( y = nHeight - 1; y >= 0; --y ){
344           buf.length = 0;
345           bytes.readBytes( buf, 0, line );
346           for ( x = 0; x < nWidth; x += 2 ){
347             col = buf.readUnsignedByte();
348             bd.setPixel( x, y, palette[ col >> 4 ] );
349             bd.setPixel( x + 1, y, palette[ col & 0x0f ] );
350           }
351         }
352       } catch ( e:IOError ) {
353         throw new VerifyError("invalid image data");
354       }
355     }
356     /**
357      * decode 8bit( RLE Compression )
358      */
359     private function decode8BitRLE():void {
360       var x:int;
361       var y:int;
362       var i:int;
363       var n:int;
364       var col:int;
365       var data:uint;
366       var buf:ByteArray = new ByteArray();
367       try {
368         for ( y = nHeight - 1; y >= 0; --y ){
369           buf.length = 0;
370           while ( bytes.bytesAvailable > 0 ){
371             n = bytes.readUnsignedByte();
372             if ( n > 0 ){
373               // encode data
374               data = bytes.readUnsignedByte();
375               for ( i = 0; i < n; ++i ){
376                 buf.writeByte( data );
377               }
378             } else {
379               n = bytes.readUnsignedByte();
380               if ( n > 0 ){
381                 // abs mode data
382                 bytes.readBytes( buf, buf.length, n );
383                 buf.position += n;
384                 if ( n + 1 >> 1 << 1 != n ){
385                   bytes.readUnsignedByte();
386                 }
387               } else {
388                 // EOL
389                 break;
390               }
391             }
392           }
393           buf.position = 0;
394           for ( x = 0; x < nWidth; ++x ){
395             bd.setPixel( x, y, palette[ buf.readUnsignedByte() ] );
396           }
397         }
398       } catch ( e:IOError ) {
399         throw new VerifyError("invalid image data");
400       }
401     }
402     /**
403      * decode 8bit(no Compression)
404      */
405     private function decode8BitBMP():void {
406       var x:int;
407       var y:int;
408       var i:int;
409       var col:int;
410       var buf:ByteArray = new ByteArray();
411       var line:int = nWidth;
412       if ( line % 4 > 0 ){
413         line = ( ( line / 4 | 0 ) + 1 ) * 4;
414       }
415       try {
416         for ( y = nHeight - 1; y >= 0; --y ){
417           buf.length = 0;
418           bytes.readBytes( buf, 0, line );
419           for ( x = 0; x < nWidth; ++x ){
420             bd.setPixel( x, y, palette[ buf.readUnsignedByte() ] );
421           }
422         }
423       } catch ( e:IOError ) {
424         throw new VerifyError("invalid image data");
425       }
426     }
427     /**
428      * decode 16bit
429      */
430     private function decode16BitBMP():void {
431       var x:int;
432       var y:int;
433       var col:int;
434       try {
435         for ( y = nHeight - 1; y >= 0; --y ){
436           for ( x = 0; x < nWidth; ++x ){
437             col = bytes.readUnsignedShort();
438             bd.setPixel( x, y, ( ( ( col & nRMask ) >> nRPos )*0xff/nRMax << 16 ) + ( ( ( col & nGMask ) >> nGPos )*0xff/nGMax << 8 ) + ( ( ( col & nBMask ) >> nBPos )*0xff/nBMax << 0 ) );
439           }
440         }
441       } catch ( e:IOError ) {
442         throw new VerifyError("invalid image data");
443       }
444     }
445     /**
446      * decode 24bit BMP
447      */
448     private function decode24BitBMP():void {
449       var x:int;
450       var y:int;
451       var col:int;
452       var buf:ByteArray = new ByteArray();
453       var line:int = nWidth * 3;
454       if ( line % 4 > 0 ){
455         line = ( ( line / 4 | 0 ) + 1 ) * 4;
456       }
457       try {
458         for ( y = nHeight - 1; y >= 0; --y ){
459           buf.length = 0;
460           bytes.readBytes( buf, 0, line );
461           for ( x = 0; x < nWidth; ++x ){
462             bd.setPixel( x, y, buf.readUnsignedByte() + ( buf.readUnsignedByte() << 8 ) + ( buf.readUnsignedByte() << 16 ) );
463           }
464         }
465       } catch ( e:IOError ) {
466         throw new VerifyError("invalid image data");
467       }
468     }
469     /**
470      * decode 32bit BMP
471      */
472     private function decode32BitBMP():void {
473       var x:int;
474       var y:int;
475       var col:int;
476       try {
477         for ( y = nHeight - 1; y >= 0; --y ){
478           for ( x = 0; x < nWidth; ++x ){
479             col = bytes.readUnsignedInt();
480             bd.setPixel( x, y, ( ( ( col & nRMask ) >> nRPos )*0xff/nRMax << 16 ) + ( ( ( col & nGMask ) >> nGPos )*0xff/nGMax << 8 ) + ( ( ( col & nBMask ) >> nBPos )*0xff/nBMax << 0 ) );
481           }
482         }
483       } catch ( e:IOError ) {
484         throw new VerifyError("invalid image data");
485       }
486     }
487     /**
488      * check color mask
489      */
490     private function checkColorMask():void {
491       if ( ( nRMask & nGMask ) | ( nGMask & nBMask ) | ( nBMask & nRMask ) ){
492         throw new VerifyError("invalid bit fields");
493       }
494       while ( ( ( nRMask >> nRPos ) & 0x00000001 ) == 0 ){
495         nRPos++;
496       }
497       while ( ( ( nGMask >> nGPos ) & 0x00000001 ) == 0 ){
498         nGPos++;
499       }
500       while ( ( ( nBMask >> nBPos ) & 0x00000001 ) == 0 ){
501         nBPos++;
502       }
503       nRMax = nRMask >> nRPos;
504       nGMax = nGMask >> nGPos;
505       nBMax = nBMask >> nBPos;
506     }
507     /**
508      * print information
509      */
510     public function traceInfo():void {
511       trace("---- FILE HEADER ----");
512       trace("nFileSize: " + nFileSize );
513       trace("nReserved1: " + nReserved1 );
514       trace("nReserved2: " + nReserved2 );
515       trace("nOffbits: " + nOffbits );
516       trace("---- INFO HEADER ----");
517       trace("nWidth: " + nWidth );
518       trace("nHeight: " + nHeight );
519       trace("nPlains: " + nPlains );
520       trace("nBitsPerPixel: " + nBitsPerPixel );
521       if ( nInfoSize >= 40 ){
522         trace("nCompression: " + nCompression );
523         trace("nSizeImage: " + nSizeImage );
524         trace("nXPixPerMeter: " + nXPixPerMeter );
525         trace("nYPixPerMeter: " + nYPixPerMeter );
526         trace("nColorUsed: " + nColorUsed );
527         trace("nColorUsed: " + nColorImportant );
528       }
529       if ( nInfoSize >= 52 ){
530         trace("nRMask: " + nRMask.toString( 2 ) );
531         trace("nGMask: " + nGMask.toString( 2 ) );
532         trace("nBMask: " + nBMask.toString( 2 ) );
533       }
534     }
535   }
536 }

Cheers!

 

=================================

=================================

=================================

 

 

 

출처: http://forums.mediabox.fr/topic/99416-error-2044-ioerrorevent/

 

Bonjour,

Je refais monter ce sujet après moultes recherches. Je suis toujours bloqué malgré les indications postées. J'ai le même type d'erreur pour un chargement dynamique d'images (retournées par une servlet).

Action Script


var chargeur:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://localhost:8080/TO/download"); //retourne un jpeg
chargeur.dataFormat = URLLoaderDataFormat.BINARY;
request.data = "file="+(value as FileVO).path;
chargeur.addEventListener(Event.COMPLETE, finDuChargement);
chargeur.addEventListener(ProgressEvent.PROGRESS, avancement);
chargeur.load(request);

function finDuChargement ( event:Event ) {
//removeChild(progressBar);
//removeChild(pic);
getChildIndex(pic)
var contenu = event.target.data;
creerLoader (contenu)
}
			
function creerLoader ( datas ) {
var chargeur:Loader = new Loader();
chargeur.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, indiquerErreur);
chargeur.loadBytes(datas);
addChild(chargeur);
} 


Voilà l'erreur que je récupère dans la console :
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2124: Le type du fichier chargé est inconnu."]

Je ne sais pas trop comment faire.
Avez vous une piste ?

Merci par avance.

 

 

=================================

=================================

=================================

 

 

 

 

반응형