File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes View for scrollable, zoomable, clickable image? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Mobile » Android
Reply Bookmark "View for scrollable, zoomable, clickable image?" Watch "View for scrollable, zoomable, clickable image?" New topic
Author

View for scrollable, zoomable, clickable image?

HaoZhe Xu
Ranch Hand

Joined: Nov 03, 2003
Posts: 222
Hi, I need to show an image which is actually a map with coloured areas, also I need to be able to:
1. zoom in and out using two fingers
2. scroll the image as it is bigger than screen
3. clicks on the image, get clicked area pixel value(color), so that I know which area the user clicks

I searched many hours, tried many approaches:
1. Write a class that extends View, and display a Bitmap, I found a thread in the forum about it, but there is no zoom, and the scroll is not natural.
2. Use a WebView to display HTML file that contains the image, so there is zoom and scroll functionalities, however, I cannot control the limit of zoom in/out, also, when the user clicks, I'm not sure if I can get the position on the image map by adding scrollX, scrollY with touchX, touchY. As the image may be scaled up/down, also, there may be paddings that WebView adds to its content.

This really drives me crazy, can anyone help?

Thanks in advance!


[url]Olnex.net[/url]
[SCJP 1.2, SCJD, SCWCD]
Dave MacLean
author
Ranch Hand

Joined: May 10, 2011
Posts: 46

If you're displaying a map, could you use the Android MapView instead of trying to manipulate your own image? MapView has everything you're looking for and is a whole lot easier than trying to manage zoom, scrollbars, etc. Plus, I'm worried about how you'll handle large images. There have been lots of people who have their apps crash because they're trying to load a large image all at once and their app is killed because it's using too much memory. The way around that problem is to work with tiles of the full image, but you can imagine how complicated that gets in a hurry, especially when you try to add zoom in/out.

- dave


Dave MacLean our book (Pro Android 3)
HaoZhe Xu
Ranch Hand

Joined: Nov 03, 2003
Posts: 222
Thanks for your reply, but I'm not sure if I can provide my own image to MapView?
Dave MacLean
author
Ranch Hand

Joined: May 10, 2011
Posts: 46

You said your image was a map. Is it not a map from Earth?
HaoZhe Xu
Ranch Hand

Joined: Nov 03, 2003
Posts: 222
Dave MacLean wrote:You said your image was a map. Is it not a map from Earth?


It is a map, but the file is just a plain png file.
Dave MacLean
author
Ranch Hand

Joined: May 10, 2011
Posts: 46

I don't believe there's a way to use your own image with MapView, and I wasn't suggesting that. I'm sorry if I caused confusion. Could you not use your image file but instead use the Google Maps and everything that comes with it? Then you would be using MapView and a MapActivity, and you'd get the pinch to zoom, scrolling, and the ability to receive a user's touch to select a location on the map. You'd specify the starting location for the map so it would be where you want it to be when the user first launches the application. There are ways you could restrict the zooming and the panning if you want to. If you need to put markers on the map, that's not hard to do at all. If you're displaying a map to the user, wouldn't you want the functionality to be similar to how other maps work on Android? Without having to reinvent it all yourself? Unfortunately, I'm not aware of a robust image manipulation library for Android that mimics what you can do with maps in MapView. It's possible to do scrollbars, and it's possible to implement the pinch gesture in Android 2.1 and below, or you can use the supported pinch gesture for images in Android 2.2 and above (see the ScaleGestureDetector class). We covered both techniques in chapter 25. The as far as detecting touches and mapping them to a coordinate on the image, that can be done with touch callbacks, also covered in chapter 25. It would be a lot to cover in this post I'm afraid.

- dave
 
 
subject: View for scrollable, zoomable, clickable image?
 
Threads others viewed
Zooming Images
Image viewer with drag/zoom and operations on the image?
problem with setting scrollbar value
Displaying GIF/PNG image files in a Java Swing application
How to use zoom controls on TextView in Android ?
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture