Updated code

writing image into png directly