Android Question Split an Image

vecino

Well-Known Member
Licensed User
Hi, thanks, I think is not what I want.
What I need is to divide an image into several parts.
 

klaus

Expert
Licensed User
If I understand your problem well, you want an event raised when you touch the ImageView.
I would use one Panel with the whole image instead of a set of ImageViews.
And in the Touch event calculate from the X and Y coordinates the part of the image where you touch it and act according to this.
 

vecino

Well-Known Member
Licensed User
Hi, thanks, it's a good idea.
Although was thinking of dividing the image and then add each piece a "imageview" different.
 

vecino

Well-Known Member
Licensed User
Hi, I have found the solution.
The "BitmapExtended" library.
Thank you, friends.

For example, I have an image of 300x100 and I divide it into 3 parts.
B4X:
Dim bex As BitmapExtended
bex.Initialize("bex")

img1.Bitmap = bex.createBitmap3( imgSrc.Bitmap,   0, 0, 100, 100 )
img2.Bitmap = bex.createBitmap3( imgSrc.Bitmap, 100, 0, 100, 100 )
img3.Bitmap = bex.createBitmap3( imgSrc.Bitmap, 200, 0, 100, 100 )
 

klaus

Expert
Licensed User
The code below calculates the row and column indexes in the Touch event.
B4X:
Row = Floor(Y / Panel.Height * NumberOfRows)
Column = Floor(X / Panel.Width * NumberOfColumns)
If you have only one row you can omit the first equation.
 
Last edited:

vecino

Well-Known Member
Licensed User
Hi, thanks for the information.
I have a question but do not know if I should create another thread. It is this:

Is there any library to mark areas?
For example, touching a map and that the country is displayed.
Thanks and regards.

mapa.jpg
 

warwound

Expert
Licensed User
There is the ScreenHotspots code module: http://www.b4x.com/android/forum/threads/code-module-hotspots.27614/
Though i'm not sure if it'll be much use for your map - not sure if it can detect a hit on a polygon shaped country area.

And there is my Spatialite library: http://www.b4x.com/android/forum/threads/spatialite.36296/#content
Post #2 in that thread contains an example that detects whether a coordinate is within a country bounds.

You can use a GroundOverlay on a GoogleMap to display your map image: http://www.b4x.com/android/forum/threads/google-maps-android-v2-tutorial.24415/page-3#post-152012

So i'd suggest:
  • Display your image as a GroundOverlay on a GoogleMap.
    You can set the GoogleMap MapType to NONE so that only your image displays (no tiles underneath) if that's what you require.
  • Detect clicks on the GoogleMap.
    The clicks will be LatLng objects.
  • Use a Spatialite database to find out if the clicked coordinate (the LatLng) is within a country bounds.

Martin.
 

Troberg

Well-Known Member
Licensed User
If it's a fixed bitmap map, I'd go the route of hit colors.

Behind the scenes, I'd have an additional bitmap, with the same size as the first, where each country is a single, unique color. Finland red, Egypt white, Germany black and so on. Then, when you get a click on the map, check the color on the same coordinate on the color hitmap, and reference to a table. So, a click on a red pixel means Finland.

To light up the countries, I would then try to generate an alpha overlay map from the color map. In other words, (assuming we selected Finland), create an alpha overlay where all the red pixels in the hitmap are fully transparent and everything else is, say, 75% transparent, and color of the entire overlay is black. Then, just overlay that map on the display map. Finland will be at full brightness, the rest will be slightly dimmed. (Of course, these overlay maps could also be pregenerated, but that would require a full size image for each country, so it would be pretty wasteful.)

(bonus points to whoever can spot the hidden reference in this post)
 

Troberg

Well-Known Member
Licensed User
A small addition to the above post:

The same technique (hit colors) is useful in many other applications. I once made a remote control application for Windows, with user defined controls. Basically, it went like this:

* One display bitmap with the image of the remote control.
* One bitmap with the color map (easily done by coloring the display image).
* On script file, with "events" for each hit color.

So, when the user clicked a button with the hit color red, I read the script file and ran the script for red. The script language was VBScript with various specific enhancements for sending remote key presses, DDE messages, TCP/IP messages and so on.

Dead simple, and yet a quite powerful application that was easy (for a power user) to customize. For example, setting up a minimal remote control for VLC took me about ten minutes, most of it in PaintShop.

One small note if you do this on Windows: Windows has a bug, in that, when you ask for the color of a pixel, it does not return the color as it is in the bitmap, it returns the color which the pixel is displayed as on screen, which depends on bit depth, gamma correction and so on. This means that either you need to do your own bitmap decoding (easy if you use uncompressed BMP) or test the color with a certain allowance for variation. Extremely annoying, and wrecks a lot of otherwise simple solutions.
 

vecino

Well-Known Member
Licensed User
Thank you very much, folks, now I have a lot of information to process :)
 
Top