Announcement

Collapse
No announcement yet.

bitmap manipulation in PBWin?

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

  • Edwin Knoppert
    replied
    I used it with msgbox statements and the modified image shows fine.
    Sleep makes that it doesn't get updated.

    Leave a comment:


  • Frank Kestens
    replied
    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"

    Leave a comment:


  • Frank Kestens
    replied
    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 ..?

    Leave a comment:


  • Chris Holbrook
    replied
    Have you tried using GRAPHIC SAVE?

    Leave a comment:


  • Petr Schreiber jr
    replied
    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

    Leave a comment:


  • Frank Kestens
    replied
    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

    Leave a comment:


  • Frank Kestens
    replied
    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

    Leave a comment:


  • Frank Kestens
    replied
    Thanks Bob and Richard ! I can get along now .

    Leave a comment:


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

    Leave a comment:


  • Bob Zale
    replied
    Sure. Just use GRAPHIC GET BITS to retrieve the data and GRAPHIC SET BITS to put it back.

    Best regards,

    Bob Zale

    Leave a comment:


  • Frank Kestens
    started a topic bitmap manipulation in PBWin?

    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 .
Working...
X