Phonegap : Scaling HTML5 canvas for smaller screens - android

This is a Phonegap android app that uses HTML5 canvas (preferably with fabricjs). One of the required functionality is that it can load image from gallery/take picture from camera and save the image after some preset edits. The input image/image taken from camera may be different in size depending on the device but the output image needs to be of fixed size (900x450 in this case) always. The app is supposed to support devices with both smaller and bigger screens. I can load the image to the canvas of preset size and export data url (after edits). But how do I get around using it on a smaller screen? I can display a smaller scaled down canvas and do manipulations there and do the actual stuff on a hidden canvas of the required size, but that would be very messy. Is there a better approach to this?

How about just “scaling” your canvas element by setting its width/height via CSS?
This should not affect the actual pixel size of the canvas element.

Related

image resolution for banner and logo

I have a problem with image size and resolution on my app I need to upload an image then I want to resize it to all screen, which is the best image size and width/height for banner and logo and I need a good tool that resizes image?
You will want to remake the logo in a vector format, this relies on positions rather than individual pixels.
In other words no matter how big you make the image, it will always be crisp and sharp.
If I remember to back when I dabbled in Android development I seem to remember android making different sized versions of the logo and banner... Therefore what I would do is create the logo in a vector program such as Inkscape or Adobe Illustrator, and exporting it as a high quality png, this way if you need to resize it in the future, you just export it at a different size and you're good to go.

Imageview looks like mapview

I have a image (resolution 8328x3987). And I want to load that image in my app with zoom controls for better viewing.
As we all know that Android will not load large images directly on device (like in my example). So Android system suggested us to scale down the image to load large images. I have tried this and scale my image upto four times as:
options.inSampleSize = 4;
Using this way my image will displayed on screen, but when I zoom-in the image then this image becomes unreadable (text becomes very blurry), this is because, maybe I scale down the image before showing?
But when I see that image in to device's default gallery app (Android Lollipop, Photos app), then this image looks like a mapview (only visible portion is readable and outside is blurry, and when I move the image then visible area becomes readable) when I zoomed in at max level. So my questions is:
Is Android lollipop added any new way to load large files that looks like mapview?
If not, then do you have an idea how that apps do this or any example?
Reducing the sample size of an image that big will not work at all.(very very bad resolution and memory consumption)
I suggest you to divide image to tiles and recycle the views just like map views do.
This library may help you. Or you can do it your way too.

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