alibaba / tidevice

tidevice can be used to communicate with iPhone device
MIT License
2.43k stars 459 forks source link

Update _perf.py #309

Closed dhiravidamani238 closed 1 year ago

dhiravidamani238 commented 1 year ago

Hi ,

I'm using this library for my mac os x application. I can getting the screenshot value like "screenshot {'value': <PIL.PngImagePlugin.PngImageFile image mode=RGB size=349x500 at 0x10F663290>, 'timestamp': 1682069034630}" using "tidevice perf -B com.example.app" command. In frontend we are using swift language and we can't convert screenshot value "<PIL.PngImagePlugin.PngImageFile image mode=RGB size=349x500 at 0x10F663290>" to NSImage. So I modified your code(in my local) like converting image to bytes(as modified in the below code) and send to front end. In front end(swift) we can convert the bytes to image and it's working fine. The problem is when I install the tidevice using "pip3 install -U tidevice" command the modified code was removed and new file installed from github. So I can't using the modified code. The code I need to update in github below are

def iter_screenshot(d: BaseDevice) -> Iterator[Tuple[DataType, dict]]: for img in d.iter_screenshot(): _time = time.time() img.thumbnail((200, 200)) # 缩小图片已方便保存

    buffered = BytesIO()
    img.save(buffered, format="JPEG")
    img_str = base64.b64encode(buffered.getvalue())

    # example of convert image to bytes
    # buf = io.BytesIO()
    # img.save(buf, format="JPEG")

    # turn image to URL
    yield DataType.SCREENSHOT, {"time": _time, "value": img, "img_str": img_str, "type": "screenshot"}

Kindly do the needfull. Thanks.

CLAassistant commented 1 year ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

codeskyblue commented 1 year ago

The size of the converted base64 image could be quite large. It may be advisable to save it to the local disk and include the filename in the output json.

dhiravidamani238 commented 1 year ago

The size of the converted base64 image could be quite large. It may be advisable to save it to the local disk and include the filename in the output json.

Hi @codeskyblue Thanks for your response.

  1. So we tried but we could not get the file from local directory. Can you provide me the details for the fetching the image from local directory?