| Цитата(14SatanA88 @ 7.9.2011, 12:23) | Доброго времени суток, уважаемые программеры.
Разбираю BMP по кускам (лаба).
| Код | bmpfi:=p+sizeof(BMPFileHeader);
|
На этой строке компилятор ругает меня: "Operator not applicable to this operand type".
| Код | procedure TMainForm.btnBMPClick(Sender: TObject); type {BMP file header} BMPFileHeader = record bfhType_l, bfhType_h: CHAR; bfhSize_l, bfhSize_h: WORD; bfhReserved1, bfhReserved2: WORD; bfhDataOffset_l, bfhDataOffset_h: WORD; end; {BMP info header} BMPInfoHeader = record bihSize_l, bihSize_h: WORD; bihWidth_l, bihWidth_h: WORD; bihHeight_l, bihHeight_h: WORD; bihPlanes: WORD; bihBits: WORD; bihCompression_l, bihCompression_h: WORD; bihSizeImage_l, bihSizeImage_h: WORD; bihResX_l, bihResX_h: WORD; bihResY_l, bihResY_h: WORD; bihColors_l, bihColors_h: WORD; bihIColors_l, bihIColors_h: WORD; end; var fBMP: file of byte; // file buf: array[1..1024] of byte; bmpfh: ^BMPFileHeader; bmpfi: ^BMPInfoHeader; p: pointer; begin
// set filter on dialog OpenDialog.Filter:='BMP|*.bmp';
// opening file if OpenDialog.Execute then begin imgBMP.Picture.LoadFromFile(OpenDialog.FileName); editBMP.Text:=OpenDialog.FileName; AssignFile(fBMP,OpenDialog.FileName); Reset(fBMP); BlockRead(fBMP,buf,sizeof(BMPInfoHeader)+sizeof(BMPInfoHeader)); p:=@buf; memoBMP.Clear; // output // head bmpfh:=p; memoBMP.Lines.Add('signature = '+bmpfh^.bfhType_l+bmpfh^.bfhType_h); memoBMP.Lines.Add('size = '+inttostr(bmpfh^.bfhSize_h*65536+bmpfh^.bfhSize_l)); memoBMP.Lines.Add('image starting address = '+inttostr(bmpfh^.bfhDataOffset_h*65536+bmpfh^.bfhDataOffset_l)); // info bmpfi:=p+sizeof(BMPFileHeader); memoBMP.Lines.Add('header size = '+inttostr(bmpfi^.bihSize_h*65536+bmpfi^.bihSize_l)); memoBMP.Lines.Add('width = '+inttostr(bmpfi^.bihWidth_h*65536+bmpfi^.bihWidth_l)); // end CloseFile(fBMP); end;
|
Как обойти? К сожалению, мало что соображаю в указателях, не знаю как там что... Заранее благодарен за помощь.
P.S. Я надеюсь, проблему изложил понятно.
P.P.S. Видел здесь где-то статейку про указатели, но потерял. Дайте ссылку. |
Не уверен, что это правильно, но попробуй так
| Код | type {BMP file header} BMPFileHeader = record bfhType_l, bfhType_h: CHAR; bfhSize_l, bfhSize_h: WORD; bfhReserved1, bfhReserved2: WORD; bfhDataOffset_l, bfhDataOffset_h: WORD; end; PBMPFileHeader = ^BMPFileHeader; {BMP info header} BMPInfoHeader = record bihSize_l, bihSize_h: WORD; bihWidth_l, bihWidth_h: WORD; bihHeight_l, bihHeight_h: WORD; bihPlanes: WORD; bihBits: WORD; bihCompression_l, bihCompression_h: WORD; bihSizeImage_l, bihSizeImage_h: WORD; bihResX_l, bihResX_h: WORD; bihResY_l, bihResY_h: WORD; bihColors_l, bihColors_h: WORD; bihIColors_l, bihIColors_h: WORD; end; PBMPInfoHeader = ^BMPInfoHeader; var fBMP: file of byte; // file buf: array[1..1024] of byte; bmpfh: PBMPFileHeader; bmpfi: PBMPInfoHeader; p: pointer; begin
// set filter on dialog OpenDialog.Filter:='BMP|*.bmp';
// opening file if OpenDialog.Execute then begin imgBMP.Picture.LoadFromFile(OpenDialog.FileName); editBMP.Text:=OpenDialog.FileName; AssignFile(fBMP,OpenDialog.FileName); Reset(fBMP); BlockRead(fBMP,buf,sizeof(BMPInfoHeader)+sizeof(BMPInfoHeader)); p:=@buf; memoBMP.Clear; // output // head bmpfh:=p; memoBMP.Lines.Add('signature = '+bmpfh^.bfhType_l+bmpfh^.bfhType_h); memoBMP.Lines.Add('size = '+inttostr(bmpfh^.bfhSize_h*65536+bmpfh^.bfhSize_l)); memoBMP.Lines.Add('image starting address = '+inttostr(bmpfh^.bfhDataOffset_h*65536+bmpfh^.bfhDataOffset_l)); // info Inc(PBMPFileHeader(p)); bmpfi:=p; memoBMP.Lines.Add('header size = '+inttostr(bmpfi^.bihSize_h*65536+bmpfi^.bihSize_l)); memoBMP.Lines.Add('width = '+inttostr(bmpfi^.bihWidth_h*65536+bmpfi^.bihWidth_l)); // end CloseFile(fBMP); end;
|
|