omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Saving camera photo to local folder

    Pythonista
    2
    3
    1744
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • secepar
      secepar last edited by omz

      Hi,

      I think it is a simple task. I have a button action to take a photo and save it to the local folder as well as the camera roll.

      def take_front_action(sender):
      	console.alert("Take front image", "", "OK")
      	front_image=photos.capture_image()
      	photos.save_image(front_image) #saving to camera roll working fine
      	last_asset=photos.get_assets()[-1]
      	img=last_asset.get_image()
      	front_filename=str(ObjCInstance(last_asset).valueForKey_('filename'))
      	with open(front_filename, 'wb') as out_file:
      		out_file.write(img)
      

      My code is giving me the following error:
      a bytes-linked object is required, not 'Image' or
      a bytes-linked object is required, not 'JpegImageFile',
      Depending on what I put inside 'img', 'last_asset' or 'front_image'in write().

      I think I'm not so clear what file format I'm getting in each function call. Hence the error.

      Any help will be greatly appreciated. Many thanks in advance.

      Sec

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        Just use the save method of the Image object:

        def take_front_action(sender):
            console.alert("Take front image", "", "OK")
            front_image=photos.capture_image()
            photos.save_image(front_image) #saving to camera roll working fine
            last_asset=photos.get_assets()[-1]
            front_filename=str(ObjCInstance(last_asset).valueForKey_('filename'))
            front_image.save(front_filename)
        
        1 Reply Last reply Reply Quote 0
        • secepar
          secepar last edited by

          That works. Thanks.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors