dcsimg
Results 1 to 12 of 12

Thread: How to make an array of values that corresponds to an array of images?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    How to make an array of values that corresponds to an array of images?

    I have an array of images in a PictureClip control. It is arranged like this:

    Code:
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
     | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |10 |11 |12 |13 |14 |15 |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
     |16 |17 |18 |19 |20 |21 |22 |23 |24 |25 |26 |27 |28 |29 |30 |31 |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
     |32 |33 |34 |35 |36 |37 |38 |39 |40 |41 |42 |43 |44 |45 |46 |47 |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
     |48 |49 |50 |51 |52 |53 |54 |55 |56 |57 |58 |59 |60 |61 |62 |63 |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
       '                                                           '
       '                                                           '
       '                                                           '
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
     |192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
    In the code I reference each cell using PictureClip1.CellNumber = nnn

    Now I need to place the images somewhere on the Form so I need another array that will contain the X and Y of each image from the Clip.

    So, using the same nnn index number that I used to get the image I want to use it to get the X,Y value out of another array. How do I make this other array that will contain only the X,Y values of each cell in the Clip array?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,628

    Re: How to make an array of values that corresponds to an array of images?

    If you are using CellNumber then why would you need the X and Y?

    In any case it sounds like a trivial problem:

    Code:
    Sub (ByVal Cell As Long, ByRef X As Long, ByRef Y As Long)
        X = Cell Mod 16
        Y = Cell \ 16
    End Sub
    If you want X and Y in pixels then just multiply by pixels per clip.

    What am I missing?

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,628

    Re: How to make an array of values that corresponds to an array of images?

    Ahh, it sounds like you want a different X and Y that corresponds to each clipped subimage.

    If so then why not use two simple arrays or an array of a Class with an X and Y property, or if you insist a UDT?

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,132

    Re: How to make an array of values that corresponds to an array of images?

    I would create a UDT myself and then create an array of that type
    Code:
    Option Explicit
    Private Type Coords
        x As Long
        y As Long
    End Type
    
    Dim MyCoords(207)  As Coords
    
    Private Sub Form_Load()
        MyCoords(0).x = 200
        MyCoords(0).y = 250
        
        Debug.Print "x = " & MyCoords(0).x
        Debug.Print "y = " & MyCoords(0).y
    End Sub

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Re: How to make an array of values that corresponds to an array of images?

    I need the X and Y of where I am going to copy and place the image from the PictureClip array to somewhere on the Form. Each image in the array will have a different X,Y on the Form (not the X,Y of where the image is in the array)

    Basically, the other array would be the same as the PictureClip array but will have two values per cell.

    So, if I make a 2D array how then can I have two values in each cell? Is there a way to have one value and using a math extract out the X and Y values? Kind of like taking a Long value and extracting out the R,G,B values for an image pixel color


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Re: How to make an array of values that corresponds to an array of images?

    I didn't see post 4. I guess a UDT would be the best way to handle this.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to make an array of values that corresponds to an array of images?

    Quote Originally Posted by jmsrickland View Post
    So, if I make a 2D array how then can I have two values in each cell?
    UDT is probably the way to go, but to answer the question, you don't have two values per cell:

    Code:
    Dim MyCoords(207,1) As Long
    
    MyCoords(0,0) = XValue_PictureClip0
    MyCoords(0,1) = YValue_PictureClip0
    MyCoords(1,0) = XValue_PictureClip1
    MyCoords(1,1) = YValue_PictureClip1
    
    etc

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Re: How to make an array of values that corresponds to an array of images?

    Why is UDT better than the 2D array MyCoords(207,1)


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to make an array of values that corresponds to an array of images?

    I don't know if a UDT is more 'efficient' in resource usage but the main advantage I would suggest is the intelisense and 'auto documentation' of the X and Y values. With the UDT, when you type in 'MyCoords(0).' the X and Y items will drop down so you can select the one to use.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,073

    Re: How to make an array of values that corresponds to an array of images?

    OK, so it's a design time advantage


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  11. #11
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,423

    Re: How to make an array of values that corresponds to an array of images?

    I would use a 2d array (matrix). With a 2d array you won't need to loop or anything; when you have x and y, the corresponding value/image will always be at position ArrValues(x,y), using this you have direct (indexed) access.
    Last edited by jcis; Dec 12th, 2013 at 04:39 PM.

  12. #12
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to make an array of values that corresponds to an array of images?

    With a 2d array you won't need to loop or anything
    I think it's the same whether you use a UDT Array or 2D Array

    MyUDT(n).X = XValue
    MyUDT(n).Y = YValue

    MyArray(n, 0) = XValue
    MyArray(n, 1) = YValue

    Both are indexed by 'n' which is the PictureClip.CellNumber.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width