首页 > 编程 > C# > 正文

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

2020-04-24 21:39:17
字体:
来源:转载
供稿:网友
使用方法:
代码如下:
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);
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表