<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
        當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

        C# 解析 RAS文件 SUM 光柵文件圖象的代碼

        來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:43:17
        文檔

        C# 解析 RAS文件 SUM 光柵文件圖象的代碼

        C# 解析 RAS文件 SUM 光柵文件圖象的代碼:使用方法: 代碼如下:ImageRas _Ras = new ImageRas(@D:\temp\test.ras); pictureBox1.Image = _Ras.Image; _Ras.SaveRas(@d:\temp\OK.ras); 我只實(shí)現(xiàn)了24位色和8位色 這個(gè)結(jié)構(gòu)也太簡(jiǎn)單了。只有文件頭和數(shù)據(jù)區(qū) 。就是8位色的色彩表有些特殊
        推薦度:
        導(dǎo)讀C# 解析 RAS文件 SUM 光柵文件圖象的代碼:使用方法: 代碼如下:ImageRas _Ras = new ImageRas(@D:\temp\test.ras); pictureBox1.Image = _Ras.Image; _Ras.SaveRas(@d:\temp\OK.ras); 我只實(shí)現(xiàn)了24位色和8位色 這個(gè)結(jié)構(gòu)也太簡(jiǎn)單了。只有文件頭和數(shù)據(jù)區(qū) 。就是8位色的色彩表有些特殊

        使用方法:
        代碼如下:

        ImageRas _Ras = new ImageRas(@"D:\temp\test.ras");
        pictureBox1.Image = _Ras.Image;
        _Ras.SaveRas(@"d:\temp\OK.ras");

        我只實(shí)現(xiàn)了24位色和8位色 這個(gè)結(jié)構(gòu)也太簡(jiǎn)單了。只有文件頭和數(shù)據(jù)區(qū) 。就是8位色的色彩表有些特殊
        先是紅色表 綠色表 藍(lán)色表 平時(shí)都是 RGB、RGB 這樣放 這東西居然RRRR.....GGG......B....
        不知道怎么想的。
        項(xiàng)目多了很少有時(shí)間做這些東西了。下個(gè)目標(biāo)是IFF文件
        全部代碼
        代碼如下:

        using System;
        using System.Collections.Generic;
        using System.Text;
        using System.Runtime.InteropServices;
        using System.Drawing.Imaging;
        using System.Drawing;
        using System.IO;
        namespace Zgke.MyImage.ImageFile
        {
        /// <summary>
        /// SUN光柵圖形 RAS
        /// zgke@sina.com
        /// qq:116149
        /// </summary>
        public class ImageRas
        {
        public ImageRas(string p_ImageFile)
        {
        if (System.IO.File.Exists(p_ImageFile))
        {
        LoadImage(System.IO.File.ReadAllBytes(p_ImageFile));
        }
        }
        public ImageRas()
        {
        }
        #region 私有
        /// <summary>
        /// 文件頭 956AA659
        /// </summary>
        private uint m_Mageic = 0x956AA659;
        /// <summary>
        /// 寬
        /// </summary>
        private uint m_Width = 0;
        /// <summary>
        /// 高
        /// </summary>
        private uint m_Height = 0;
        /// <summary>
        /// 顏色深
        /// </summary>
        private uint m_Depth = 0;
        /// <summary>
        /// 圖形區(qū)域數(shù)據(jù)大小
        /// </summary>
        private uint m_Length = 0;
        /// <summary>
        /// 數(shù)據(jù)類型
        /// </summary>
        private uint m_Type = 0;
        /// <summary>
        /// 色彩圖形類型
        /// </summary>
        private uint m_MapType = 0;
        /// <summary>
        /// 色彩長(zhǎng)度
        /// </summary>
        private uint m_MapLength = 0;
        /// <summary>
        /// 顏色表
        /// </summary>
        private Color[] m_ColorList = new Color[256];
        /// <summary>
        /// 圖形
        /// </summary>
        private Bitmap m_Image;
        #endregion
        /// <summary>
        /// 獲取圖形
        /// </summary>
        public Bitmap Image
        {
        get
        {
        return m_Image;
        }
        set
        {
        if (value != null)
        {
        m_Image = value;
        m_Width = (uint)value.Width;
        m_Height = (uint)value.Height;
        switch (value.PixelFormat)
        {
        case PixelFormat.Format8bppIndexed:
        break;
        case PixelFormat.Format32bppArgb:
        break;
        default:
        m_Depth = 24;
        break;
        }
        }
        }
        }
        /// <summary>
        /// 獲取數(shù)據(jù)
        /// </summary>
        /// <param name="p_ImageBytes"></param>
        private void LoadImage(byte[] p_ImageBytes)
        {
        if (BitConverter.ToUInt32(p_ImageBytes, 0) != m_Mageic) throw new Exception("文件頭不正確!");
        m_Width = BytesToUint(p_ImageBytes, 4);
        m_Height = BytesToUint(p_ImageBytes, 8);
        m_Depth = BytesToUint(p_ImageBytes, 12);
        m_Length = BytesToUint(p_ImageBytes, 16);
        m_Type = BytesToUint(p_ImageBytes, 20);
        m_MapType = BytesToUint(p_ImageBytes, 24);
        m_MapLength = BytesToUint(p_ImageBytes, 28);
        int _StarIndex = 32;
        switch (m_MapType)
        {
        case 1:
        int _ColorTable = (int)m_MapLength / 3;
        for (int i = 0; i != _ColorTable; i++)
        {
        m_ColorList[i] = Color.FromArgb(p_ImageBytes[_StarIndex], p_ImageBytes[_StarIndex + _ColorTable], p_ImageBytes[_StarIndex + (_ColorTable * 2)]);
        _StarIndex++;
        }
        _StarIndex += _ColorTable * 2;
        break;
        default:
        break;
        }
        LoadData(p_ImageBytes, _StarIndex);
        }
        /// <summary>
        /// 字節(jié)轉(zhuǎn)換為UINT
        /// </summary>
        /// <param name="p_Value">字節(jié)數(shù)組</param>
        /// <param name="p_Index">開(kāi)始位置</param>
        /// <returns></returns>
        private uint BytesToUint(byte[] p_Value, int p_Index)
        {
        byte[] _ValueBytes = new byte[4];
        _ValueBytes[0] = p_Value[p_Index + 3];
        _ValueBytes[1] = p_Value[p_Index + 2];
        _ValueBytes[2] = p_Value[p_Index + 1];
        _ValueBytes[3] = p_Value[p_Index];
        return BitConverter.ToUInt32(_ValueBytes, 0);
        }
        /// <summary>
        /// 獲取反轉(zhuǎn)的BYTES
        /// </summary>
        /// <param name="p_Value"></param>
        /// <returns></returns>
        private byte[] UintToBytes(uint p_Value)
        {
        byte[] _ValueBytes = BitConverter.GetBytes(p_Value);
        Array.Reverse(_ValueBytes);
        return _ValueBytes;
        }
        /// <summary>
        /// 獲取圖形數(shù)據(jù)
        /// </summary>
        /// <param name="p_ValueBytes">文件留</param>
        /// <param name="p_StarIndex">RGB留開(kāi)始位置</param>
        private void LoadData(byte[] p_ValueBytes, int p_StarIndex)
        {
        PixelFormat _Format = PixelFormat.Format24bppRgb;
        switch (m_Depth)
        {
        case 8:
        _Format = PixelFormat.Format8bppIndexed;
        break;
        case 24:
        _Format = PixelFormat.Format24bppRgb;
        break;
        default:
        throw new Exception("未實(shí)現(xiàn)!");
        }
        m_Image = new Bitmap((int)m_Width, (int)m_Height, _Format);
        BitmapData _Data = m_Image.LockBits(new Rectangle(0, 0, m_Image.Width, m_Image.Height), ImageLockMode.ReadWrite, m_Image.PixelFormat);
        byte[] _WriteBytes = new byte[_Data.Height * _Data.Stride];
        int _StarIndex = 0;
        int _WriteIndex = 0;
        for (int i = 0; i != _Data.Height; i++)
        {
        _WriteIndex = i * _Data.Stride;
        _StarIndex = i * ((int)m_Length / (int)m_Height) + p_StarIndex;
        for (int z = 0; z != _Data.Width; z++)
        {
        switch (m_Depth)
        {
        case 8:
        _WriteBytes[_WriteIndex] = p_ValueBytes[_StarIndex];
        _WriteIndex++;
        _StarIndex++;
        break;
        case 24:
        _WriteBytes[_WriteIndex] = p_ValueBytes[_StarIndex + 2];
        _WriteBytes[_WriteIndex + 1] = p_ValueBytes[_StarIndex + 1];
        _WriteBytes[_WriteIndex + 2] = p_ValueBytes[_StarIndex];
        _WriteIndex += 3;
        _StarIndex += 3;
        break;
        }
        }
        }
        switch (m_Depth)
        {
        case 8:
        ColorPalette _Palette = m_Image.Palette;
        for (int i = 0; i != m_ColorList.Length; i++)
        {
        _Palette.Entries[i] = m_ColorList[i];
        }
        m_Image.Palette = _Palette;
        break;
        default:
        break;
        }
        Marshal.Copy(_WriteBytes, 0, _Data.Scan0, _WriteBytes.Length);
        m_Image.UnlockBits(_Data);
        }
        /// <summary>
        /// 保存圖形
        /// </summary>
        /// <returns></returns>
        private byte[] SaveImageOfRas()
        {
        if (m_Image == null) return new byte[0];
        MemoryStream _Stream = new MemoryStream();
        _Stream.Write(BitConverter.GetBytes(m_Mageic), 0, 4);
        _Stream.Write(UintToBytes(m_Width), 0, 4);
        _Stream.Write(UintToBytes(m_Height), 0, 4);
        switch (m_Depth)
        {
        case 8:
        BitmapData _Data256 = m_Image.LockBits(new Rectangle(0, 0, m_Image.Width, m_Image.Height), ImageLockMode.ReadOnly, m_Image.PixelFormat);
        byte[] _DataBytes = new byte[_Data256.Stride * _Data256.Height];
        int _Stride = _Data256.Stride;
        Marshal.Copy(_Data256.Scan0, _DataBytes, 0, _DataBytes.Length);
        m_Image.UnlockBits(_Data256);
        _Stream.Write(UintToBytes(8), 0, 4);
        uint _WidthCount = (uint)m_Image.Width;
        if (m_Image.Width % 2 != 0) _WidthCount = (uint)m_Image.Width + 1;
        uint _AllCount = _WidthCount * (uint)m_Image.Height;
        _Stream.Write(UintToBytes(_AllCount), 0, 4);
        _Stream.Write(UintToBytes(0), 0, 4);
        _Stream.Write(UintToBytes(1), 0, 4);
        _Stream.Write(UintToBytes(768), 0, 4);
        byte[] _RedBytes = new byte[256];
        byte[] _GreenBytes = new byte[256];
        byte[] _BlueBytes = new byte[256];
        for (int i = 0; i != 256; i++)
        {
        _RedBytes[i] = m_Image.Palette.Entries[i].R;
        _GreenBytes[i] = m_Image.Palette.Entries[i].G;
        _BlueBytes[i] = m_Image.Palette.Entries[i].B;
        }
        _Stream.Write(_RedBytes, 0, _RedBytes.Length);
        _Stream.Write(_GreenBytes, 0, _GreenBytes.Length);
        _Stream.Write(_BlueBytes, 0, _BlueBytes.Length);
        byte[] _Write = new byte[_WidthCount];
        for (int i = 0; i != m_Image.Height; i++)
        {
        Array.Copy(_DataBytes, i * _Stride, _Write, 0, _WidthCount);
        _Stream.Write(_Write, 0, _Write.Length);
        }
        break;
        default:
        Bitmap _NewBitmap = new Bitmap(m_Image.Width, m_Image.Height, PixelFormat.Format24bppRgb);
        Graphics _Graphics = Graphics.FromImage(_NewBitmap);
        _Graphics.DrawImage(m_Image, new Rectangle(0, 0, m_Image.Width, m_Image.Height));
        _Graphics.Dispose();
        BitmapData _Data24 = _NewBitmap.LockBits(new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height), ImageLockMode.ReadOnly, _NewBitmap.PixelFormat);
        byte[] _DataBytes24 = new byte[_Data24.Stride * _Data24.Height];
        int _Stride24 = _Data24.Stride;
        Marshal.Copy(_Data24.Scan0, _DataBytes24, 0, _DataBytes24.Length);
        _NewBitmap.UnlockBits(_Data24);
        _Stream.Write(UintToBytes(24), 0, 4);
        uint _WidthCount24 = (uint)_NewBitmap.Width;
        if (_NewBitmap.Width % 2 != 0) _WidthCount24 = (uint)_NewBitmap.Width + 1;
        uint _AllCount24 = _WidthCount24 * (uint)_NewBitmap.Height * 3;
        _WidthCount24 = _WidthCount24 * 3;
        _Stream.Write(UintToBytes(_AllCount24), 0, 4);
        _Stream.Write(UintToBytes(0), 0, 4);
        _Stream.Write(UintToBytes(0), 0, 4);
        _Stream.Write(UintToBytes(0), 0, 4);
        byte[] _Write24 = new byte[0];
        for (int i = 0; i != m_Image.Height; i++)
        {
        _Write24 = new byte[_WidthCount24];
        int _WriteIndex = 0;
        int _StarIndex = i * _Stride24;
        for (int z = 0; z != m_Image.Width; z++)
        {
        _Write24[_WriteIndex] = _DataBytes24[_StarIndex + 2];
        _Write24[_WriteIndex + 1] = _DataBytes24[_StarIndex + 1];
        _Write24[_WriteIndex + 2] = _DataBytes24[_StarIndex];
        _WriteIndex += 3;
        _StarIndex += 3;
        }
        _Stream.Write(_Write24, 0, _Write24.Length);
        }
        _NewBitmap.Dispose();
        break;
        }
        byte[] _Return = _Stream.ToArray();
        return _Return;
        }
        /// <summary>
        /// 保存圖形到RAS文件
        /// </summary>
        /// <param name="p_File"></param>
        public void SaveRas(string p_File)
        {
        byte[] _Value = SaveImageOfRas();
        if (_Value.Length != 0) File.WriteAllBytes(p_File, _Value);
        }
        }
        }

        聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        C# 解析 RAS文件 SUM 光柵文件圖象的代碼

        C# 解析 RAS文件 SUM 光柵文件圖象的代碼:使用方法: 代碼如下:ImageRas _Ras = new ImageRas(@D:\temp\test.ras); pictureBox1.Image = _Ras.Image; _Ras.SaveRas(@d:\temp\OK.ras); 我只實(shí)現(xiàn)了24位色和8位色 這個(gè)結(jié)構(gòu)也太簡(jiǎn)單了。只有文件頭和數(shù)據(jù)區(qū) 。就是8位色的色彩表有些特殊
        推薦度:
        標(biāo)簽: 代碼 解析 代碼代碼
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 在线美女免费观看网站h| 中文字幕无码免费久久9一区9| 久久99精品免费视频| 国产亚洲美女精品久久久2020| 一区二区免费国产在线观看| 天堂亚洲免费视频| 国产免费久久精品丫丫| 亚洲国产另类久久久精品| 91成人免费观看在线观看| 亚洲va无码专区国产乱码| 久9热免费精品视频在线观看| 亚洲av色影在线| h视频在线免费看| 在线aⅴ亚洲中文字幕| 国产精品高清全国免费观看| 色吊丝性永久免费看码 | 国产亚洲AV夜间福利香蕉149| 亚洲一区二区三区免费| 亚洲av无码一区二区三区不卡| 精品无码无人网站免费视频| 亚洲mv国产精品mv日本mv| 国产成人免费高清在线观看| 国产精品免费久久久久电影网| 国产V亚洲V天堂无码| 成人浮力影院免费看| 亚洲gay片在线gv网站| 亚洲日韩精品A∨片无码| 亚洲无砖砖区免费| 校园亚洲春色另类小说合集| 亚洲精品无码不卡在线播HE| 国产网站在线免费观看| 美女视频黄a视频全免费网站色| 亚洲狠狠婷婷综合久久久久 | 中国性猛交xxxxx免费看| 久久精品国产亚洲AV无码偷窥 | j8又粗又长又硬又爽免费视频| 亚洲国产日韩一区高清在线 | 国产精品亚洲二区在线| 国产亚洲综合成人91精品| 在线观看无码AV网站永久免费| 窝窝影视午夜看片免费|