Announcement

Collapse
No announcement yet.

bitmap manipulation in PBWin?

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

  • bitmap manipulation in PBWin?

    I want to perform some transformations on bitmaps , especially the "world-maps" in which a globe is represented as a rectangle .
    Is there some way to adress the individual pixels once the bitmap has been loaded in memory ? It would be usefull if I could get the bitmap in a nxm array .

  • #2
    Sure. Just use GRAPHIC GET BITS to retrieve the data and GRAPHIC SET BITS to put it back.

    Best regards,

    Bob Zale

    Comment


    • #3
      some examples, albeit with different transformations, can be found in the forums as well as the DDT samples: {Drive}:\PBWin90\Samples\Ddt\Graphic\GraphicTransforms
      Rick Angell

      Comment


      • #4
        Thanks Bob and Richard ! I can get along now .

        Comment


        • #5
          Graphic Get Bits works fine , but I've a problem when I want to save a modified .bmp file . In fact the new mofified file saves , but it can't be read again , neither with normal viewers nor with the program itself .
          The program hereunder reads a .bmp file , modifies some pixels and saves it .
          Anybody has an idea what goes wrong ?
          Attached Files

          Comment


          • #6
            Same post as above but with the program listed :

            #COMPILE EXE
            #DIM NONE
            FUNCTION PBMAIN () AS LONG
            BmpName$ = INPUTBOX$(".... .bmp","Choose_Bmp.file")
            OPEN BmpName$ FOR BINARY AS #1 ' Retrieving the width and the heifht of the bitmap '
            GET #1, 19, nWidth&
            GET #1, 23, nHeight&
            CLOSE #1
            GRAPHIC WINDOW "Converting pixels...", 1, 1, nWidth& , nHeight& TO hWin???
            GRAPHIC ATTACH hWin???, 0
            GRAPHIC RENDER BmpName$, (0, 0)-(nWidth&, nHeight&)
            GRAPHIC SET POS(10,10): GRAPHIC PRINT nWidth&;nHeight&
            LOCAL PixelPtr AS LONG PTR
            GRAPHIC GET BITS TO bmpName1$
            xsize& = CVL(bmpName1$,1)
            ysize& = CVL(bmpName1$,5)
            PixelPtr = STRPTR(bmpName1$) + 8
            FOR i& = 1 TO xsize& * ysize&
            a$=HEX$(@pixelptr)
            REPLACE "F" WITH "B" IN a$ 'converting each " " with " "
            @pixelptr=VAL("&H"+a$)
            INCR PixelPtr
            NEXT i&
            GRAPHIC SET BITS bmpName1$
            SLEEP 3000
            ' this doesn'r work when opening the file again
            OPEN "result.bmp" FOR BINARY AS #1
            SEEK # 1, 1
            PUT$ #1 , bmpName1$
            CLOSE #1
            END FUNCTION

            Comment


            • #7
              Frank,

              BMP files consist of header and RGB sequence, you example supplies just the ~RGB sequence.
              While I could bother you with creating header, my answer will be short:
              Code:
              GRAPHIC SAVE "result.bmp"
              The complete code then:
              Code:
              #COMPILE EXE
              #DIM NONE
              
              FUNCTION PBMAIN () AS LONG
                  
                  BmpName$ = INPUTBOX$(".... .bmp","Choose_Bmp.file")
                  OPEN BmpName$ FOR BINARY AS #1 ' Retrieving the width and the heifht of the bitmap '
                      GET #1, 19, nWidth&
                      GET #1, 23, nHeight&
                  CLOSE #1
                  
                  GRAPHIC WINDOW "Converting pixels...", 1, 1, nWidth& , nHeight& TO hWin???
                  GRAPHIC ATTACH hWin???, 0
                  
                  GRAPHIC RENDER BmpName$, (0, 0)-(nWidth&, nHeight&)
                  GRAPHIC SET POS(10,10): GRAPHIC PRINT nWidth&;nHeight&
                  
                  LOCAL PixelPtr AS LONG PTR
                  GRAPHIC GET BITS TO bmpName1$
                  xsize& = CVL(bmpName1$,1)
                  ysize& = CVL(bmpName1$,5)
                  PixelPtr = STRPTR(bmpName1$) + 8
                  
                  FOR i& = 1 TO xsize& * ysize&
                      a$=HEX$(@pixelptr)
                      REPLACE "F" WITH "B" IN a$ 'converting each " " with " "
                      @pixelptr=VAL("&H"+a$)
                      INCR PixelPtr
                  NEXT i&
                  
                  GRAPHIC SET BITS bmpName1$
                  
                  SLEEP 3000
                  
                  GRAPHIC SAVE "result.bmp"
              END FUNCTION

              Petr
              [email protected]

              Comment


              • #8
                Have you tried using GRAPHIC SAVE?

                Comment


                • #9
                  bitmaps save

                  Thanks Peter and Chris , this works !
                  The "easy" way with GRAPHIC SAVE works while I was trying to do this the hard way . I thought the instructions in my program would also transfer the headers , but obviously this isn't the case . I guess the instruction GRAPHIC GET BITS transforms some information from the original bitmap , which isn't set back when saving again , or ..?

                  Comment


                  • #10
                    bitmap manipulation

                    The code works wunderfull .
                    Here's some code to swap the red and blue tones in a bitmap .

                    LOCAL PixelPtr AS LONG PTR
                    GRAPHIC GET BITS TO bmpName1$
                    xsize& = CVL(bmpName1$,1)
                    ysize& = CVL(bmpName1$,5)
                    PixelPtr = STRPTR(bmpName1$) + 8
                    FOR i& = 1 TO xsize& * ysize&
                    a$=HEX$(@pixelptr)
                    r$=LEFT$(a$,2)
                    g$=MID$ (a$,3,2)
                    b$=RIGHT$(a$,2)
                    a$=b$+g$+r$
                    @pixelptr=VAL("&H"+a$)
                    INCR PixelPtr
                    NEXT i&
                    GRAPHIC SET BITS bmpName1$
                    SLEEP 3000
                    GRAPHIC SAVE "result.bmp"

                    Comment


                    • #11
                      I used it with msgbox statements and the modified image shows fine.
                      Sleep makes that it doesn't get updated.
                      hellobasic

                      Comment

                      Working...
                      X