यह सिर्फ बाइनरी फ़ाइल प्रारूप को समझने की बात है। संपीड़ित प्रारूप अधिक कठिन होने जा रहे हैं।
#incremental_write_bmp.py
import binascii
data='''
0h -2 -42 4D -"BM" -Magic Number (unsigned integer 66, 77)
2h -4 -46 00 00 00 -70 Bytes -Size of the BMP file
6h -2 -00 00 -Unused -Application Specific
8h -2 -00 00 -Unused -Application Specific
Ah -4 -36 00 00 00 -54 bytes -The offset where the bitmap data (pixels) can be found.
Eh -4 -28 00 00 00 -40 bytes -The number of bytes in the header (from this point).
12h -4 -02 00 00 00 -2 pixels -The width of the bitmap in pixels
16h -4 -02 00 00 00 -2 pixels -The height of the bitmap in pixels
1Ah -2 -01 00 -1 plane -Number of color planes being used.
1Ch -2 -18 00 -24 bits -The number of bits/pixel.
1Eh -4 -00 00 00 00 -0 -BI_RGB, No compression used
22h -4 -10 00 00 00 -16 bytes -The size of the raw BMP data (after this header)
26h -4 -13 0B 00 00 -2,835 pixels/meter -The horizontal resolution of the image
2Ah -4 -13 0B 00 00 -2,835 pixels/meter -The vertical resolution of the image
2Eh -4 -00 00 00 00 -0 colors -Number of colors in the palette
32h -4 -00 00 00 00 -0 important colors -Means all colors are important
36h -3 -00 00 FF -0 0 255 -Red, Pixel (1,0)
39h -3 -FF FF FF -255 255 255 -White, Pixel (1,1)
3Ch -2 -00 00 -0 0 -Padding for 4 byte alignment (Could be a value other than zero)
3Eh -3 -FF 00 00 -255 0 0 -Blue, Pixel (0,0)
41h -3 -00 FF 00 -0 255 0 -Green, Pixel (0,1)
44h -2 -00 00 -0 0 -Padding for 4 byte alignment (Could be a value other than zero)
'''.strip().split('\n')
open('test.bmp','wb')
for l in data:
b = l.split('-')[2].strip()
d = ''.join(b.split())
x = binascii.a2b_hex(d)
# this re-opens the file and appends each iteration
open('test.bmp','ab').write(x)
... संवर्द्धित उदाहरण 2x2 बिटमैप लिखेंगे पाया here:
आप यह मानते हुए एक बिटमैप/डीआईबी, इस कोड को चाहते हैं। अब यह हेडर को आपके इच्छित आकार में सेट करना और सही क्रम में अपनी टाईल्स को पढ़ना (और कभी-कभी पुनः पढ़ना) करना है। मैंने इसे एक बहुत बड़ी फाइल के साथ करने की कोशिश की और पाइथन की मेमोरी स्पाइक नहीं देखी। मुझे लगता है कि ओएस पूरी चीज को पढ़ने के बिना फाइल में जोड़ सकता है।
क्या छवियों को आरजीबी मोड में होना चाहिए? –
हां, वे रंगीन छवियां हैं। इसके अलावा 25000x25000 वास्तव में पूर्ण छवि का केवल एक छोटा हिस्सा है, जो शायद 175,000x325,000 होने जा रहा है। भले ही छवियां ग्रेस्केल हों, मैं एक छवि का अनुमान लगा रहा हूं कि आकार अभी भी रैम में फिट नहीं होगा। – meatvest
यह आमतौर पर ऐसे प्रश्नों का उत्तर देने में मदद करता है यह जानने के लिए कि आउटपुट का उपयोग कैसे किया जाएगा। कौन सा प्रोग्राम/सिस्टम इस डेटा का उपभोग करेगा (और/या किस उपयोग के लिए)? इसका उत्तर रास्ता इंगित कर सकता है। –