/// <summary>
/// 使用byte[]數據
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <returns></returns>
public static Bitmap CreateBitmap(byte[] originalImageData
{
//指定
Bitmap resultBitmap = new Bitmap(originalWidth
//將該位圖存入內存中
MemoryStream curImageStream = new MemoryStream();
resultBitmap
curImageStream
//由於位圖數據需要DWORD對齊(
int curPadNum = ((originalWidth *
//最終生成的位圖數據大小
int bitmapDataSize = ((originalWidth *
//數據部分相對文件開始偏移
int dataOffset = ReadData(curImageStream
//改變調色板
int paletteStart =
int paletteEnd = dataOffset;
int color =
for (int i = paletteStart; i < paletteEnd; i +=
{
byte[] tempColor = new byte[
tempColor[
tempColor[
tempColor[
tempColor[
color++;
curImageStream
curImageStream
}
//最終生成的位圖數據
byte[] destImageData = new byte[bitmapDataSize];
int destWidth = originalWidth + curPadNum;
//生成最終的位圖數據
for (int originalRowIndex = originalHeight
{
int destRowIndex = originalHeight
for (int dataIndex =
{
//同時還要注意
destImageData[destRowIndex * destWidth + dataIndex] = originalImageData[originalRowIndex * originalWidth + dataIndex];
}
}
//將流的Position移到數據段
curImageStream
//將新位圖數據寫入內存中
curImageStream
curImageStream
//將內存中的位圖寫入Bitmap對象
resultBitmap = new Bitmap(curImageStream);
return resultBitmap;
}
/// <summary>
/// 從內存流中指定位置
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <returns></returns>
public static int ReadData(MemoryStream curStream
{
int result =
byte[] tempData = new byte[length];
curStream
curStream
result = BitConverter
return result;
}
/// <summary>
/// 向內存流中指定位置
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <param name=
public static void WriteData(MemoryStream curStream
{
curStream
curStream
}
From:http://tw.wingwit.com/Article/program/net/201311/12589.html