Android Question Split an Image

Discussion in 'Android Questions' started by vecino, Jan 30, 2015.

  1. vecino

    vecino Well-Known Member Licensed User

    Hello, how I can split an image?

    Example:
    dividirimagen.png
     
  2. RandomCoder

    RandomCoder Well-Known Member Licensed User

    You need to use a canvas to get each section of the image, see help on canvas here... http://www.b4x.com/android/help/drawing.html#canvas
    They're may be image libraries that could do this but I'm not familiar with which ones to use. What are you wanting to do with the sections of the image?
     
    KZero and vecino like this.
  3. vecino

    vecino Well-Known Member Licensed User

    I want to assign them to different imageview to press each.
     
  4. NJDude

    NJDude Expert Licensed User

    Take a look at THIS class.
     
  5. vecino

    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.
     
  6. klaus

    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.
     
    Peter Simpson and vecino like this.
  7. vecino

    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.
     
  8. vecino

    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.
    Code:
    Dim bex As BitmapExtended
    bex.Initialize(
    "bex")

    img1.Bitmap = bex.createBitmap3( imgSrc.Bitmap,   
    00100100 )
    img2.Bitmap = bex.createBitmap3( imgSrc.Bitmap, 
    1000100100 )
    img3.Bitmap = bex.createBitmap3( imgSrc.Bitmap, 
    2000100100 )
     
  9. vecino

    vecino Well-Known Member Licensed User

    klaus, how is it done? :)
     
  10. klaus

    klaus Expert Licensed User

    The code below calculates the row and column indexes in the Touch event.
    Code:
    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: Feb 2, 2015
    vecino likes this.
  11. vecino

    vecino Well-Known Member Licensed User

    Thank you very much :)
     
  12. warwound

    warwound Expert Licensed User

  13. vecino

    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
     
  14. warwound

    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.
     
    vecino likes this.
  15. Troberg

    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)
     
    vecino likes this.
  16. Troberg

    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 likes this.
  17. vecino

    vecino Well-Known Member Licensed User

    Thank you very much, folks, now I have a lot of information to process :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice