Image width - what am I doing wrong?
#1
Greetings,

In my application, I am loading one of many .jpgs of unknown width and height. My GUI will have a height limit, but not a width limitation.
Therefore, I want to scale the image based on the height, and center it based on the width.

I'm not getting the expected feedback from getWidth, that I wanted. It seems this is giving me the Control Objects width, and not the image's width.

Code:
caller_img=self.getControl(CALLER_IMG)
caller_img.setImage(__hf_addondir__ + get_kodi_prop("caller_name") + ".jpg")

call_img_width=caller_img.getWidth()
call_img_height=caller_img.getHeight()
log("width: " + str(call_img_width))
log("height: " + str(call_img_height))

What I see is this:
Code:
16:02:09 T:140537859438336  NOTICE: HFXML: width: 640
16:02:09 T:140537859438336  NOTICE: HFXML: height: 256

The height being what I set in the XML file, and retaining the aspect ratio.
But the width is definitely not right. Every image I select returns the same value.

Can I actually get the image's width/height? I definitely need something from the width, so I can center this image.

Thanks!
Reply
#2
i don't think you can.
that being said, i fail to understand why you'd need it.

if you use this in your xml:
Code:
<aspectratio>keep</aspectratio>
the image will be centered within the image control.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
He probably needs to align something to the image and not the control. There has to be a way as I think the photoviewer thingy can show the bitmap width/height?
Reply
#4
I found something here:
http://stackoverflow.com/questions/80326...ternal-lib

Mentions a python module called pillow. And something called PIL.
Reply
#5
Ronie was right. Perhaps I was overthinking this. I didn't realize the controlImage was more of an area with an image in side it. When I made the controlImage width the entire width of the area, and the height being set to 256, it centers every image perfectly.

Thanks for the lesson!
Reply

Logout Mark Read Team Forum Stats Members Help
Image width - what am I doing wrong?0