Python Read/Write Binary Image Files

python day 32

We always use “copy” and “paste” buttons to duplicate images. Today let’s use Python to code to do so.

  • Overwrite the picture “b2” as “binary”
  • Copy and Paste the picture “binary” with an empty picture “b2”

*rb: read as binary
*wb: write as binary

def r_binary():
        with open("C:/Users/Desktop/binary.jpg" ,"rb") as fs1:
        with open("C:/Users/Desktop/b2.jpg" ,"wb") as fs2:
    except FileNotFoundError as e:
        print('No file existed -_-|||')
    except IOError as e:
        print('Something is wrong @_@') 
    print("Done! ~_~")

<class 'bytes'>
Done! ~_~


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial
%d bloggers like this: