以系统文件notepad.exe为例:
'''
Created on 2018-3-26
'''
import numpy as np
import cv2
f = open('D:\\xxx\\notepad.exe', mode='rb')
image = np.fromfile(f, dtype=np.ubyte)
filesize = image.shape[0]
# print(filesize)
width = 256 #设置图片宽度为256
rem = filesize%width
# print(rem)
if rem != 0:
image = image[:-rem]
height = int(image.shape[0]/width)
image = image.reshape(height,width)
cv2.imshow("notepad.exe",image)
cv2.imwrite('D:\\xxx\\notepad.png', image)
cv2.waitKey(0)
结果输出: