• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            S.l.e!ep.¢%

            像打了激速一樣,以四倍的速度運轉,開心的工作
            簡單、開放、平等的公司文化;尊重個性、自由與個人價值;
            posts - 1098, comments - 335, trackbacks - 0, articles - 1
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            AS3 bitmapdata與bytearray轉換

            Posted on 2010-06-30 17:49 S.l.e!ep.¢% 閱讀(3537) 評論(0)  編輯 收藏 引用 所屬分類: Flash
            bitmapdata.getpixel 方法是ActionScript 3.0中的一個新方法,可以把矩形內的像素讀取成bytearray,但是這種bytearray又不能直接用loader.loadbytes來讀,一 讀就會出現IOERROR。

            為了達到可以直接用loader.loadbytes讀取的目的,找了一下百度和GOOGLE,找到了以下方法,有需要的可以用用。

            PS 以下代碼轉自互聯網,牛C網只負責整理
            /*
            Copyright (c) 2007 Trevor McCauley - www.senocular.com
            Permission is hereby granted, free of charge, to any person
            obtaining a copy of this software and associated documentation
            files (the "Software"), to deal in the Software without
            restriction, including without limitation the rights to use,
            copy, modify, merge, publish, distribute, sublicense, and/or sell
            copies of the Software, and to permit persons to whom the
            Software is furnished to do so, subject to the following
            conditions:
            The above copyright notice and this permission notice shall be
            included in all copies or substantial portions of the Software.
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
            EXPRESS or IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
            OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS or COPYRIGHT
            HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES or OTHER LIABILITY,
            WHETHER IN AN ACTION OF CONTRACT, TORT or OTHERWISE, ARISING
            FROM, OUT OF or IN CONNECTION WITH THE SOFTWARE or THE USE or
            OTHER DEALINGS IN THE SOFTWARE.
            */
            package com.senocular.images {
            import flash.display.BitmapData;
            import flash.geom.Matrix;
            import flash.utils.ByteArray;
            import flash.utils.Endian;
            public class BMPEncoder {
            /**
            * Converts a BitmapData instance into a 32-bit
            * BMP image.
            * @param bitmapData A BitmapData instance of the image
            * desired to have converted into a Bitmap (BMP).
            * @return A ByteArray containing the binary Bitmap (BMP)
            * representation of the BitmapData instance passed.
            */
            public static function encode(bitmapData:BitmapData):ByteArray {
            // image/file properties
            var bmpWidth:int = bitmapData.width;
            var bmpHeight:int = bitmapData.height;
            var imageBytes:ByteArray = bitmapData.getPixels(bitmapData.rect);
            var imageSize:int = imageBytes.length;
            var imageDataOffset:int = 0x36;
            var fileSize:int = imageSize + imageDataOffset;
            // binary BMP data
            var bmpBytes:ByteArray = new ByteArray();
            bmpBytes.endian = Endian.LITTLE_ENDIAN; // byte order
            // header information
            bmpBytes.length = fileSize;
            bmpBytes.writeByte(0x42); // B
            bmpBytes.writeByte(0x4D); // M (BMP identifier)
            bmpBytes.writeInt(fileSize); // file size
            bmpBytes.position = 0x0A; // offset to image data
            bmpBytes.writeInt(imageDataOffset);
            bmpBytes.writeInt(0x28); // header size
            bmpBytes.position = 0x12; // width, height
            bmpBytes.writeInt(bmpWidth);
            bmpBytes.writeInt(bmpHeight);
            bmpBytes.writeShort(1); // planes (1)
            bmpBytes.writeShort(32); // color depth (32 bit)
            bmpBytes.writeInt(0); // compression type
            bmpBytes.writeInt(imageSize); // image data size
            bmpBytes.position = imageDataOffset; // start of image data...
            // write pixel bytes in upside-down order
            // (as per BMP format)
            var col:int = bmpWidth;
            var row:int = bmpHeight;
            var rowLength:int = col * 4; // 4 bytes per pixel (32 bit)
            try {
            // make sure we're starting at the
            // beginning of the image data
            imageBytes.position = 0;
            // bottom row up
            while (row--) {
            // from end of file up to imageDataOffset
            bmpBytes.position = imageDataOffset + row*rowLength;
            // read through each column writing
            // those bits to the image in normal
            // left to rightorder
            col = bmpWidth;
            while (col--) {
            bmpBytes.writeInt(imageBytes.readInt());
            }
            }
            }catch(error:Error){
            // end of file
            }
            // return BMP file
            return bmpBytes;
            }
            }
            }
            99久久精品无码一区二区毛片 | 日产精品久久久一区二区| 国产精品美女久久久久av爽| 精品久久久久久无码专区不卡| 久久久久久精品免费看SSS| 日韩欧美亚洲国产精品字幕久久久 | 色偷偷偷久久伊人大杳蕉| 色欲久久久天天天综合网| 无码国产69精品久久久久网站| 一本色道久久HEZYO无码| 囯产精品久久久久久久久蜜桃| 久久精品一本到99热免费| 久久久久高潮综合影院| 国产成人综合久久精品红| 久久伊人五月天论坛| 亚洲国产香蕉人人爽成AV片久久 | 99久久国产免费福利| 99久久精品国产一区二区蜜芽 | 久久精品国产91久久综合麻豆自制| 精品久久8x国产免费观看| 伊人久久大香线蕉精品| 久久免费观看视频| 少妇久久久久久久久久| 亚洲一本综合久久| 久久亚洲国产成人影院| AV色综合久久天堂AV色综合在| 国产亚州精品女人久久久久久| 人妻无码αv中文字幕久久琪琪布| 欧美一区二区三区久久综合| 精品人妻伦一二三区久久| 国产精品99久久久精品无码| 久久精品www| 午夜人妻久久久久久久久| 99久久99久久精品国产片果冻| 伊人久久大香线蕉综合网站| 91久久精品91久久性色| 久久亚洲精品无码播放| 久久国产精品一区二区| 久久精品国产亚洲av高清漫画| 久久99精品久久久久久秒播| 久久99精品久久久久婷婷|