Results 1 to 9 of 9

Thread: picture transpaence in canvas mode?

  1. #1

    picture transpaence in canvas mode?

    How I can make a picture (*.bmp, *jpg) transparent in canvas mode? It's possible with current thinbasic version to store two pictures over one place (with magenta trick?) ? bye, largo

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Hi Largo,

    no I'm sorry but at the moment there is no a native command able to do that job.
    I will see what I can do in next thinBasic version.

    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    I think this is a job for GDIplus. Will you support a GDIp canvas in thinBasic 2.0, Eros?

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    GdiPlus module sure. A pseudo basic version has always been there in thinbasic distribution.
    A GdiPlus Canvas native control ... maybe
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    If you don't need ultrafast solution, you can have a look at:
    /SampleScripts/UI/Canvas/Image_Background/Image_Background.tBasic

    ...which shows approach with magenta masked images on canvas.

    If you need solid speed for thousands of transparent, I would recommend to jump over GDI Plus straight to the realm of GPUs and try alpha masking / alpha blending.
    In ThinBASIC, you can use pure OpenGL for this, or for better comfort TBGL. When you look at TBGL_LoadTexture command, you will see you can specify optional transparent color.

    Other approach would be using Mike's sprite functions, have a look at examples under:
    /SampleScripts/TBGL/Sprites/


    Petr
    Last edited by Petr Schreiber; 29-05-2012 at 08:16.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Hi Petr,

    thanks and sorry: I forgot about the "Quick and dirty approach" example you developed

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109
    hello largo, this could be a solution:


    pixelColor = GDIP_ARGB(0, 255, 0, 255) '=> transparence modus !!!
    
    ' Empty GUI script created on 10-31-2011 + 11-03-2011, 15:32:15 by largo_winch (ThinAIR)
    '--------------> GDIPLUS TEST FOR THINBASIC -------------------->
    
    '-- modified by frank for largo about question of "transparence modus" for images, 29.mai.2012 :)
    
    Uses "UI", "console"
    '---------------------------->
    #INCLUDE "GDIPLUS_LW1a.INC"
    '---------------------------->
    
    Begin ControlID
      %Canvas_Gdip 
      %bClose 
    End ControlID
    
    Type BGRA
      B As Byte
      G As Byte
      R As Byte
      A As Byte
    End Type
    
    ' ========================================================================================
    
    ' ========================================================================================
    ' Main
    ' ========================================================================================
    Function TBMain() As Long
    
       Local hr As Long
       Local hDlg As DWord
       Local hdc As DWord
       Local token As DWord
       Local StartupInput As GdiplusStartupInput
    
       ' Initialize GDI+
       StartupInput.GdiplusVersion = 1
       hr = GdiplusStartup(token, StartupInput, ByVal %NULL)
       If hr Then
          MsgBox "Error initializing GDI+"
          Exit Function
       End If
    
      Dialog New 0, "tb_gdiplus DrawImage",-1,-1, 420, 270, _
                                        %WS_POPUP Or %WS_VISIBLE Or _
                                         %WS_CLIPCHILDREN Or %WS_CAPTION Or _
                                         %WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg
      
        
      Dialog Show Modal hDlg, Call dlgProc
    
       ' Shutdown GDI+
       GdiplusShutdown token
    
    End Function
    ' ========================================================================================
    
    ' ========================================================================================
    ' Main Dialog procedure
    ' ========================================================================================
    CallBack Function DlgProc() As Long  
      Local cx, cy As Long, hDc As Long
    
    ' -- Test for messages
      Select Case CBMSG
        Case %WM_INITDIALOG
      ' -- Place controls here
          Dialog Pixels CBHNDL, 400, 250 To Units cx, cy
      
          Control Add Canvas, CBHNDL, %Canvas_Gdip, "", 5, 5, cx+100, cy+100
          Control Add Button, CBHNDL, %bClose, "Close", 80+cx, cy+5-84, 50, 18, Call bCloseProc
          Canvas_Attach CBHNDL, %Canvas_Gdip, %TRUE  
          Canvas_Color Rgb(128, 255, 0), Rgb(0, 0, 0)
          'Canvas_Clear(Rgb(0,0,0)) 
          Canvas_Scale Pixels
      
        Case %WM_PAINT
            GDIP_DrawImage()
            Canvas_Redraw
    
        Case %WM_COMMAND
             Select Case CBCTL
    
                Case %IDCANCEL
                   If CBCTLMSG = %BN_CLICKED Then Dialog End CBHNDL, 0
             End Select
    
       End Select
    
    End Function
    
    ' -- Callback for close button
    CallBack Function bCloseProc()
    
      If CBMSG = %WM_COMMAND Then       
        If CBCTLMSG = %BN_CLICKED Then
          ' -- Closes the dialog 
          Dialog End CBHNDL
        End If
      End If
    
    End Function
    
    '--------------------> ~~~~~~~~~
    Sub GDIP_DrawImage() ' SETPIXEL
    '--------------------> ~~~~~~~~~
    
       Local hStatus As Long
       Local pGraphics As DWord
       Local pImage As DWord
       Local strFileName As String
       Local nWidth As Long
       Local nHeight As Long
       Local rows As Long
       Local cols As Long
       Local pixelColor As Long
       
       hStatus = GdipCreateFromHDC(Canvas_GetDC, pGraphics)
    
       ' // Create the Image object
       strFileName = Ucode$("Metallica1a.jpg")
       hStatus = GdipLoadImageFromFile(StrPtr(strFileName), pImage)
       
       
       ' // Draw the image
       hStatus = GdipDrawImage(pGraphics, pImage, 10, 10)
       
       ' // Get the width and height of the bitmap
       hStatus = GdipGetImageWidth(pImage, nWidth ) '(varptr(nWidth))
       hStatus = GdipGetImageHeight(pImage, nHeight ) '(varptr(nHeigth))
       
       '--------- // that's important! ------------ //
       'pixelColor = GDIP_ARGB(255, 0, 255, 0) 'green pixeled
       pixelColor = GDIP_ARGB(0, 255, 0, 255) '=> transparence modus !!!
       '--------- // that's important! ------------ //
       
       ' // Create a checkered pattern with black pixels.
       For rows = 1 To nWidth - 1 Step 2
          For cols = 1 To nHeight Step 2
             hStatus = GdipBitmapSetPixel(pImage, rows, cols, pixelColor)
          Next
       Next
    
       ' // Draw the altered bitmap.
       hStatus = GdipDrawImage(pGraphics, pImage, 200, 200)
              
       ' // Cleanup
       If pImage Then GdipDisposeImage(pImage)
       If pGraphics Then GdipDeleteGraphics(pGraphics)
    
    End Sub
    
    you find solution in zip folder with your own gdip include file.

    best regards, frank
    Attached Images Attached Images
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  8. #8
    thanks a lot for replies and good examples and infos! (petr, eros, charles, frank)

    1) first thing:
    /SampleScripts/UI/Canvas/Image_Background/Image_Background.tBasic
    the example Image_Background causes error code 30 (something with "pointapi" isn't correct here (new thinbasic beta version 1.9.0.0)

    @petr: at this example how I can add new color background/foreground to the image (ferrari) ?

    2) many thanks @lionheart, that example with my gdip include files will make my day, it's nearly the approach I was looking for, great the color argb function is exactly what I need for my idea. I will try to build little klick-a-picture game for next weeks.

    3) 2d tbgl features is quite new thing for me, I will test the module from michael next days, thanks for that important link too.

    bye, largo

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    1. this is a problem I need to check
      Positive is that also here in my current beta version I get same error.
      I will let you know and publish as soon as possible an update

      In thinBasic version 1.8.9.0 problem is not present
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Get Pixel Color from a Picture
    By zak in forum UI (User Interface)
    Replies: 3
    Last Post: 09-03-2011, 17:07
  2. add picture as attachements?
    By Lionheart008 in forum thinBasic General
    Replies: 0
    Last Post: 07-10-2010, 18:57
  3. texturing model by one picture stretched
    By zak in forum TBGL General
    Replies: 3
    Last Post: 11-09-2010, 20:29
  4. Replies: 6
    Last Post: 16-06-2010, 06:40

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •