I'm using Pillow to capture an image on my screen. I would then be able to open up the captured image and view it. However, I encountered a problem where I cannot open the image for a reason unbeknownst to me.
This is my code:
import PIL.ImageGrab
from PIL import Image
def lswth():
crnts2 = PIL.ImageGrab.grab(bbox=(934, 813, 966, 830))
im = Image.open(crnts2)
im.show()
lswth()
The following code does not produce any images and returns me:
AttributeError: 'PixelAccess' object has no attribute 'read'
I tried viewing other articles about similar problems How do i read image using PILLOW image?, https://www.geeksforgeeks.org/python-pil-image-open-method/#, ect. but the problem consisted of an image that was already saved on the computer rather than being taken by PILLOW. I tinkered around the code using other commands like Image.open, Image.save, .load(), ect. but they also returned an error or did not show the image. From what I can gather, the command only works on images already saved on the computer, not images taken by PILLOW. I feel like I have to save the image directly onto the computer but I haven't found a way to do that as Image.save does not work.
How would I view a file saved by pillow?
I think your problem is that you are trying load an image from your pc. Instead simply do the following:
import PIL.ImageGrab
from PIL import Image
def lswth():
crnts2 = PIL.ImageGrab.grab(bbox=None)
crnts2.show()
lswth()
I removed the dimensions you had specified in your own coded but you can place whatever specs you want in there to customise it.