I am making an android based app that includes image capturing and displaying it on the screen.
I’m currently using Android Studio to develop this application.
I am developing this app with a Xiaomi RedMi note5A/5. The screen resolution is 1280x720. However, its camera can take a much higher resolution image. Will the phone’s screen resolution be able to display that captured imaged at its best resolution or will it be scaled down to fit 1280x720 due to screen limitations.
I’ve tried looking up the method for getSupportedPreviewSizes() method in the library and attempted to use it. The supported preview sizes are only up to 1280x720. Please advise! Thanks
If the picture has more pixels than the screen, then the image must be scaled or cropped in order to be displayed. An easy way to deal with this is to simply set your picture as the source of an ImageView. Android will handle the scaling, so your image can fit the view. See below for a simple example.
myImageView.setImageBitmap(pictureBmp);
Working in android studio. I'm importing an image into an imageview but as I test my app across different devices the images becomes a bit distored. I'm assuming this is because of different resolution/size of the devices. Is there anyway to maintain the same image size across all of the different android devices? Thank you.
First of all your image size must be larger than you're trying to support device(s). If your image is in app resources, you can resize it for hdpi, mdpi, xhdpi, xxhdpi, etc. and if the range is not suitable for the screen(s), you can crop in center or something like that. But if you get this image from a URL, you had better do this with Retrofit that does caching and background task.
Set to your ImageView android:scaleType="centerCrop". That should solve your problem.
I have an ImageView in a RelativeLayout:
<ImageView
android:id="#+id/image"
android:src="#drawable/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
It works on many devices (phones and tablets) and emulators, but does not work on Google Nexus 5 with Android 6. The application works perfectly but the ImageView background is not displayed.
(Image is in drawable folder and I change the image with setImageResource)
I also got the same problem, in which my image show in all android version rest of Android 6.0.
I was testing my application in android 5.0 and android 6.0, that time image shown properly in android 5.0 but in android 6.0 image does not load in Imageview.
I have used src and background both property but did not get the image in Imageview in android 6.0.
Then, To solve this problem I checked my logcat and I got below string in logcat.
W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (3240x5760, max=4096x4096)
I searched related this string and got the solution for this, it is Android 6.0 does not give permission to do the heavy process in UI Thread. If your image is small in size and resolution, then you can use src or background for the load it. but your image is too heavy then Android 6.0 skip this process in UI Thread.
But, You can solve this by use of below solutions.
Solution 1:
Resolve it by use of third party library like Glide for load heavy images.
I have solved it with the use of this.
Solution 2:
Add a drawable-nodpi folder in res, put the image in it and simply use it with src in Imageview tag.
Images come in all shapes and sizes. In many cases they are larger
than required for a typical application user interface (UI). For
example, the system Gallery application displays photos taken using
your Android devices's camera which are typically much higher
resolution than the screen density of your device.
Given that you are working with limited memory, ideally you only want to load a lower resolution version in memory. The lower resolution version should match the size of the UI component that displays it. An image with a higher resolution does not provide any visible benefit, but still takes up precious memory and incurs additional performance overhead due to additional on the fly scaling.
Displays an arbitrary image, such as an icon. The ImageView class can
load images from various sources (such as resources or content
providers), takes care of computing its measurement from the image so
that it can be used in any layout manager, and provides various
display options such as scaling and tinting.
Remove android:adjustViewBounds="true"
Use Small Size (Resolution) oriented image .
Advice
You can use public void setImageResource (int resId)
Sets a drawable as the content of this ImageView.
This does Bitmap reading and decoding on the UI thread, which can
cause a latency hiccup. If that's a concern, consider using
setImageDrawable(android.graphics.drawable.Drawable) or
setImageBitmap(android.graphics.Bitmap) and BitmapFactory instead.
ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.setImageResource(R.drawable.image1);
Read Drawable-hdpi, Drawable-mdpi, Drawable-ldpi Android
To declare different layouts and bitmaps you'd like to use for the
different screens, you must place these alternative resources in
separate directories/folders.
This means that if you generate a 200x200 image for xhdpi devices, you
should generate the same resource in 150x150 for hdpi, 100x100 for
mdpi, and 75x75 for ldpi devices.
I was also facing slightly different image view issue on Nexus 5 with 6.0. It was like, image was coming when I reached to the page (having custom keyboard) but if I tap on device back button, image view was hiding (Hiding Custom keyboard).
So what I did, I removed the android:adjustViewBounds="true from the layout, for me its working fine. If you want, you can remove scaletype also.
Still don't know why its happening. I am waiting for proper solution.
move your image to drawable-nodpi instead of drawable.
Basically if u put a image in drawable folder it will be treated as drawable-mdpi so android will resize to fit xxhdpi that is nexus 5 ,
and since the bitmap becomes large it wont display
I was able to load an imageView on API23.
I had faced similar issue when the image was not getting displayed on certain Mi, Vaio devices. I narrowed it down to be the problem of image resolution being too high for those specific devices. So I used Glide image loader library to lower the resolution of an image only while opening it on image view(else the orignal size was saved in SD card) using the following code.
Glide.with(context).load(imagePath).override(1280,720).fitCenter().into(imageView);
I have an image of rather large resolution (9332 x 5116). When I go to the codename one editor, to add image, I can add the image, but then when I get back into the editor, the left-side menu doesn't display properly. To be more specific, it doesn't redraw when I'm in the Multi-image or All Images menu. The only way to go back to normal is to do a "Delete unused images."
Is this a known issue? I'd hate to sacrifice image quality.
Any advice greatly appreciated.
Thanks.
The image is WAY too big to fit into any device and would crash many devices when they try to open it. The designer wasn't built to handle images so large, you can run it with more RAM but the solution is to use an image of realistic size.
Hi there I'm making a live wallpaper and I want to have an option so that people can disable it being hd (so that low power devices will also be able to use my app). My live wallpaper uses an inputstream and a Movie. Is there anyway I can downscale the quality using code?
The reason I am using movie is because I am using an animated gif for my wallpaper.
(Or do you have to edit the quality of the Canvas that the live wallpaper draws onto the movie each frame?)