Loading ...
Sorry, an error occurred while loading the content.
 

Re: [libertybasic] Re: _coloroncolor

Expand Messages
  • Marc Rossi
    Rod, I debugged my program.  I have been tryng for 2 days to get an image larger than my graphics box window to shrink to fit.  If I use a smaller than
    Message 1 of 9 , May 14, 2013
      Rod,
      I debugged my program.  I have been tryng for 2 days to get an image larger than my graphics box window to shrink to fit.  If I use a smaller than graphic box window , the program works fine.  I have my whole program here.  Maybe you can run it or debug it on your computer , I would appreciate it
      Marc
       
      ' code start
       

      NOMAINWIN
      WindowWidth = 700
      WindowHeight = 750
      UpperLeftX = (DisplayWidth - WindowWidth )/ 2
      UpperLeftY = (DisplayHeight - WindowHeight )/ 2

      Menu #gwin,"&Program", "&About", [whatabout]
      Menu #gwin, "&File", "&open", [op]
      Menu #gwin, "&Exit", "&Quit", [quit]
      graphicbox #gwin.gbox, 10, 10, 660, 660
      open "Test BMP" for window as #gwin
      hw = hwnd(#gwin.gbox)
      print #gwin.gbox, "trapclose [quit]"
      print #gwin.gbox, "home;fill black"
      wait
      [op]
      filedialog "Open graphics file", "*.bmp", fileName$
      fil$ = fileName$   ' different name to use for ascii input from file instead of struct
       
      WindowWidth = 400
      WindowHeight = 400
      UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
      UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
      open "Properties" for text as #prop
      print #prop, "!trapclose [quit1]"
       
      open fil$ for input as #p
      h29$ = input$(#p,29)
      BitsPixel = asc(right$(h29$,1))
      print #prop, "BMP format bits per pixel  = ";BitsPixel
      close #p
       ' get width of bitmap
      open fil$ for input as #b
      w19$ = input$(#b, 19)
      close #b
      w19 = asc(right$(w19$,1))   ' ascii value of 19
      open fil$ for input as #b
      w20$ = input$(#b, 20)
      close #b
      w20 = asc(right$(w20$,1))  ' ascii value of 20
      wc = (w20 * 256)        ' calculation of 20 by 256
      widthBitmap = w19 + wc
      print #prop, "Width of bitmap =  ";widthBitmap
      ' get height of bitmap
      open fil$ for input as #f
      h23$ = input$(#f, 23)
      close #f
      open fil$ for input as #f
      h24$ = input$(#f, 24)
      close #f
      h23 = asc(right$(h23$,1))  ' convert to value
      h24 = asc(right$(h24$,1))  ' convert to value
      hc = (h24 * 256) ' calculation by 256 char 24 ascii)
      heightBitmap = (hc + h23)
      print #prop, "Height of bitmap = ";heightBitmap

      loadbmp "f", fil$
      print #gwin.gbox, "drawbmp f 0 0"
      hBitmap = hbmp("f")
       

      ' create a struct to hold the retrieved info
      STRUCT BITMAP,_
      bmType as long,_
      bmWidth as long,_
      bmHeight as long,_
      bmWidthBytes as long,_
      bmPlanes as word,_
      bmBitsPixel as word,_
      bmBits as long

      nSize = len(BITMAP.struct)  ' returns the length of the struct
      calldll #gdi32, "GetObjectA",_
      hBitmap as long,_   ' handle of object queried
      nSize as long,_  ' number of bytes in struct
      BITMAP as struct,_ ' address of struct
      result as long  ' retrieves the number of bytes retreived, 0 on error
       
      type = BITMAP.bmType.struct
      width = BITMAP.bmWidth.struct
      height = BITMAP.bmHeight.struct
      widthBytes = BITMAP.bmWidthBytes.struct
      planes = BITMAP.bmPlanes.struct
      'bpp =   bmBitsPixel and bmBits'  always return 0
      print #prop, "After API call"
      print #prop, "type of bitmap = ";type
      print #prop, "width of bitmap = ";width
      print #prop, "height of bitmap = ";height
      print #prop, "widthbytes = ";widthBytes
      ' print #prop, "The = ";bpp
      ' *****************************************************************************************************************
      calldll #user32, "GetDC",_
      hw as ulong,_   ' handle of window
      hDC as ulong
      if width > 660 or height > 660 then
      calldll #gdi32, "SetStretchBltMode",_
      hDC as ulong,_                      ' device context
      _COLORONCOLOR as long,_             ' desired mode
      result as long    ' returns mode
      end if
      calldll #gdi32, "GetStretchBltMode",_
      hDC as ulong,_                      ' device context
      _COLORONCOLOR as long,_             ' desired mode
      result as long    ' returns mode
      print #prop, "Mode is = ";result
      calldll #gdi32, "StretchBlt",_
      hDC as ulong,_  ' the destination dc
      0 as long,_  ' x location of destination
      0 as long,_ ' y location of destination ***********************
      660 as long,_  ' new width desired
      660 as long,_  ' new height desired
      hDC as ulong,_  ' the source dc
      0 as long,_  ' x location of source rectangle
      0 as long,_   'y locaton of source rectangle
      width as long,_  ' width of source rectangle
      height as long,_  ' height of source rectangle
      _SRCCOPY as ulong,_    ' desired call
      result as long
      wait
      [quit1]
      unloadbmp "f"
      calldll #user32, "ReleaseDC",_
      hw as ulong,_   ' handle of window
      hDC as ulong
      wait
      [whatabout]
      notice "BMP Test"
      wait
      [exit]
      [quit]
      calldll #user32, "ReleaseDC",_
      hw as ulong,_   ' handle of window
      hDC as ulong
      unloadbmp "f"
      close #gwin
      close #prop
      end
       
       
       
       
       
       
       

       

      ________________________________
      From: Rod <rodbird@...>
      To: libertybasic@yahoogroups.com
      Sent: Sunday, May 12, 2013 10:44 AM
      Subject: [libertybasic] Re: _coloroncolor

       

      The _coloroncolor mode simply sets how the color pixels are combined when an image is shrunk. It is the correct mode to use but to shrink an image you must blit from a large image to a small image so your destination width and height will be smaller than your source width and height. To make any image fit your screen use your screen width and height as the destination values and the image width and height as the source values.

      --- In mailto:libertybasic%40yahoogroups.com, "Marc" <mrossi8888@...> wrote:
      >
      > Dear Liberty basic members,
      > I am using "StretchStretchBltMode" for my bmps and it works fine when the dimensions are smaller than my window. I use _coloroncolor (mode 3 such as
      > :
      > ' code
      > if width > 660 or height > 620 then
      > calldll #gdi32, "SetStretchBltMode",_
      > hDC as ulong,_ ' device context
      > _COLORONCOLOR as long,_ ' desired mode
      > result as long ' returns mode
      > end if
      > if the bmp is larger than my window ZZI thought this was supposed to shrink it to size.
      > Any comments or help is appreciated,
      > Marc
      >




      [Non-text portions of this message have been removed]
    • Rod
      I would recommend getting hold of Alyce s tutorials and spending a little time experimenting with the examples she codes, so too the Dan Teel demo and the wiki
      Message 2 of 9 , May 14, 2013
        I would recommend getting hold of Alyce's tutorials and spending a little time experimenting with the examples she codes, so too the Dan Teel demo and the wiki examples. The problem is that you were using a single DC, Blitting is about moving an image from one DC to another.

        This code uses two DCs it loads the image into memory, measures its size then loads it into the memory DC. Then we stretch it and blit it from the memory DC to the screen DC.



        nomainwin
        WindowWidth = 700
        WindowHeight = 750
        UpperLeftX = (DisplayWidth - WindowWidth )/ 2
        UpperLeftY = (DisplayHeight - WindowHeight )/ 2

        Menu #1,"&Program", "&About", [whatabout]
        Menu #1, "&File", "&open", [op]
        Menu #1, "&Exit", "&Quit", [quit]
        graphicbox #1.g, 10, 10, 660, 660
        open "Test BMP" for window as #1
        print #1.g, "trapclose [quit]"
        print #1.g, "fill black"
        wait


        [op]
        filedialog "Open graphics file", "*.bmp", fileName$
        WindowWidth = 400
        WindowHeight = 400
        UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
        UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
        open "Properties" for text as #prop
        print #prop, "!trapclose [quit1]"
        loadbmp "f", fileName$
        bmphandle = hbmp("f")

        ' create a struct to hold the retrieved info
        STRUCT BITMAP,_
        bmType as long,_
        bmWidth as long,_
        bmHeight as long,_
        bmWidthBytes as long,_
        bmPlanes as word,_
        bmBitsPixel as word,_
        bmBits as long

        nSize = len(BITMAP.struct) ' returns the length of the struct
        calldll #gdi32, "GetObjectA",_
        bmphandle as long,_ ' handle of object queried
        nSize as long,_ ' number of bytes in struct
        BITMAP as struct,_ ' address of struct
        result as long ' retrieves the number of bytes retreived, 0 on error

        type = BITMAP.bmType.struct
        width = BITMAP.bmWidth.struct
        height = BITMAP.bmHeight.struct
        widthBytes = BITMAP.bmWidthBytes.struct
        planes = BITMAP.bmPlanes.struct

        print #prop, "After API call"
        print #prop, "type of bitmap = ";type
        print #prop, "width of bitmap = ";width
        print #prop, "height of bitmap = ";height
        print #prop, "Close this window to continue."
        wait

        [quit1]
        close #prop

        ' set up our bitmaps, open device contexts and store our bitmaps in them

        ' bDC is our screen
        bDC=GetDC(hwnd(#1.g))

        ' mDC is a copy of the screen in memory
        mDC=CreateCompatibleDC(bDC)
        ' select the loaded bmp into the memory DC
        oldBmp=SelectObject(mDC,bmphandle)

        ' now stretch the image from the memory DC to the screen DC
        call StretchBlt,bDC,0,0,660,660,mDC,0,0,width,height
        wait



        [quit]

        unloadbmp "bmp"
        call ReleaseDC hwnd(#1), gDC
        call DeleteDC mDC
        close #1

        end


        '=============================Window and DC functions=================================
        Function GetDC(hWnd)
        CallDLL #user32, "GetDC",_
        hWnd As ulong,_ 'window or control handle
        GetDC As ulong 'returns device context
        End Function

        Sub ReleaseDC hWnd, hDC
        CallDLL#user32,"ReleaseDC",_
        hWnd As ulong,_ 'window or control handle
        hDC As ulong,_ 'handle of DC to delete
        result As Long
        End Sub

        Function CreateCompatibleDC(hDC)
        CallDLL #gdi32,"CreateCompatibleDC",_
        hDC As ulong,_ 'window DC
        CreateCompatibleDC As ulong 'memory DC
        End Function

        Sub DeleteDC hDC
        CallDLL #gdi32, "DeleteDC",_
        hDC As ulong,_ 'memory DC to delete
        r As Long
        End Sub

        Sub StretchBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2
        CallDLL #gdi32, "SetStretchBltMode",_
        hDCdest As ulong,_ 'device context
        _COLORONCOLOR As Long,_ 'color reduction mode
        RESULT As Long
        CallDLL #gdi32, "StretchBlt",_
        hDCdest As ulong,_ 'destination
        x As Long,_ 'destination x pos
        y As Long,_ 'destination y pos
        w As Long,_ 'destination width desired
        h As Long,_ 'destination height desired
        hDCsrc As ulong,_ 'source
        x2 As Long,_ 'x location to start from source
        y2 As Long,_ 'y location to start from source
        w2 As Long,_ 'width desired from source
        h2 As Long,_ 'height desired from source
        _SRCCOPY As long,_ 'dwRasterOperation
        RESULT As Long
        End Sub


        Function SelectObject(hDC,hObject)
        CallDLL #gdi32,"SelectObject",_
        hDC As ulong,_ 'memory device context
        hObject As long,_ 'handle of object
        SelectObject As long 'returns previously selected object
        End Function
      • Rod
        the quit code should look like this unloadbmp f call ReleaseDC hwnd(#1), bDC call DeleteDC mDC close #1
        Message 3 of 9 , May 14, 2013
          the quit code should look like this

          unloadbmp "f"
          call ReleaseDC hwnd(#1), bDC
          call DeleteDC mDC
          close #1
        • Marc Rossi
          Thank You very much ,Rod.  Works great.  I appreciate you spending the time to help me. Marc   ________________________________ From: Rod
          Message 4 of 9 , May 14, 2013
            Thank You very much ,Rod.  Works great.  I appreciate you spending the time to help me.
            Marc
             


            ________________________________
            From: Rod <rodbird@...>
            To: libertybasic@yahoogroups.com
            Sent: Tuesday, May 14, 2013 3:03 PM
            Subject: [libertybasic] Re: _coloroncolor

             

            I would recommend getting hold of Alyce's tutorials and spending a little time experimenting with the examples she codes, so too the Dan Teel demo and the wiki examples. The problem is that you were using a single DC, Blitting is about moving an image from one DC to another.

            This code uses two DCs it loads the image into memory, measures its size then loads it into the memory DC. Then we stretch it and blit it from the memory DC to the screen DC.

            nomainwin
            WindowWidth = 700
            WindowHeight = 750
            UpperLeftX = (DisplayWidth - WindowWidth )/ 2
            UpperLeftY = (DisplayHeight - WindowHeight )/ 2

            Menu #1,"&Program", "&About", [whatabout]
            Menu #1, "&File", "&open", [op]
            Menu #1, "&Exit", "&Quit", [quit]
            graphicbox #1.g, 10, 10, 660, 660
            open "Test BMP" for window as #1
            print #1.g, "trapclose [quit]"
            print #1.g, "fill black"
            wait

            [op]
            filedialog "Open graphics file", "*.bmp", fileName$
            WindowWidth = 400
            WindowHeight = 400
            UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
            UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
            open "Properties" for text as #prop
            print #prop, "!trapclose [quit1]"
            loadbmp "f", fileName$
            bmphandle = hbmp("f")

            ' create a struct to hold the retrieved info
            STRUCT BITMAP,_
            bmType as long,_
            bmWidth as long,_
            bmHeight as long,_
            bmWidthBytes as long,_
            bmPlanes as word,_
            bmBitsPixel as word,_
            bmBits as long

            nSize = len(BITMAP.struct) ' returns the length of the struct
            calldll #gdi32, "GetObjectA",_
            bmphandle as long,_ ' handle of object queried
            nSize as long,_ ' number of bytes in struct
            BITMAP as struct,_ ' address of struct
            result as long ' retrieves the number of bytes retreived, 0 on error

            type = BITMAP.bmType.struct
            width = BITMAP.bmWidth.struct
            height = BITMAP.bmHeight.struct
            widthBytes = BITMAP.bmWidthBytes.struct
            planes = BITMAP.bmPlanes.struct

            print #prop, "After API call"
            print #prop, "type of bitmap = ";type
            print #prop, "width of bitmap = ";width
            print #prop, "height of bitmap = ";height
            print #prop, "Close this window to continue."
            wait

            [quit1]
            close #prop

            ' set up our bitmaps, open device contexts and store our bitmaps in them

            ' bDC is our screen
            bDC=GetDC(hwnd(#1.g))

            ' mDC is a copy of the screen in memory
            mDC=CreateCompatibleDC(bDC)
            ' select the loaded bmp into the memory DC
            oldBmp=SelectObject(mDC,bmphandle)

            ' now stretch the image from the memory DC to the screen DC
            call StretchBlt,bDC,0,0,660,660,mDC,0,0,width,height
            wait

            [quit]

            unloadbmp "bmp"
            call ReleaseDC hwnd(#1), gDC
            call DeleteDC mDC
            close #1

            end

            '=============================Window and DC functions=================================
            Function GetDC(hWnd)
            CallDLL #user32, "GetDC",_
            hWnd As ulong,_ 'window or control handle
            GetDC As ulong 'returns device context
            End Function

            Sub ReleaseDC hWnd, hDC
            CallDLL#user32,"ReleaseDC",_
            hWnd As ulong,_ 'window or control handle
            hDC As ulong,_ 'handle of DC to delete
            result As Long
            End Sub

            Function CreateCompatibleDC(hDC)
            CallDLL #gdi32,"CreateCompatibleDC",_
            hDC As ulong,_ 'window DC
            CreateCompatibleDC As ulong 'memory DC
            End Function

            Sub DeleteDC hDC
            CallDLL #gdi32, "DeleteDC",_
            hDC As ulong,_ 'memory DC to delete
            r As Long
            End Sub

            Sub StretchBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2
            CallDLL #gdi32, "SetStretchBltMode",_
            hDCdest As ulong,_ 'device context
            _COLORONCOLOR As Long,_ 'color reduction mode
            RESULT As Long
            CallDLL #gdi32, "StretchBlt",_
            hDCdest As ulong,_ 'destination
            x As Long,_ 'destination x pos
            y As Long,_ 'destination y pos
            w As Long,_ 'destination width desired
            h As Long,_ 'destination height desired
            hDCsrc As ulong,_ 'source
            x2 As Long,_ 'x location to start from source
            y2 As Long,_ 'y location to start from source
            w2 As Long,_ 'width desired from source
            h2 As Long,_ 'height desired from source
            _SRCCOPY As long,_ 'dwRasterOperation
            RESULT As Long
            End Sub

            Function SelectObject(hDC,hObject)
            CallDLL #gdi32,"SelectObject",_
            hDC As ulong,_ 'memory device context
            hObject As long,_ 'handle of object
            SelectObject As long 'returns previously selected object
            End Function




            [Non-text portions of this message have been removed]
          • Henrik
            Just a notice If you run the code and click program = about, then you will get a message : Invalid branch lable : [whatabout] ________________________________
            Message 5 of 9 , May 14, 2013
              Just a notice
              If you run the code and click
              program => about, then you will
              get a message :
              Invalid branch lable : [whatabout]


              ________________________________
              From: Rod <rodbird@...>
              To: libertybasic@yahoogroups.com
              Sent: Tuesday, May 14, 2013 9:03 PM
              Subject: [libertybasic] Re: _coloroncolor



               
              I would recommend getting hold of Alyce's tutorials and spending a little time experimenting with the examples she codes, so too the Dan Teel demo and the wiki examples. The problem is that you were using a single DC, Blitting is about moving an image from one DC to another.

              This code uses two DCs it loads the image into memory, measures its size then loads it into the memory DC. Then we stretch it and blit it from the memory DC to the screen DC.

              nomainwin
              WindowWidth = 700
              WindowHeight = 750
              UpperLeftX = (DisplayWidth - WindowWidth )/ 2
              UpperLeftY = (DisplayHeight - WindowHeight )/ 2

              Menu #1,"&Program", "&About", [whatabout]
              Menu #1, "&File", "&open", [op]
              Menu #1, "&Exit", "&Quit", [quit]
              graphicbox #1.g, 10, 10, 660, 660
              open "Test BMP" for window as #1
              print #1.g, "trapclose [quit]"
              print #1.g, "fill black"
              wait

              [op]
              filedialog "Open graphics file", "*.bmp", fileName$
              WindowWidth = 400
              WindowHeight = 400
              UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
              UpperLeftY=INT((DisplayHeight-WindowHeight)/2)
              open "Properties" for text as #prop
              print #prop, "!trapclose [quit1]"
              loadbmp "f", fileName$
              bmphandle = hbmp("f")

              ' create a struct to hold the retrieved info
              STRUCT BITMAP,_
              bmType as long,_
              bmWidth as long,_
              bmHeight as long,_
              bmWidthBytes as long,_
              bmPlanes as word,_
              bmBitsPixel as word,_
              bmBits as long

              nSize = len(BITMAP.struct) ' returns the length of the struct
              calldll #gdi32, "GetObjectA",_
              bmphandle as long,_ ' handle of object queried
              nSize as long,_ ' number of bytes in struct
              BITMAP as struct,_ ' address of struct
              result as long ' retrieves the number of bytes retreived, 0 on error

              type = BITMAP.bmType.struct
              width = BITMAP.bmWidth.struct
              height = BITMAP.bmHeight.struct
              widthBytes = BITMAP.bmWidthBytes.struct
              planes = BITMAP.bmPlanes.struct

              print #prop, "After API call"
              print #prop, "type of bitmap = ";type
              print #prop, "width of bitmap = ";width
              print #prop, "height of bitmap = ";height
              print #prop, "Close this window to continue."
              wait

              [quit1]
              close #prop

              ' set up our bitmaps, open device contexts and store our bitmaps in them

              ' bDC is our screen
              bDC=GetDC(hwnd(#1.g))

              ' mDC is a copy of the screen in memory
              mDC=CreateCompatibleDC(bDC)
              ' select the loaded bmp into the memory DC
              oldBmp=SelectObject(mDC,bmphandle)

              ' now stretch the image from the memory DC to the screen DC
              call StretchBlt,bDC,0,0,660,660,mDC,0,0,width,height
              wait

              [quit]

              unloadbmp "bmp"
              call ReleaseDC hwnd(#1), gDC
              call DeleteDC mDC
              close #1

              end

              '=============================Window and DC functions=================================
              Function GetDC(hWnd)
              CallDLL #user32, "GetDC",_
              hWnd As ulong,_ 'window or control handle
              GetDC As ulong 'returns device context
              End Function

              Sub ReleaseDC hWnd, hDC
              CallDLL#user32,"ReleaseDC",_
              hWnd As ulong,_ 'window or control handle
              hDC As ulong,_ 'handle of DC to delete
              result As Long
              End Sub

              Function CreateCompatibleDC(hDC)
              CallDLL #gdi32,"CreateCompatibleDC",_
              hDC As ulong,_ 'window DC
              CreateCompatibleDC As ulong 'memory DC
              End Function

              Sub DeleteDC hDC
              CallDLL #gdi32, "DeleteDC",_
              hDC As ulong,_ 'memory DC to delete
              r As Long
              End Sub

              Sub StretchBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2
              CallDLL #gdi32, "SetStretchBltMode",_
              hDCdest As ulong,_ 'device context
              _COLORONCOLOR As Long,_ 'color reduction mode
              RESULT As Long
              CallDLL #gdi32, "StretchBlt",_
              hDCdest As ulong,_ 'destination
              x As Long,_ 'destination x pos
              y As Long,_ 'destination y pos
              w As Long,_ 'destination width desired
              h As Long,_ 'destination height desired
              hDCsrc As ulong,_ 'source
              x2 As Long,_ 'x location to start from source
              y2 As Long,_ 'y location to start from source
              w2 As Long,_ 'width desired from source
              h2 As Long,_ 'height desired from source
              _SRCCOPY As long,_ 'dwRasterOperation
              RESULT As Long
              End Sub

              Function SelectObject(hDC,hObject)
              CallDLL #gdi32,"SelectObject",_
              hDC As ulong,_ 'memory device context
              hObject As long,_ 'handle of object
              SelectObject As long 'returns previously selected object
              End Function




              [Non-text portions of this message have been removed]
            • Rod
              Richard has reminded me that Alyce shows a much simpler way to achieve this task here http://lbpe.wikispaces.com/Load+Bitmap+to+Size
              Message 6 of 9 , May 14, 2013
                Richard has reminded me that Alyce shows a much simpler way to achieve this task here

                http://lbpe.wikispaces.com/Load+Bitmap+to+Size
              • Marc Rossi
                Thanks Richard for the link, Marc ________________________________ From: Rod To: libertybasic@yahoogroups.com Sent: Wednesday, May 15,
                Message 7 of 9 , May 15, 2013
                  Thanks Richard for the link,
                  Marc


                  ________________________________
                  From: Rod <rodbird@...>
                  To: libertybasic@yahoogroups.com
                  Sent: Wednesday, May 15, 2013 2:07 AM
                  Subject: [libertybasic] Re: _coloroncolor

                   

                  Richard has reminded me that Alyce shows a much simpler way to achieve this task here

                  http://lbpe.wikispaces.com/Load+Bitmap+to+Size




                  [Non-text portions of this message have been removed]
                Your message has been successfully submitted and would be delivered to recipients shortly.