Announcement

Collapse
No announcement yet.

Use PBCC to open, rotate, and save Image File

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

  • Use PBCC to open, rotate, and save Image File

    Before I dig in myself to figure out how to do this, perhaps one of you experts already has code or can quickly educate me.

    I just want a little PBCC utility that will open an existing BMP or JPG, rotate the image by 90 degrees, then save it again. Don't need to draw it, just save it.

    Maybe it's easy if you already know about picture formats and such. Obviously every Photoshop-like program can do it, but I want to do it from within PBCC code.

    Thanks for any help, and you are welcome to insult me for being so stupid....again!


  • #2
    Check posts 25 and 26 in this thread(bmp only):
    https://forum.powerbasic.com/forum/u...es-not-display
    Rod
    "To every unsung hero in the universe
    To those who roam the skies and those who roam the earth
    To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

    Comment


    • #3
      Thanks, Rodney!

      I'll have to mess with it to use it in PBCC instead of PBwin, but shouldn't take long.

      Your code, or Kurt's ?

      Comment


      • #4
        @Daniel,

        Using my headers:

        Code:
        #COMPILE EXE
        #DIM ALL
        #INCLUDE "GDIPUTILS.INC"
        
        ' (1) Available constants
        '%RotateNoneFlipNone = 0
        '%Rotate90FlipNone   = 1
        '%Rotate180FlipNone  = 2
        '%Rotate270FlipNone  = 3
        
        '%RotateNoneFlipX    = 4
        '%Rotate90FlipX      = 5
        '%Rotate180FlipX     = 6
        '%Rotate270FlipX     = 7
        
        '%RotateNoneFlipY    = %Rotate180FlipX
        '%Rotate90FlipY      = %Rotate270FlipX
        '%Rotate180FlipY     = %RotateNoneFlipX
        '%Rotate270FlipY     = %Rotate90FlipX
        
        '%RotateNoneFlipXY   = %Rotate180FlipNone
        '%Rotate90FlipXY     = %Rotate270FlipNone
        '%Rotate180FlipXY    = %RotateNoneFlipNone
        '%Rotate270FlipXY    = %Rotate90FlipNone
        
        FUNCTION PBMAIN
        
           LOCAL token AS DWORD
           LOCAL StartupInput AS GdiplusStartupInput
           LOCAL nStatus AS LONG
           LOCAL wszFileName AS WSTRINGZ * 260
           LOCAL pImage AS DWORD
        
           ' Initialize GDI+
           StartupInput.GdiplusVersion = 1
           nStatus = GdiplusStartup(token, StartupInput, BYVAL %NULL)
           IF nStatus <> 0 THEN
              PRINT "Error initializing GDI+"
              WAITKEY$
              EXIT FUNCTION
           END IF
        
           wszFileName = "climber.jpg"   ' --> change me
           nStatus = GdipLoadImageFromFile(wszFileName, pImage)
           nStatus = GdipImageRotateFlip(pImage, %Rotate90FlipNone)   ' (1)
           nStatus = GdiPlusSaveImageToJpeg(pImage, "rotated.jpg")   ' --> change me
        '--or--
        '   nStatus = GdiPlusSaveImageToBmp(pImage, "rotated.bmp")   ' --> change me
        '   nStatus = GdiPlusSaveImageToPng(pImage, "rotated.png")   ' --> change me
           IF pImage THEN GdipDisposeImage(pImage)
        
           ' Shutdown GDI+
           GdiplusShutdown token
        
           IF nStatus THEN
              PRINT "Error - status code: " & STR$(nStatus)
           ELSE
              PRINT "image saved"
           END IF
           WAITKEY$
        
        END FUNCTION
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          It's Kurt's code, the first one I came across while searching. I think there's at least one by Gary Beene as well.
          Rod
          "To every unsung hero in the universe
          To those who roam the skies and those who roam the earth
          To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

          Comment


          • #6
            Side note: In Windows Explorer, right clicking on an image will bring a context menu with the rotate left or right option.

            Pierre

            Comment


            • #7
              You cannot give Reputation to the same post twice.
              Dang!
              Rgds, Dave

              Comment


              • #8
                Jose - your routines look perfect, but where you provide the Headers it says "You must also be aware that these headers are not extensions to the ones provided with the compiler, but a full replacement. Therefore, you must not mix them with the PowerBASIC include files in any way, neither directly (via #INCLUDE), nor indirectly (via the include path in the IDE)."

                My code has #INCLUDE "Win32Api.inc" . Just change that to your version?

                My code also hasthe Contools/GFX #INCLUDE "GFXT_Pro.INC" and "CT_Pro.INC". Any problems there?

                Comment


                • #9
                  > My code has #INCLUDE "Win32Api.inc" . Just change that to your version?

                  Not needed. You only need to replace the path to the PB includes in the PB IDE to the path to my includes.

                  > My code also hasthe Contools/GFX #INCLUDE "GFXT_Pro.INC" and "CT_Pro.INC". Any problems there?

                  I don't use them, but I don' think there will be any problems.
                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                  Comment


                  • #10
                    In fact, there are little incompatibilities between the PB headers and mine, and none if you define %USEPBDECL before starting to add #INCLUDE. The problem is that if you have the paths of both mixed in the PB IDE, the compiler may choose the PB one that may lack the needed support for my wrappers. For example, the PB includes don't have any support for GDI+.
                    Forum: http://www.jose.it-berater.org/smfforum/index.php

                    Comment

                    Working...
                    X