nativescript-bitmap-factory
nativescript-bitmap-factory copied to clipboard
Pixels vs DIP (Device Independent Pixels) Causing Issues
My experiments suggest that different functions assume different pixel units:
- BitmapFactory.create() expects "actual" pixel dimensions
- insert() reads the imageSource.width/height and treats them as "actual" pixel dimensions (even though these properties are most often measured in DIP)
- resizeHeight() expects DIP dimension
px = actual pixels DIP = device independent pixels
Is there a logic to this? Let's say I want to create a new empty 1000x1000 bitmap:
BitmapFactory.create(1000, 1000)
I then have a 1000x1000px image which I want to cover the entire bitmap so I try:
insert(image)
What I get is a mostly blank bitmap with the upper left corner filled with the inserted image. This is because image.height and image.width are measured in DIP, not px, but the insert function assumes that the values are always in px. I cannot compensate for image.height and image.width by multiplything them with the screen scale, because they are read-only properties. Is there a way around this?
Any help is greatly appreciated! :)