Results 1 to 5 of 5

Thread: Bitmap arrays

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Location
    England
    Posts
    7

    Angry Bitmap arrays

    Hi all!

    I've been using VB6 for a few years now and I've finally decided to move to .NET a few weeks ago.

    I've now got a small problem, I'll explain it the best I can...


    I want an array of the bitmap variable with the resolution declared.

    For example: -

    Dim bmpPicture(10) As New Bitmap(320,240)


    Problem 1: It won't allow the "new" keyword and if I take it out the resolution can't be declared.

    Problem 2: If I just do: -


    Dim bmpPicture(10) as Bitmap

    bmpPicture(0).SetResolution(320,240)

    OR

    bmpPicture(0).SetPixel(320,240,Color.Black)


    ...I get a run-time error, something about a null exception or reference on those lines.

    I can use the bitmap variable OK but I can't get it to work as an array - Which is what I want!!!


    What is going on? I'm confused! VB.NET so far seems to be a different lauguage!!!

    I hope someone can help me since I'm new to VB.NET and I've been trying to get it working for a week now!


    Thanks in advance.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    To make the bitmap you have to load it from something else instead of out right. For instance from a file like this:
    VB Code:
    1. Dim bmp As Bitmap = Bitmap.FromFile("..mybmp.bmp")

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    No, that isn't true, the image object can't be created directly, but the bitmap can (I do it all the time). Here is what the docs say about the image class:
    An abstract base class that provides functionality for Bitmap, Icon and Metafile descended classes.
    Now, to figure out how to create an array of bitmap objects, you do this (this is also how the MSDN library suggests to do it):
    VB Code:
    1. Dim bmpPicture(10) As Bitmap
    2. Dim iCounter As Integer
    3.  
    4. For iCounter = 0 to 10
    5.     bmpPicture(iCounter) = New Bitmap(320,240)
    6. Next
    7.  
    8. 'Now do what you want with them.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Location
    England
    Posts
    7
    hellswraith: Thanks alot! That code did the trick! I searched the MSDN but found nothing! Where excatly did you find it?

    Thanks for your quick response.

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I can't remember now, but I was searching with the words 'arrays' and 'objects'.

    Glad to hear it works.

Posting Permissions

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



Click Here to Expand Forum to Full Width