Actually I'm using android-svg library to display SVG files in ImageView. For scrolling and scaling on this image I used calculated values on matrix.postTranslate() and matrix.postScale() and it works fine, but every time when I update matrix it trigger onDraw() method which render whole SVG for this operation. Those SVG files are very big and scrolling with scaling are not smooth if every event trigger rendering again. I want to render this file once and just change viewport for user when scrolling or zooming image. Is it even possible ? If it's then how to achieve it ?
Thanks for any help.
Related
This image is SVG image which is loaded into SVGImageView. I can't fill color into SVG with onTouch listener. I am tired to fill color into particular shape or area. Help me. Thank you.
https://i.stack.imgur.com/96TM5.png
And fill area with different color like this :
https://i.stack.imgur.com/t9zXG.jpg
AFAIK at the moment none of the SVG libraries for Android support interaction. I am the author of AndroidSVG and it is a high priority on my list of things to implement.
If you need it now, however, I think you will need to resort to displaying the SVG in a WebView and using Javascript events to determine what is clicked on.
I'm working with PDFViewer to view a pdf within my app and I loaded a test pdf that displays rather poorly with text edges being blotchy and straight lines having breaks.
If you zoom in it clears(obviously) because it stretches a small area over the same size screen.
If you pinch out to the minimum from a zoomed in image and hold it there, the image is as you would expect it to be. When you release your fingers it seems to perform a final render and this is when the problems come in.
I'm busy going through the draw method and cache manager to perhaps render a better image. Does anyone perhaps have a better solution?
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.
My end goal here is to be able to add two (or more) images to a view/canvas, then turn that canvas into a single bitmap. I've seen many similar SO posts about dragging images around on a view, however, none of them cover dragging multiple images.
I am currently using the matrix commands to rotate and zoom, which work fine but only for one image. The code I am using is similar to this post. The issue here is that using fill_parent on the image will only allow for one image to be dragged because it is on top of the other image. Using wrap_content will only allow the image to be dragged within the confines of how big the image currently is, producing a cropped looking image.
So, is there anyway to edit this code (or use fresh code) to allow multiple images to be dragged and/or zoomed? As I've mentioned, there are many other SO posts about this but none have any solid answers.
Check out the demo app from the project Android Multitouch Controller, pretty much everything is done for you already. It lets you drag, rotate, and scale many images on a custom View. I've used this in the past for a custom image cropper, and it worked out great.
As for turning the resulting Canvas into a Bitmap, I've got a modified version of the Android Multitouch Controller project to do exactly that. You can see that project on GitHub.
I am working in a map project in android. It contains larger image of 10000x10000 resolution. Using this image with Bitmap it gives OutOfMemoryError. So I want to tile and scroll this image. When I scroll image, only visible screen must have tiles and other invisible tiles must be recycled. I spent lots of time but didn't find anything.
Any help will be appreciated.
Provide me better solutions or idea.
as per Dave's recommendation, you can split the image into 1600 parts of 250x250px each. Photoshop does this easily in less than a minute (here). You don't have to worry about writing the html yourself too. Once you have the html (lets call it bigimage.html) and the images folder, place both these in your assets folder and access them this way -
setContentView(webView);
try {
webView.loadUrl("file:///android_asset/bigimage.html";
webView.getSettings().setLoadsImagesAutomatically(true);
} catch (Exception e) {
e.printStackTrace();
}
Starting from API level 10, you can use BitmapRegionDecoder to load specific regions from an image without the need of manually generating the tile images. I've recently developed a lib that provides the visualisation of large images with touch gesture handling. The source code and samples are available at https://github.com/diegocarloslima/ByakuGallery
Someone I know ran into the same problem. They solved it by first splitting the image into square tiles. Then they generate an HTML page that displays the images in a <table> layout and get the built-in browser to display the resulting page. This means the browser manages the visibility of the images, and it gives you bi-directional scrolling and pinch-to-zoom.
This approach is very easy to code, but loses the flexibility of writing your own custom solution. This was for a smaller image (2000x1500 ish) so I'm not sure how it will scale to the dimensions you need.
If you do go this route, make sure you have border="0" cellpadding="0" cellspacing="0" on your table and border="0" on the images to ensure that the joins are seamless.
You could tile your image into square tiles (for example 256x256 px).
You can subclass View, and maintain current offset from the center [0,0] in member variables.
In onDraw(Canvas) you should draw the tiles which are visible based on the current offset (it's easy to calculate which should be visible as you know the current translation offset, size of each tile and size of the screen. Simply draw the tiles as Bitmaps onto the Canvas.
Then handle onTouchEvent in your Activity. You can handle MotionEvent.ACTION_MOVE where you'd only move around the currently visible tiles, and then on MotionEvent.ACTION_UP you'd do a real repaint and invoke a thread to fetch the new tiles (so you won't do an expensive operation on each finger movement). Use View's invalidate() method to force it to repaint after the panning.