如何 16 和 32 bit 的位图中的图象数据 另存为一种格式
简单点就是获得 每个像素的数据 希望 高手指点下这里贴个 8 位的 给大家参考下
function  AddBitmap(NewBitMap:TBitMap;X,Y:SmallInt):Boolean;
var
  DBits:PByte;
Begin
 Result:=False;
 try
   lsDib:=TDib.Create;
   lsDib.Width := NewBitMap.Width;
   lsDib.Height := NewBitMap.Height;
   lsDib.ColorTable := MainPalette;
   lsDib.UpdatePalette;
   lsDib.Canvas.Draw(0,0,NewBitmap);
   if Stream<>nil then
   Begin
     DBits:=lsDIb.PBits;
     Stream.Write(DBits^,lsDib.Height*lsDib.Width);
   End;
   Result:=True;
  Except
  End;
End;

解决方案 »

  1.   

    你查一下BMP图的格式吧,网上多的是,说的很清楚
      

  2.   


    const
      PICW=640;/640 图像宽度
      PICH=480;//480图像高度
    type
    Trgb=record
        b:byte;
        g:byte;
        r:byte;
      end;
    var
      imag0:   array[1..PICH,0..PICW] of byte;
    procedure bmptoarray(path: string);
    var
      i,x,y:      integer;
      stream:     Tmemorystream;
      rgb:        array[0..PICW*PICH-1+18] of Trgb;
    begin
      Stream := TMemoryStream.Create;
      stream.LoadFromFile(path);
      stream.Position:=0;
      stream.Read(rgb,sizeof(rgb));
      stream.Free;
      for i:=18 to PICW*PICH+17 do
      begin
        x:=(i-18) MOD PICW;
        y:=(i-18) div PICW;
        imag0[PICH-y,x+1]:=round(0.11*rgb[i].b+0.3*rgb[i].r+0.59*rgb[i].g+0.1);//亮度值
        //imag0[PICH-y,x+1]:=rgb[i].r; 红色
      end;
    end;
    这是一个处理640*480 32位的bmp图像素的例程