Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Load bitmap from resource in VB with GDI Api

Load bitmap from resource in VB with GDI Api

Scheduled Pinned Locked Moved Visual Basic
graphicscomjsonhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi I have a ActiveX control in V.Basic and need to load a bitmap and obtain the handle to use with API functions eg: SelectObject,GetObject,TransparentBlt,etc. It´s work fine if the image is loaded from a file eg: hImageGray = LoadImage(App.hInstance, "c:\gray.bmp", IMAGE_BITMAP, 0, 0, LR_COLOR Or LR_LOADFROMFILE) The problem is when I try to load the bitmap from a resource file added in the ActiveX control project. I try from different methods: "ID_GRAY = 102 hImageGray = LoadImage(App.hInstance, CLng(ID_GRAY), IMAGE_BITMAP, 0, 0, LR_COLOR )" " LoadBitmap(App.hInstance, ID_GRAY)" "LoadBitmap(App.hInstance, "102") " Ever with the same result. No work". Also try to use the v.Basic method to load the image with LoadResPicture, returning a IPictureDisp with the image loaded. This solution have a problem: the handle property of IPictureDisp isn't a bitmap handle to use with the GDI API´s. Any ideas to solve this problem??? Thank´s (and sorry by my bad english! :-) MrSparc.

    M 1 Reply Last reply
    0
    • A Anonymous

      Hi I have a ActiveX control in V.Basic and need to load a bitmap and obtain the handle to use with API functions eg: SelectObject,GetObject,TransparentBlt,etc. It´s work fine if the image is loaded from a file eg: hImageGray = LoadImage(App.hInstance, "c:\gray.bmp", IMAGE_BITMAP, 0, 0, LR_COLOR Or LR_LOADFROMFILE) The problem is when I try to load the bitmap from a resource file added in the ActiveX control project. I try from different methods: "ID_GRAY = 102 hImageGray = LoadImage(App.hInstance, CLng(ID_GRAY), IMAGE_BITMAP, 0, 0, LR_COLOR )" " LoadBitmap(App.hInstance, ID_GRAY)" "LoadBitmap(App.hInstance, "102") " Ever with the same result. No work". Also try to use the v.Basic method to load the image with LoadResPicture, returning a IPictureDisp with the image loaded. This solution have a problem: the handle property of IPictureDisp isn't a bitmap handle to use with the GDI API´s. Any ideas to solve this problem??? Thank´s (and sorry by my bad english! :-) MrSparc.

      M Offline
      M Offline
      mirano
      wrote on last edited by
      #2

      Yes, thanks for you help. Now you are right, the variable does not get set to null at once, but if I try to create a new DC and select an old hBitmap in it, it return error...meaning a bitmap has been deleted successfully. Thanks again. .

      L 1 Reply Last reply
      0
      • M mirano

        Yes, thanks for you help. Now you are right, the variable does not get set to null at once, but if I try to create a new DC and select an old hBitmap in it, it return error...meaning a bitmap has been deleted successfully. Thanks again. .

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Haha...sorry man, I clicked it by accident, I actually wanted to reply to your answer to me just two lines before yours in this table. Anyways, with respect to your question, I had the same problem and never succeeded in loading a bitmap from the resource. I perused all the books I had, Web sites, posted the same question at a several developer, sites...but nope, no answer. I guess it is not possible to explain to an API functions to use a bitmap from a VB resource. They made those wrapper functions to retreive an object from the resource, like LoadResPicture and alike, but it was never meant to be used by API functions. I also find it strange, for it is only logical if you use LR_LOADFROMFILE that you can use another constant to retreive a bitmap from the resource for example...but I don't think it is possible. Anyways, thanks for your answer to my inquiry, you were absolutelly right.

        A 1 Reply Last reply
        0
        • L Lost User

          Haha...sorry man, I clicked it by accident, I actually wanted to reply to your answer to me just two lines before yours in this table. Anyways, with respect to your question, I had the same problem and never succeeded in loading a bitmap from the resource. I perused all the books I had, Web sites, posted the same question at a several developer, sites...but nope, no answer. I guess it is not possible to explain to an API functions to use a bitmap from a VB resource. They made those wrapper functions to retreive an object from the resource, like LoadResPicture and alike, but it was never meant to be used by API functions. I also find it strange, for it is only logical if you use LR_LOADFROMFILE that you can use another constant to retreive a bitmap from the resource for example...but I don't think it is possible. Anyways, thanks for your answer to my inquiry, you were absolutelly right.

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          This is THE solution: The solution to load the resource of bitmap in a StdPicture object is really effective!. I tried to use handle property of the IPictureDisp that returned the LoadResPicture but it failed because he is not handle of bitmap. Nevertheless, if we assigned the IPictureDisp returned by LoadResPicture in a StdPicture object, the StdPicture.handle is perfect bitmap handle!! This is the solution that I implemented : Dim tBitmap As BITMAP Dim iRes As Integer Dim picTemp As New StdPicture ' 102 is the ID of a Bitmap in the .res file. Set picTemp = LoadResPicture(102, vbResBitmap) hImageGray = picTemp.handle If hImageGray <> 0 Then GetObjectAPI hImageGray, Len(tBitmap), tBitmap ' bla bla bla bla..... ........ DeleteObject hImageGray ' I think that this DeleteObject could be cleared since bitmap ' would have to be destroyed when Set picTemp = Nothing, ' but by the doubts that Bill has forgotten to him.... :-) End If Set picTemp = Nothing This works excellent. Mike_spice, when I discovered the solution jumped in a leg. I hope that it serves so much to you as it served my, since in my case, it had a ActiveX and it was already thinking the revolting thing that it would be to distribute bitmap along with the OCX . MrSparc.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups