代碼:
import re
fp = open('Image.raw', 'rb')
content = fp.read()
fp.close()
cnt = 0
start = 0
while True:
pic_start = content.find('\xff\xd8\xff\xe0', start)
if pic_start == -1:
break
start = pic_start + 1
while True:
first_start = content.find('\xff\xd8\xff\xe0', start)
first_end = content.find('\xff\xd9', start)
if first_start != -1 and first_start < first_end:
start = first_end + 1
else:
break
pic_end = first_end
cnt += 1
fp = open('%d.jpg' % cnt, 'wb')
fp.write(content[pic_start:pic_end + 2])
fp.close()
start = pic_end + 1
轉載自:ZXCVBNM《