0

This is the code for the screenshot:

im = ImageGrab.grab()
im.save(r'C:\screen.jpg')

I am suppposed to return the image but i dont know how to.

I've tried to open it as a file and read it in 1024 pieces but these are two different def so the response spose to be the file name.

with open (response, 'w') as filename:
    data = filename.read()
Matthias
  • 12,873
  • 6
  • 42
  • 48
  • 1
    You want to read it in 1024 byte chunks? First you'll want to open the file in `rb` mode. `w` will truncate the file (get rid of your screenshot). the `b` means you are reading in binary or bytes mode – C.Nivs Dec 20 '19 at 15:12
  • `read()` accepts an optional integer argument of how many bytes to read and will return `b''` (an empty bytearray) when there aren't any more. i.e. `data = read(1024)`. Be sure to open the file with mode `rb`. – martineau Dec 20 '19 at 15:41
  • ok ive changed to rb but i stiil dont understand how to send it, i want to send the image from the server to the client in 1024 bytes every time and to let the client know when it has finished – JULY PELEG Dec 20 '19 at 16:02
  • 1
    You'll need to use the [socket](https://docs.python.org/3/library/socket.html#module-socket) module. Here's some [documentation with examples](https://pymotw.com/3/socket/index.html). Until you've done some more research and made an attempt to use it, your question is too broad and off-topic for this website. You might be able to find some examples of using the module here though, so I encourage you to [look](https://stackoverflow.com/questions/tagged/python+sockets). There's also a [HowTo](https://docs.python.org/3/howto/sockets.html) in the online docs. – martineau Dec 20 '19 at 16:27
  • Also see question [Read file in chunks - RAM-usage, read Strings from binary files](https://stackoverflow.com/questions/17056382/read-file-in-chunks-ram-usage-read-strings-from-binary-files) for examples of reading a file in pieces or chunks. – martineau Dec 20 '19 at 17:02

0 Answers0