Usage,
ImageRas _ Ras = new ImageRas (@ "D: empest. ras ");
PictureBox1.Image = _ Ras. Image;
_ Ras. SaveRas (@ "d: empOK. ras ");
I only implemented the 24-bit color and 8-bit color structure, which is too simple. Only the file header and data area are supported. The 8-bit color table has some special features.
First, the red table, the green table, and the blue table are usually RGB and RGB. In this case, the RRRR... GGG... B ....
I don't know what to think.
There is little time to do these things when there are too many projects. The next target is the IFF file.
All code
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 Raster image 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 private
/// <Summary>
/// File Header 956AA659
/// </Summary>
Private uint m_Mageic = 0x956AA659;
/// <Summary>
/// Width
/// </Summary>
Private uint m_Width = 0;
/// <Summary>
/// High
/// </Summary>
Private uint m_Height = 0;
/// <Summary>
/// Color depth
/// </Summary>
Private uint m_Depth = 0;
/// <Summary>
/// Data size in the graphic Area
/// </Summary>
Private uint m_Length = 0;
/// <Summary>
/// Data Type
/// </Summary>
Private uint m_Type = 0;
/// <Summary>
/// Color image type
/// </Summary>
Private uint m_MapType = 0;
/// <Summary>
/// Color Length
/// </Summary>
Private uint m_MapLength = 0;
/// <Summary>
/// Color table
/// </Summary>
Private Color [] m_ColorList = new Color [256];
/// <Summary>
/// Image
/// </Summary>
Private Bitmap m_Image;
# Endregion
/// <Summary>
/// Obtain the image
/// </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)
&