Answer the question
In order to leave comments, you need to log in
How to upload an image in Android Studio with the ability to scale it on the phone?
How to upload an image in Android Studio with the ability to scale it on the phone? Are there links to a resource with ready-made similar projects? If not, then help me do it, explain how to upload your images to Android Studio and, if possible, how to scale them?
Answer the question
In order to leave comments, you need to log in
Here's an example of a function from the book that takes an image by filename and returns a scaled bitmap.
public static Bitmap getScaledBitmap(String path, int destWidth, int destHeight){
//read in the dimensions of the image on disk
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
float srcWidth = options.outWidth;
float srcHeight = options.outHeight;
//figure out how much to scale down by
int inSampleSize = 1;
if(srcHeight > destHeight || srcWidth > destWidth){
if(srcWidth > srcHeight)
inSampleSize = Math.round(srcHeight / destHeight);
else
inSampleSize = Math.round(srcWidth / destWidth);
}
options = new BitmapFactory.Options();
options.inSampleSize = inSampleSize;
//read in and create final bitmap
return BitmapFactory.decodeFile(path, options);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question