我想將輸入圖像的大小調整爲固定大小。然後,我想將整個調整大小的圖像文件的內容放在一個緩衝區中以供進一步使用,例如將其附加到其他緩衝區(數據)中。使用python調整圖像大小並在緩衝區中獲取數據
目前我使用下面的Python功能做起來,
def get_resize_img(img_file):
img = Image.open(img_file)
img = img.resize((640,960), Image.NEAREST)
img.save("tmp_out.jpg")
fp = open("tmp_out.jpg", "rb")
data = fp.read()
fp.close()
print "img sz:", len(data)
return data
有沒有更好的方式來實現這一目標而無需編寫成一個虛擬文件(tmp_out.jpg),並從中讀取回來。
-Mohan