加入收藏 | 设为首页 | 会员中心 | 我要投稿 好传媒网 (https://www.haochuanmei.com/)- 区块链、物联平台、物联安全、数据迁移、5G!
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

C# 剖析 RAS文件 SUM 光栅文件图象的代码

发布时间:2023-06-10 16:00:19 所属栏目:语言 来源:互联网
导读:   使用方法:



  代码如下:



  ImageRas _Ras = new ImageRas(@"D:/temp/test.ras");



  pictureBox1.Image = _Ras.Image;



  _Ras.SaveRas(@"d:/temp/OK.ra
  使用方法:
 
  代码如下:
 
  ImageRas _Ras = new ImageRas(@"D:/temp/test.ras");
 
  pictureBox1.Image = _Ras.Image;
 
  _Ras.SaveRas(@"d:/temp/OK.ras");
 
  我只实现了24位色和8位色 这个结构也太简单了。只有文件头和数据区 。就是8位色的色彩表有些特殊
 
  先是红色表 绿色表 蓝色表 平时都是 RGB、RGB 这样放 这东西居然RRRR.....GGG......B....
 
  不知道怎么想的。
 
  项目多了很少有时间做这些东西了。下个目标是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>
 
  /// 图形区域数据大小
 
  /// </summary>
 
  private uint m_Length = 0;
 
  /// <summary>
 
  /// 数据类型
 
  /// </summary>
 
  private uint m_Type = 0;
 
  /// <summary>
 
  /// 色彩图形类型
 
  /// </summary>
 
  private uint m_MapType = 0;
 
  /// <summary>
 
  /// 色彩长度
 
  /// </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>
 
  /// 获取数据
 
  /// </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);
 

(编辑:好传媒网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章