CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: load bitmap

  1. #1
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222

    load bitmap

    I can load a bitmap into my VB IDE form and have it displayed in my VB app.

    However, now I want to set a flag to decide which bitmap of two to display. How can I load the bitmap manually from the code? Do I need to set the coordinates manually?

    Thanks
    Kevin Smith

  2. #2
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    You can use the LoadPicture() function, here an example, add one button and one image control to a blank project and try this code, of course you'll need to change the image file name:

    Code:
    Private Sub Command1_Click()
        Image1.Picture = LoadPicture("E:\Images\warden.gif")
    End Sub
    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  3. #3
    Join Date
    Jan 2002
    Location
    somewhere between a variable and a string
    Posts
    214

    Load Bitmap

    Code:
    Option Explicit
    ' Add Component : Picture Clip Control !
    ' Add 2 Command Buttons
    ' Default 1  ( Indexed as 0 and as 1 )
    ' In the Picture Clip Properties window ( to the right )
    ' Set Rows to 2
    ' Columns - default setting
    ' This will allow you to load pictures into 1 picture clip control
    ' and then show them as a slideshow if you wanted to ( as an example )
    ' The Picture Clip file type Limitations though are limited to an .BMP
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Just showing you another option at your fingers
    '
    ' Some code may return errors as I didn't copy and paste anything
    ' just rambled at the top of my head , but it will work .
    ' Hope you find it useful , if not now , maybe later it will come in handy :)
    '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub Form1_Load()
    
    On Error goto LostPhoto
    
        PictureClip1.Picture = LoadPicture(APP.Path & "\MyNudePicture.BMP")
    
    exit sub
    
    LostPhoto:
                      Msg"Someone,Somehow has removed a file, Action Aborted !",vbcritical
    
    End Sub
    
    Private Sub Command1_Click(index as integer)' replace with yours...
    
    with Image1
    
     If 0 then
                   .Picture = PictureClip1.GraphicCell(0)
    Else
         .Picture = PictureClip1.GraphicCell(1)
          end if
    
    end with
    end sub
    How can anyone sell information when all the information that they sell is free at the library ?

    How come Doctors keep getting smarter yet they cannot cure the common cold ?

    If Scientist are right and man evolved from monkey then where did the monkeys' come from ?

    Man I love this little dude that waves => <= He just doesn't stop

  4. #4
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222
    Thanks for your responses... there is one prob. The bitmap cannot be separate from the exe, it must be already loaded in the IDE. Know what I mean?

    So I need 2 bitmaps already loaded in the IDE, and the initial image of the 2 I display will be determined by a flag.

  5. #5
    Join Date
    Dec 2001
    Posts
    6,332
    You can use a resource file, or you can use image controls with the Picture property set from within the IDE, so the exe contains the images.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  6. #6
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222
    Thanks, I tried loading my bitmap from the resource file I made like this:

    frmProgress.pic.Picture = LoadResPicture(101, vbResBitmap)

    When I run the app, I now get this error message:
    "Can't show non-modal form when modal form is displayed."

    Why is this happening? What am I doing wrong?

  7. #7
    Join Date
    Dec 2001
    Posts
    6,332
    Referrencing the form or anything on it will load it, executing any code in the Load sub as well. It seems that the form you have showing when that code is executed is modal at the time. Instead of loading the form and image before they are needed, it might be better to just put pic.Picture = LoadResPicture(101, vbResBitmap) in the Load sub of the form where the picture is. That way, the picture is only loaded when the form is.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  8. #8
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222
    Thanks Wiz, got it working!

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

Featured