Announcement

Collapse
No announcement yet.

FreeImage library and DDT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • FreeImage library and DDT

    I found a sample in the source forum that displays JPG and other images using the FreeImage library and it seems to work pretty well, but it uses SDK style coding. Is it possible to get this into a DDT GRAPHIC CONTROL?

    I tried using the handle returned by FreeImage_Load with GRAPHIC COPY to copy it into a DDT GRAPHIC BITMAP and then to use GRAPHIC STRETCH to move that into the GRAPHIC CONTROL, but that didn't work. Actually it acted like it was working and gave me a nearly black GRAPHIC CONTROL. I would have expected it to stay white but I don't know where the black is coming from.

    I plan to work on this some more in the morning and if I don't get anywhere I'll clean up the code and post it. It's the code I got with the sample that I've added my own lines to and I haven't removed a lot of now extraneous stuff so I hate posting that till I clean it up a little.

    Any thoughts will be appreciated.

    Barry

  • #2
    Hi Barry,

    Try:
    http://www.jose.it-berater.org/smffo...cseen#msg11016

    Scroll to second post for samples in DDT and SDK.
    Regards,
    Marc

    Comment


    • #3
      Thanks, but that's the code I started with. I got it some time ago and just started playing at it and I guess I forgot where I got it.

      That works just fine for putting the bitmap onto the dialog's client area. I'd like to get it into a DDT graphic bitmap and eventually into a graphic control.

      I'm still playing with it and not having much luck yet but I haven't given up. I don't really understand what's going on and I'm learning a little about device contexts, etc.

      Any tips on how to get this into into a DDT graphic bitmap will be appreciated. At this point I'd rather have suggestions than code, although that might change.

      Barry

      Comment


      • #4
        I'll post some additional code later, but as a start did you look at the VB6 wrappers that come with freedimage? That would be my first place to look.

        I've not used it myself but I'm interested. I'll go take a look and see if I can generate/share a few DDT examples.

        Comment


        • #5
          Originally posted by Gary Beene View Post
          I'll post some additional code later, but as a start did you look at the VB6 wrappers that come with freedimage? That would be my first place to look.

          I've not used it myself but I'm interested. I'll go take a look and see if I can generate/share a few DDT examples.
          I know very little about VB. I wrote some DLL's at work in, I think, the Win 3.1 days, that let VB access SQL Server. That's practically my only Windows programming experience. I had to write some VB code to test that and that was my only VB experience. I think it was VB 1 or 2. I'm not sure.

          Anyway, at this point I think I'd be better off with an explanation of how it might work, although if you do write some code I will give that a try.

          What I'm trying to do is to use the handle of the image loaded by FreeImage and the handle of the graphic bitmap to use graphic copy to copy it into the bitmap so I can use it with DDT graphic functions. So far that hasn't worked and I'm not sure if it really should work.

          I've also tried modifying the code in the original sample that copies the images to the dialog, but I know very little about device contexts. Also I did this in pbmain, not in response to the %WM_PAINT message because I'm not sure %WM_PAINT is really involved since there's nothing on the screen at this point. I'm not sure that's right either.

          Basically I'm groping in the dark.

          I thought if I could get the image into the graphic control then I'd be able to use the DDT graphic stuff with it, and I'm somewhat familiar with them. I want to be able to do simple graphics stuff that involves JPG files without having to get into a long learning curve such as is seemingly needed for GDI+.

          Barry

          Comment


          • #6
            What I'm trying to do is to use the handle of the image loaded by FreeImage and the handle of the graphic bitmap to use graphic copy to copy it into the bitmap so I can use it with DDT graphic functions. So far that hasn't worked and I'm not sure if it really should work.
            I do not believe it is supposed to work. It think both the "hWin" returned by GRAPHIC WINDOW NEW and the "hctrl" returned by CONTROL HANDLE ('CONTROL ADD GRAPHIC') are proprietary handles, usable only by the GRAPHICS XXXX statements.

            But loading an image file for use with the PB GRAPHICS statements I know is in the command set; maybe for this particular screen/control in this application you can use an "All-DDT" solution?

            Maybe something like
            Code:
               Load_Image_using_library   TO somehandle
               Save_loaded_image (somehandle)  TO somediskfile$      
               CONTROL ADD GRAPHIC  hDlg, SomeDiskfile$.........
            ?????

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Originally posted by Michael Mattias View Post
              But loading an image file for use with the PB GRAPHICS statements I know is in the command set; maybe for this particular screen/control in this application you can use an "All-DDT" solution?

              MCM
              I can load BMP images for use with DDT just fine. The problem is loading JPG and GIF and PNG images.

              Barry

              Comment


              • #8
                I don't know what you want to do with these PNG and GIF and JPEG images (code not shown), but LoadImage() will handle those, and displaying them in a control is not all that hard. I'll bet there are plenty of demos right here from which you can start.

                The controls themselves can be "ddt-managed" but I believe the PB graphics handling functions are reserved for use with PB-created graphics objects. (This should really be in the help file somewhere).
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Load image can handle bitmaps, cursors and icons, not .jpg, .gif or .png files.

                  FreeImage returns DIB (Device Independent Bitmap) handles, so you have to use the API DIB functions.
                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                  Comment


                  • #10
                    Hi Barry,

                    This is an example adapted directly from the code on José's site. It seems to work ok here, although I'm sure it could be improved.

                    Anyway, I hope it helps.

                    Code:
                    #DIM ALL
                    #COMPILE EXE
                    #INCLUDE ONCE "FREEIMAGE.INC"
                    
                    GLOBAL hDib1 AS DWORD
                    GLOBAL hDib2 AS DWORD
                    
                    ' ========================================================================================
                    ' Main
                    ' ========================================================================================
                    FUNCTION PBMAIN
                    
                       LOCAL hDlg     AS DWORD
                       LOCAL szFile   AS ASCIIZ * %MAX_PATH
                    
                       szFile = "Image1.bmp"   ' <--- change me!
                       hDib1 = FreeImage_Load(%FIF_BMP, szFile, %BMP_DEFAULT)
                       IF hDib1 = 0 THEN
                          MSGBOX "Image not loaded"
                          EXIT FUNCTION
                       END IF
                    
                       DIALOG NEW 0, "FreeImage Demo",,, 800, 600,  %WS_OVERLAPPED OR %WS_SYSMENU _
                              OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_THICKFRAME OR %WS_CLIPSIBLINGS _
                              OR %WS_CLIPCHILDREN TO hDlg
                       IF hDlg = 0 THEN EXIT FUNCTION
                    
                    
                       ' Added section-----------------------------------------------
                       LOCAL nWidth AS LONG
                       LOCAL nHeight AS LONG
                       LOCAL hBMP AS DWORD
                       LOCAL hDC_BMP AS DWORD
                    
                       nWidth = FreeImage_GetWidth(hDib1)
                       nHeight = FreeImage_GetHeight(hDib1)
                       GRAPHIC BITMAP NEW nWidth, nHeight TO hBMP
                       GRAPHIC ATTACH hBMP, 0
                       GRAPHIC GET DC TO hDC_BMP
                       SetStretchBltMode(hDC_BMP, %COLORONCOLOR)
                       StretchDibits(hDC_BMP, 0, 0, nWidth, nHeight, _
                          0, 0, nWidth, nHeight, _
                          BYVAL FreeImage_GetBits(hDib1), BYVAL FreeImage_GetInfo(hDib1), _
                          %DIB_RGB_COLORS, %SRCCOPY)
                    
                       CONTROL ADD GRAPHIC, hDlg, 1001, "", 10, 10, nWidth, nHeight, %SS_SUNKEN
                       GRAPHIC ATTACH hDlg, 1001
                       GRAPHIC COPY hBMP, 0
                       GRAPHIC ATTACH hBMP, 0
                       GRAPHIC BITMAP END
                       ' ------------------------------------------------------------
                    
                       DIALOG SHOW MODAL hDlg CALL DlgProc
                    
                       IF hDib1 THEN FreeImage_Unload hDib1
                       IF hDib2 THEN FreeImage_Unload hDib2
                    
                    END FUNCTION
                    ' ========================================================================================
                    
                    ' ========================================================================================
                    ' Main dialog callback
                    ' ========================================================================================
                    CALLBACK FUNCTION DlgProc() AS LONG
                    
                       SELECT CASE CBMSG
                    
                       CASE %WM_COMMAND
                          SELECT CASE CBCTL
                             CASE %IDCANCEL
                                DIALOG END CBHNDL, 0
                          END SELECT
                       END SELECT
                    END FUNCTION
                    ' ========================================================================================
                    Regards,

                    Pete.

                    Comment


                    • #11
                      > Load image can handle bitmaps, cursors and icons, not .jpg, .gif or .png files.

                      Oh, yeah that's right.

                      I have something here I have been using for JPG and PNG (but not GIF) let me see what that is... here it is... http://www.powerbasic.com/support/fo...ML/001671.html

                      I don't have a new forum thread reference, but that works.

                      Hmm, maybe 'someone' should migrate that to the "PB with objects" syntax, which was not available when Mr. Burcham first posted that code.

                      MCM
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Originally posted by Peter Jinks View Post
                        Hi Barry,

                        This is an example adapted directly from the code on José's site. It seems to work ok here, although I'm sure it could be improved.

                        Anyway, I hope it helps.

                        Regards,

                        Pete.
                        That not only helps, it's exactly what I was trying to do.

                        It fooled me at first because you had it set up to load a BMP, but I looked up the proper constant for a JPG and it worked like a charm.

                        Thank you very much!

                        Barry

                        Comment


                        • #13
                          Originally posted by Barry Marks View Post
                          It fooled me at first because you had it set up to load a BMP, but I looked up the proper constant for a JPG and it worked like a charm.
                          When I looked at the code I saw the file name given was a .bmp file and then I saw that %FIF_BMP constant in the FreeImage_Load call. I wonder why the programmer's of FreeImage did it that way? Why not just use the extension of the filename passed in or use the header in the file to determine what type of image it is instead of making programmer's determine that before caling FreeImage_Load?

                          Ah. I decided to check to see if the documentation was available online and it was. Turns out they recommend not using a constant for that first parameter but to use one of their filetype functions such as FreeImage_GetFileType in that spot instead.
                          Jeff Blakeney

                          Comment


                          • #14
                            Originally posted by Jeff Blakeney View Post
                            Ah. I decided to check to see if the documentation was available online and it was. Turns out they recommend not using a constant for that first parameter but to use one of their filetype functions such as FreeImage_GetFileType in that spot instead.
                            I wrote code to determine which constant to use and it seemed a little clumsy. I"ll look at that function. Thanks for this.

                            Barry

                            Comment


                            • #15
                              By the way, between FreeImage, Jose Roca's code and Firefly I now have 3 solutions to choose from. I feel like I won the lottery.

                              Thanks,
                              Barry

                              Comment


                              • #16
                                I use FreeImage to convert XPM (X11 Pixmap Format) files to BMP. Only time to time. Are images generated by old lab analyzers, with Unix as OS.

                                Comment


                                • #17
                                  I've been playing with the code posted by Peter, works wonderfully!! Thanks a lot, it got me started on the great Freeimage library.

                                  What I need to do now is the following: suppose we load, say, a JPG file into a GRAPHIC BITMAP, manipulate it as needed in there, and then we will want to save the resulting image as a PNG file. I think the proper steps for this would be:

                                  Code:
                                  GRAPHIC ATTACH (the GRAPHIC BITMAP handle)
                                  GRAPHIC GET DC to hDC_BMP
                                  (some winapi function to get the attached GRAPHIC BITMAP _
                                       data into a DIB --> hDib3)
                                  FreeImage_Save(%FIF_PNG, hDib3, "file_out.png", %PNG_DEFAULT)
                                  Only thing I haven't figured out yet is exactly how to get the data in the GRAPHIC BITMAP into a DIB handle that FreeImage_Save can use. I've been looking at the "GetDIBits" function from the WinAPI, but no luck so far with it.

                                  If someone could point me in the right direction, i would be thankful...
                                  Jaime de los Hoyos, MD
                                  aka Dr. Code (not the Exult guy!)

                                  Comment


                                  • #18
                                    I'd point out that PowerBASIC is no more proprietary than turns out to be necessary. There are occasions when we'll eat the interface whole, because it's a ghastly design and we can do much better. But, if we tell you something is a "handle", you might as well see if it's a Windows handle, because we're probably just giving you a gloss over the APIs. No point in messing with things that actually work. Some bits are a clean translation.

                                    'Course, using the APIs in conjunction with PB code may lead to conflicts. You always want to have a good idea of what you're doing, but that's true regardless.

                                    Comment


                                    • #19
                                      But, if we tell you something is a "handle", you might as well see if it's a Windows handle
                                      How the heck are *we* supposed to "see if it's a Windows' handle?"

                                      I think it is PowerBASIC's responsibilty to document how and where 'handles' may be used....

                                      eg. as you tell us the handles returned by DIALOG NEW and CONTROL HANDLE are in fact Windows' handles and may be used in any WinAPI call requiring a valid window handle...

                                      ... or as you DON'T tell us (but should!) "handles" returned by GRAPHIC BITMAP LOAD are proprietary handles (Surprise! Not GDI object handles!) and may be used only with other GRAPHICS statements.

                                      MCM
                                      Michael Mattias
                                      Tal Systems (retired)
                                      Port Washington WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        I am a little confused here by the reference to a DIB handle as if it were something different than a normal Bitmap handle. What kind of handle are you refering to ?

                                        They are interchangable, meaning that APIs which require a Bitmap handle can use a DIB handle (created using CreateDIBSection).

                                        Now maybe you are refering to a memory handle to a DIB's Bits as a DIB handle, but that is different.

                                        The handle returned by CreateDIBSection is a valid Bitmap handle which can be used like any other Bitmap handle.

                                        I know, because I use them all the time.

                                        My canvas control can use either DDB's or DIB's for a Bitmap buffers and no GDI API's yet that I have used have had a problem with DIB's.

                                        Now if you have a memory handle to the location of the DIB's bits (or just a pointer to the memory), then you need to create a DIB the same size and simply do a memory copy to move the data to it, so you can have a valid Bitmap.
                                        Chris Boss
                                        Computer Workshop
                                        Developer of "EZGUI"
                                        http://cwsof.com
                                        http://twitter.com/EZGUIProGuy

                                        Comment

                                        Working...
                                        X