在德尔福7我能够做到这一点使用图像组件,这一切都很好,但我试图将相同的功能转换为C#,并有一些问题Pascal> C#绘制原始像素数据到图片框问题
procedure TMain_Form.Load_Pallete_WPN(FileName: string);
var
MOMO_Fs: TFileStream;
i, ii, iii: integer;
begin
MOMO_Fs := TFileStream.Create(FileName, fmOpenRead);
MOMO_Fs.Position := $82D80;
MOMO_Fs.Read(RGBA, $400);
iii := 0;
for i := 0 to 15 do
begin
for ii := 0 to 15 do
begin
Pallet_Preview.Picture.Bitmap.Canvas.Pixels[ii, i] :=
RGB(RGBA[iii].b, RGBA[iii].G, RGBA[iii].R);
inc(iii);
end;
end;
MOMO_Fs.Free;
end;
这是工作结果帕斯卡仅仅是明确的。 现在,当我试图实现在C#这种行为我曾试图与帕斯卡例如,下面的
public struct TRGBA_Obj
{
public byte b;
public byte g;
public byte r;
public byte a;
}
public TRGBA_Obj[] RGBA = new TRGBA_Obj[255];
public string fp;
public void Load_Pallette(string filepath)
{
int i, ii, iii;
FileStream fs = new FileStream(filepath, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
Bitmap bmp = new Bitmap(256, 256);
fs.Seek(0x82D80, SeekOrigin.Begin); // this is where the palette is
for (int x = 0; x < RGBA.Length; x++)
{
RGBA[x].r = br.ReadByte();
RGBA[x].g = br.ReadByte();
RGBA[x].b = br.ReadByte();
RGBA[x].a = br.ReadByte();
// this just dumps the color values to a list view for ref
LV_COLOR_PALETTE.Items.Add(x.ToString());
LV_COLOR_PALETTE.Items[x].SubItems.Add(RGBA[x].r.ToString());
LV_COLOR_PALETTE.Items[x].SubItems.Add(RGBA[x].g.ToString());
LV_COLOR_PALETTE.Items[x].SubItems.Add(RGBA[x].b.ToString());
LV_COLOR_PALETTE.Items[x].SubItems.Add(RGBA[x].a.ToString());
}
iii = 0;
for (int y = 0; y < 15; y++)
{
for (int j = 0; j < 15; j++)
{
bmp.SetPixel(j, y, Color.FromArgb(RGBA[iii].a, RGBA[iii].r, RGBA[iii].g, RGBA[iii].b));
iii++;
}
}
random_box.Image = bmp;
fs.Close();
br.Close();
我的结果如预期运作,因为它是唯一一个256像素的调色板的C#绘制的图像是非常小的我尝试所有的图片框的变焦/拉伸选项,如果我改变bmp的高度&宽度从256/256到较低的值图像大小增加,但看起来没有像工作的delphi示例,任何提示?哈哈