Android RemoteControlClient Bitmap Scaling - android

I have successfully included RemoteControlClient in my app. However, I was wondering if there is any way to prevent the bitmaps thrown at it from scaling On all aspects. I can do this in my activity, scaling the vertical, and preserving the aspect , but throwing the scaled bitmap to the client has no effect. It always scales to square, filling the view.
Any suggestions?

I guess, create a black (or transparent?) square bitmap background and center your album artwork or whatever it is on it... Then send a square image to RemoteControlClient.

Related

ImageView bitmap is stretched after activity transition

Is there any specific reason why this is happening?
This is the image after the transition happens.
You haven't provided any code to help us diagnose your problem, but your terrifying image (that looks like Jim Carrey) may be related to the tileMode. Your image looks like it's exhibiting clamping.
Clamping is when the edge color is replicated if the bitmap for an ImageView is smaller in size than the ImageView. These are all the options, along with a suitable picture of Jim:
disabled - Do not tile the bitmap. This is the default value.
clamp - Replicates the edge color.
repeat - Repeats the bitmap in both direction.
mirror - Repeats the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam.
Since it looks like your Bitmap is smaller than your ImageView and I don't think you actually want to use any tile mode (just use the default of disabled), I'd recommend either:
A) Use ImageView's setScaleType() so that the Bitmap resizes to fill the ImageView, using the centerCrop value (though check this blog for more examples), or...
B) Make your Bitmap larger
(I'd recommend A)

Implementation for custom image cropping in Android

I need to implement the custom image cropping instead of using the system cropping (i.e. "com.android.camera.action.CROP"). I need to know the exact position of the cropping bounding box but this information is not retrievable if I choose to use the default cropping. Besides, the bitmap image is down sampled too much by default cropping.
The steps are as following:
Create the original size bitmap from source (using uri). The
original size is about 4000x3000 which is too big.
The user defines the crop area to extract the ROI which results in resizing of the original image to fit the ImageView. (size of ImageView is about 700x700)
Record the position of the bounding box in the ImageView.
Retrieve the cropped area from the original image and create another bitmap for it.
Resize the cropped bitmap to fit the imageview size to show it on the screen.
This approach works on my device (ZTE nuoio with Android 4.3) well. However, the app crashes on Samsung S4 with Android 4.4.4 and Note 4 while performing step 1 probably because of the out-of-memory error.
Therefore, I try to do another approach that creates the bitmap which is down sampled from the source image, rather than having the original size bitmap image.
I need to have the information of the exact position of cropped area from the original image. That is the reason why I didn't use default cropping. Could you please help me out with my case either providing
the solutions to derive the exact coordinates of the bounding box of the cropped image in the original image as a matrix.
how to solve the out-of-memory error in step 1 using the approach I mentioned above.
Or other approach to achieve image cropping with knowing the exact coordinates of cropped area form the original image.
Thank you so much.
For Crop an image and get Coordinates use library Edmodo Croper https://github.com/edmodo/cropper
For Out of memory issue you have to down scale image.

OpenGLRenderer trying to scale down bitmap - when reaching end of ViewPager

App has a ViewPager with several Fragment in it.
When user scrolls to the end of pages, there's this Android gradient effect that indicates there's no more pages (instead of iOS's bounce effect).
When this effect occurs, apps become unresponsive and frames are dropped, while in the log there these lines -
Trying to scale down bitmap for texture (2560x4544 -> 2307x4096)
Scaled bitmap has been successfully created
There's no bitmap in the app of this size and it's running on a QHD (1440 x 2560 pixels) LG G3 display, so I guess some bitmap is scaled up to fit this xxxhdpi resolution, then for some reason scaled down a bit.
Question is - why is it trying to scale down a bitmap when this effect occurs? Can this be avoided?
Is it the gradient effect rendering that is being scaled down?
It stopped when I turned off the over scroll effect (iOS's bounce equivalent). Maybe this effect is an image that's resized before shown, though I don't understand why they don't cache it, if it's true.
viewPager.setOverScrollMode(View.OVER_SCROLL_NEVER);
The problem is with loading some image in your page:
Solutions:
1. if you must load the image use a library named Picasso http://square.github.io/picasso/ to load it
2. if the image is a shape try to make the shape yourself in android.
At all costs avoid loading big images in the xml. even in the newest phones this has a big impact on performance.

Cleanly down-scaling images in Android: can it be done?

I'm having trouble cleanly down-scaling images on Android. I'm looking to scale small PNG images between arbitrary sizes of about 10-100% of their original size.
I've created a sample image to demonstrate the problem and exacerbate the unusual behaviors I'm seeing in Android's image scaler:
The above image is a screenshot from an Android device with some annotations added. I've also added the same images in a second column on the left side showing how they are rendered with a linear scaling by "The GIMP" (GNU Image Manipulation Program).
The base image consists of a checkerboard pattern background of red and blue pixels. On that background I've drawn some 1px-wide yellow lines and fairly thin green text. The image is 288x288 pixels.
When scaling the image to 1/3 of its original dimensions, Android seems to simply grab one in nine pixels, throwing out all other data. Some of the yellow lines disappear entirely as a result. Remarkably, the checkerboard pattern remains intact (which is simply a result of every 3rd pixel being used).
When scaling the image to a dimension of near-but-not-exactly 50% of its original size, e.g., 142x142 or 143x143, the scaler creates some fairly large anomalies/artifacts on the image.
At 50% size (144x144), the image looks correct.
The test image does bring out the worst of the image scaler, but "normal" PNG icon images are severely impacted as well. From 10-33% or so the images aren't properly resampled, and thus appear extremely "bitmapped". And certain larger size images have very strange anomalies in them at certain sizes.
If anyone knows a means to disable this strange scaling behavior, even at a performance cost, I'd greatly appreciate knowing about it. It can certainly be solved by writing an algorithm that works directly on the pixels of bitmaps, but I'm hopeful that isn't the only option.
Also noteworthy is the fact that all image work is being done with ARGB_8888 Bitmap.Configs. I've tried manipulating image size by setting maxwidth/maxheight on ImageViews, by using Bitmap.createScaledBitmap(), and by using Bitmap.createBitmap with a Matrix. All attempts have this same result. Bitmap filtering is enabled.
Thanks again for any suggestions!
Using Bitmap.createScaledBitmap() and Bitmap.createBitmap with a Matrix is the same; see the source for Bitmap.createScaledBitmap (which hasn't changed since Android 2).
On Android 4.0+, using a matrix (as in Bitmap.createScaledBitmap) allows hardware-accelerated operations if enabled (enabled by default on 4.1+ IIRC), thus we doesn't have direct control over what is being done and how it is done.
That means you'll have to implement your own scaling method using the desired (here, linear) filtering; either by pixel processing; or using OpenGL ES with the good filter, but it may not be available on all devices.

Android - Setting a bitmap as the wallpaper

As part of this application I am making, I want to change my wallpaper on my android device based on a bitmap that the user has selected.
I am able to change the background. However, the background is a completely distorted version of the bitmap. Any idea as to why this would happen?Here is my code:
Bitmap bitmap = ((BitmapDrawable)currentDrawable).getBitmap();
this.setWallpaper(bitmap);
My bitmap has a width of 240px and height of 180px. My emulator is of a size 480px by 800px.
I can scale my bitmap to 480px. However, the bitmap still ends up being distorted on the android wallpaper. Any thoughts on how this can be fixed?
Thanks in advance
You should create multiple images, for each potential (and common) resolution. You don't want any scaling, or the image will be distorted.
UPDATE:
Here is a ton of good information on support multiple screen sizes:
http://developer.android.com/guide/practices/screens_support.html
The wallpaper used by the default Launcher is bigger than the actual screen, that's why you can scroll the content and the wallpaper too.

Categories

Resources