G gadgetmonster Active Member Licensed User Longtime User May 20, 2013 #1 Hi All My Activity has an image view whose width is 100%x (720 in my case) and has a height set to 384. What I am trying to do is take a photo that the user has selected and set the width of that photo to the width of the image view and then centre the resized photo in the image view. I successfully get the width and height of the photo (1632 x 1224) and run it through the following code to get the new photo size based on the width of my image view (Yes width is held in array pos 1 and height in 0). Code: Dim scale As Float = Activity.Width / bitmapSize(1) newWidth = bitmapSize(1) * scale newHeight = bitmapSize(0) * scale This works and gives me a new size of 720 x 540. So far so good. So now I use the following to create a new bitmap at that size: Code: Dim scaledImage As Bitmap = LoadBitmapSample(entry.PhotoDir, entry.PhotoFilename, newWidth, newHeight) If the image is landscape this results in an image which is bigger than I specified but that is ok but if its portrait the scaledimage is the same size as the original which is not so good. When I then do this: Code: imgPhoto.Bitmap = scaledImage The image is not the reduced image but looks like the original sized image (landscape and portrait). What am I doing wrong? Last edited: May 20, 2013
Hi All My Activity has an image view whose width is 100%x (720 in my case) and has a height set to 384. What I am trying to do is take a photo that the user has selected and set the width of that photo to the width of the image view and then centre the resized photo in the image view. I successfully get the width and height of the photo (1632 x 1224) and run it through the following code to get the new photo size based on the width of my image view (Yes width is held in array pos 1 and height in 0). Code: Dim scale As Float = Activity.Width / bitmapSize(1) newWidth = bitmapSize(1) * scale newHeight = bitmapSize(0) * scale This works and gives me a new size of 720 x 540. So far so good. So now I use the following to create a new bitmap at that size: Code: Dim scaledImage As Bitmap = LoadBitmapSample(entry.PhotoDir, entry.PhotoFilename, newWidth, newHeight) If the image is landscape this results in an image which is bigger than I specified but that is ok but if its portrait the scaledimage is the same size as the original which is not so good. When I then do this: Code: imgPhoto.Bitmap = scaledImage The image is not the reduced image but looks like the original sized image (landscape and portrait). What am I doing wrong?
Erel B4X founder Staff member Licensed User Longtime User May 21, 2013 #2 LoadBitmapSample will return an image that may be larger than the specified values. The purpose of LoadBitmapSample is to quickly load a sampled image so less memory is required. You should use CreateScaledBitmap (with Reflection library): http://www.b4x.com/forum/bugs-wishlist/21439-wish-createscaledbitmap-core-function.html#post123936 Upvote 0
LoadBitmapSample will return an image that may be larger than the specified values. The purpose of LoadBitmapSample is to quickly load a sampled image so less memory is required. You should use CreateScaledBitmap (with Reflection library): http://www.b4x.com/forum/bugs-wishlist/21439-wish-createscaledbitmap-core-function.html#post123936
G gadgetmonster Active Member Licensed User Longtime User May 21, 2013 #3 Thanks Erel. I used your code found at http://www.b4x.com/forum/basic4android-updates-questions/24907-live-wallpaper-background.html#post144401 which did the trick Upvote 0
Thanks Erel. I used your code found at http://www.b4x.com/forum/basic4android-updates-questions/24907-live-wallpaper-background.html#post144401 which did the trick