• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

View for scrollable, zoomable, clickable image?

 
HaoZhe Xu
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Dave MacLean
author
Ranch Hand
Posts: 49
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
HaoZhe Xu
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply, but I'm not sure if I can provide my own image to MapView?
 
Dave MacLean
author
Ranch Hand
Posts: 49
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said your image was a map. Is it not a map from Earth?
 
HaoZhe Xu
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic