एक बिटमैप फ़ाइल BITMAPFILEHEADER
के साथ शुरू होती है, bfOffBits
सदस्य छवि डेटा का प्रारंभिक पता निर्दिष्ट करता है। यह ध (11-14 वें बाइट्स) में एक ड्वॉर्ड है। डेल्फी वीसीएल में 'windows.pas' में TBitmapFileHeader
के रूप में परिभाषित संरचना है।
ScanLine
की अंतिम पंक्ति इस छवि डेटा (नीचे-अप) पर इंगित करती है। वीसीएल में यह मूल्य bmBits
dsBm
(BITMAP
) सदस्य या DIBSECTION
छवि का सदस्य है। जब एक स्कैन लाइन का अनुरोध किया जाता है, तो वीसीएल अनुरोधित पंक्ति के आधार पर ऑफ़सेट की गणना करता है, पंक्ति में पिक्सल की संख्या (छवि की चौड़ाई) और कितने बिट्स पिक्सेल बनाते हैं, और इस ऑफसेट को जोड़ने वाले पते पर पॉइंटर लौटाते हैं bmBits
। यह वास्तव में बाइट-बाय-बाइट छवि डेटा है।
नीचे डेल्फी नमूना कोड एक फ़ाइल स्ट्रीम में एक 24bit बिटमैप पढ़ता है और Bitmap.ScanLine
समकक्ष की पिक्सेल डेटा के साथ प्रत्येक पढ़ने पिक्सेल तुलना:
procedure TForm1.Button1Click(Sender: TObject);
var
BmpFile: string;
Bmp: TBitmap;
fs: TFileStream;
FileHeader: TBitmapFileHeader;
InfoHeader: TBitmapInfoHeader;
iHeight, iWidth, Padding: Longint;
ScanLine: Pointer;
RGBFile, RGBBitmap: TRGBTriple;
begin
BmpFile := ExtractFilePath(Application.ExeName) + 'Attention_128_24.bmp';
// laod bitmap to TBitmap
Bmp := TBitmap.Create;
Bmp.LoadFromFile(BmpFile);
Assert(Bmp.PixelFormat = pf24bit);
// read bitmap file with stream
fs := TFileStream.Create(BmpFile, fmOpenRead or fmShareDenyWrite);
// need to get the start of pixel array
fs.Read(FileHeader, SizeOf(FileHeader));
// need to get width and height of bitmap
fs.Read(InfoHeader, SizeOf(InfoHeader));
// just a general demo - no top-down image allowed
Assert(InfoHeader.biHeight > 0);
// size of each row is a multiple of the size of a DWORD
Padding := SizeOf(DWORD) -
(InfoHeader.biWidth * 3) mod SizeOf(DWORD); // pf24bit -> 3 bytes
// start of pixel array
fs.Seek(FileHeader.bfOffBits, soFromBeginning);
// compare reading from file stream with the value from scanline
for iHeight := InfoHeader.biHeight - 1 downto 0 do begin
// get the scanline, bottom first
ScanLine := Bmp.ScanLine[iHeight];
for iWidth := 0 to InfoHeader.biWidth - 1 do begin
// read RGB from file stream
fs.Read(RGBFile, SizeOf(RGBFile));
// read RGB from scan line
RGBBitmap := TRGBTriple(Pointer(
Longint(ScanLine) + (iWidth * SizeOf(TRGBTriple)))^);
// assert the two values are the same
Assert((RGBBitmap.rgbtBlue = RGBFile.rgbtBlue) and
(RGBBitmap.rgbtGreen = RGBFile.rgbtGreen) and
(RGBBitmap.rgbtRed = RGBFile.rgbtRed));
end;
// skip row padding
fs.Seek(Padding, soCurrent);
end;
end;
की पिक्सेल डेटा की शुरुआत खोजने के बारे में एक तस्वीर एक हेक्स संपादक में एक बिटमैप फ़ाइल:
स्रोत
2011-09-19 15:47:29
नाम "TBitmap" जरूरी माइक्रोसॉफ्ट "बिटमैप" फ़ाइल स्वरूप से कोई लेना देना नहीं है, क्या आप जानते हैं ! डेल्फी "टीबीटमैप" में "स्कैनलाइन" संपत्ति केवल एक रास्टर लाइन है - कुछ भी नहीं, कुछ भी कम नहीं। – paulsm4
बिटमैप फ़ाइल का पिक्सेल प्रारूप क्या है और आप इसे TBitmap में कैसे लोड करते हैं? क्या आपका बिटमैप ऊपर या नीचे नीचे संग्रहीत है? –
संरचना का कौन सा हिस्सा आप समझना चाहते हैं? TBitmap फ़ील्ड, या पिक्सेल डेटा? –