Results 1 to 8 of 8

Thread: display image using gdi

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    57

    display image using gdi

    ive been reading a ton of articles about vb.net and GDI, but for some reason, i cant get an image to be displayed on my form.

    ive tried everything.

    eventually, i want to be able to rotate this image according to sensor inputs, but for now, i am concentrating on just getting this image to appear.

    can someone tell me... what headers i need to include, what subs/functions i need, and what variables are supposed to be declared.

  2. #2
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: display image using gdi

    I assume you mean GDI+

    VB Code:
    1. Me.CreateGraphics.DrawImageUnscaled(Image.FromFile("c:\myimage.bmp"), 0,0)
    "so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: display image using gdi

    Check out this thread by the GDI+ Guru
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: display image using gdi

    That link has more to do with manually drawing shapes. If you want to draw an image then just use Me.CreateGraphics.DrawImage(MyImage,0,0) nothing else required.
    I don't live here any more.

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: display image using gdi

    If you want to rotate the image then you need one of the overloads of DrawImage that takes an image and a pointf array as arguments.
    I don't live here any more.

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    57

    Re: display image using gdi

    thanks guys, i tried the me.creategraphics, but it does not draw the image. i know the image is being found, because if i wereto us a wrong filename, it shows an error.


    the form is just a gray form, no image.

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.CreateGraphics.DrawImageUnscaled(Image.FromFile("C:\Documents and Settings\Cohn\My Documents\My Pictures\eclipse.jpg"), 0, 0)
    
     End Sub

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: display image using gdi

    You need to do the drawing in the forms paint event so it will persist and redraw when the forms state or size change.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    57

    Re: display image using gdi

    is this what the code should look like for the function header?
    Code:
    Private Sub PictureBox1a(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    ?

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