I found this sample code below. The decodeResource might be used for internal images, but I'd probably use this for files more since I'd know internal resources sizes to hardcode the ratios and max values...so whichever correct function for that to load from file would be needed. I just want to process a file and get the width and height without loading it into memory since the images may be large. I don't want to add a library just for this though (VBBitmap I think uses this method, but has other functions I don't need). Is there anything that does this in B4A or an alternative way either using another way like in the next paragraph or converting this code to use in B4A with Reflection?
Bitmap.InitializeSample and LoadBitmapSample seem to do some of this and allow for specifying a max size for each and appears to keep aspect ratio. Without using Gravity.Fill though the image is actually still bigger than the ImageView, so wastes resources. On the device I'm on now the Density is 1.5 and that is about how much bigger the picture is. On other devices the image may be even bigger than needed with higher density. I tried dividing the width and height of the ImageView that I pass to the sample methods by the Density which gets very close, but chops off the edges a bit like it is still a little too large.
So, how do I go about getting the image to be within the exact bounds I give for max width/height? I did figure out that specifying -1 for either value just uses the other value and keeps the ratio...which is nice, but still doesn't get it exact. There doesn't appear to be a padding issue either because the image goes right to the edges of the ImageView.
Bitmap.InitializeSample and LoadBitmapSample seem to do some of this and allow for specifying a max size for each and appears to keep aspect ratio. Without using Gravity.Fill though the image is actually still bigger than the ImageView, so wastes resources. On the device I'm on now the Density is 1.5 and that is about how much bigger the picture is. On other devices the image may be even bigger than needed with higher density. I tried dividing the width and height of the ImageView that I pass to the sample methods by the Density which gets very close, but chops off the edges a bit like it is still a little too large.
So, how do I go about getting the image to be within the exact bounds I give for max width/height? I did figure out that specifying -1 for either value just uses the other value and keeps the ratio...which is nice, but still doesn't get it exact. There doesn't appear to be a padding issue either because the image goes right to the edges of the ImageView.
B4X:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;