Joan Zapata's PDFview for android - android

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?

Related

Android - SVG scalling and rendering

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.

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.

Android: Resample bitmap as zooming in?

I have some large images that I would like to display to the user. I want them to have the ability to zoom in. I am currently using TouchImageView, and it is working, however, the quality/resolution of the image does not change as I zoom in.
I noticed that some of the Gallery apps appear to be doing this. They load the entire image, at some sampling rate so that it can be displayed without an out of memory. Then as you zoom in, it appears that the quality of the image is getting increased.
Is there example code/library for functionality similar to this?
If you have 1 source image and are zooming in on it you aren't going to magically create resolution where there was none previously. The answer is to either create multiple r-sets or multiple images with different resolutions and load/zoom/scale dynamically, OR downsample the image yourself when displaying it zoomed out at a lower resolution.
For example, consider thumbnail images. They are created as a small sample of the original image. If you zoomed in on that thumbnail it would look horrible. You calculate the best r-set image based on the zoom level and coordinates of your client view.
I think my preference would be to preprocess the large images and create different levels of resolution as I mentioned in the first paragraph. Then as the user zooms in you load a different image. This is similar to how Google maps works for example.
I hope this helps.
I suggest that you use the view provided by Dave Morrissey:
Subsampling Scale Image View
An excerpt from the source:
A custom ImageView for Android with pinch to zoom and subsampled tiles
to support large images. While zooming in, the low resolution, full
size base layer is overlaid with smaller tiles in the best resolution
for the current scale, and tiles are loaded and discarded during
panning to avoid holding too much bitmap data in memory.

Android drag two images on canvas

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.

How to tile and scroll a large image (10000x10000) in android

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.

Categories

Resources