change the picture file open as 'wb' to avoid distortion

fix the forgot of fw.close to close the picture file
change fw=open(filename,'w') to fw=open(filename,'wb')
to open as binary mode ,avoid distortion of img