Forum Archive

Crop ui.Image

pavlinb

Is there a away to crop ui.Image ? I need to avoid converting to PIL image and back to ui.Image.

Thanks.

stephen

@pavlinb

take a look at this thread and see if this is your issue.

other than that... without using PIL all i could find was inside photos module.. make sure if you test this example you have a JPEG in your current directory called temp.jpg...

import ui
import photos

img=photos.create_image_asset('./temp.jpg').get_ui_image(size=(512,512), crop=True)

v=ui.View(frame=(0, 0, 600, 800))
iv=ui.ImageView(image=img)
v.add_subview(iv)

v.present('sheets')

hope this helps.

cvp

@pavlinb try

ui_image = ui.Image.named('test:Lenna')
ui_image.show()
w,h = ui_image.size
wc,hc = w/2,2*h/3
with ui.ImageContext(wc,hc) as ctx:
    ui_image.draw(-60,-20,w,h)
    ui_image = ctx.get_image()
ui_image.show() 
stephen

@cvp said:

@pavlinb try
ui_image = ui.Image.named('test:Lenna') ui_image.show() w,h = ui_image.size wc,hc = w/2,2*h/3 with ui.ImageContext(wc,hc) as ctx: ui_image.draw(-60,-20,w,h) ui_image = ctx.get_image() ui_image.show()

aweome! i figured ImageContext was the one but couldnt think of how to position croping

pavlinb

@cvp It seems that your example helps a lot.

Thanks.