• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

AlphaBlend error in my code

Started by Randall Glass, August 30, 2013, 11:04:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Randall Glass

I have been trying to get alpha blending to work.

I am using GraphicLoadImageFileToBitmap from the powerbasic forum.

I get a error from alphablend function.

I checked to make sure both png's were 32 bit color.

Anyone have any idea on what is causing the error?



#COMPILE EXE

#INCLUDE "win32api.inc"

#INCLUDE ONCE "gdip_cut.bi"        'Have either this cut down lib included
''#include once "GdiPUtils.bi"       'Or include the full lib from Jose Roca

#INCLUDE ONCE "ImgFtoBM.bi"

'
%AC_SRC_OVER             = &H00
%AC_SRC_ALPHA            = &H01
'

FUNCTION PBMAIN () AS LONG
    LOCAL hWin,hWDC,hBMP,hBMPDC AS DWORD
    LOCAL bf AS BLENDFUNCTION
    LOCAL DialogWidth%,DialogHeight%
    LOCAL GdipToken AS DWORD
    LOCAL StartupInput AS GdiplusStartupInput

    'Initialise GDI+ - this is required ONCE in app if any GDI+ stuff is used
    StartupInput.GdiplusVersion = 1
    IF GdiplusStartup(GdipToken,StartupInput, BYVAL %NULL) THEN
        MSGBOX "Error initialising GDI+ ... (Also, program needs XP or later)"
        EXIT FUNCTION
    END IF

    bf.BlendOp = %AC_SRC_OVER
    bf.BlendFlags = 0
    bf.SourceConstantAlpha = 125
    bf.AlphaFormat = %AC_SRC_ALPHA

    hBmp = GraphicLoadImageFileToBitmap("TransDialog.png",0,0,0) 'NB No stretch / distort
    hWDC = GraphicLoadImageFileToBitmap("Screne1.png",0,0,0) 'NB No stretch / distort

    IF ISFALSE AlphaBlend(hWDC,0,0,800,600,hBMP,0,0,800,600,BYVAL CVDWD(bf)) THEN MSGBOX "Error in AlphaBlend!"
    'IF ISFALSE AlphaBlend(hWDC,0,0,800,600,hBMP,0,0,800,600,BYVAL VARPTR(bf)) THEN MSGBOX "Error in AlphaBlend!"


    GRAPHIC WINDOW "AlphaBlend plus Transparent Blt",0,0,800,600 TO hWIn
    GRAPHIC ATTACH hWin,0,REDRAW
    GRAPHIC COPY hWDC, 0 TO (0,0) , %MIX_COPYSRC

    GRAPHIC REDRAW
    SLEEP 10000
    GRAPHIC WINDOW END
    GRAPHIC ATTACH hBMP,0
    GRAPHIC BITMAP END
    GdiplusShutdown GdipToken       'Shutdown GDI plus
END FUNCTION

Lassar

RadioTelephone Tutor : Get your FCC GROL License plus Radar Endorsement
http://radiotelephonetutor.com

José Roca

#1
The correct call is

IF ISFALSE AlphaBlend(hWDC,0,0,800,600,hBMP,0,0,800,600,bf)

CVDWD(bf) comes from when PB could nod pass structures by value.

Randall Glass

Okay I modified my code according to you api, and still no luck.



#COMPILE EXE

#INCLUDE "win32api.inc"

#INCLUDE ONCE "gdip_cut.bi"        'Have either this cut down lib included
''#include once "GdiPUtils.bi"       'Or include the full lib from Jose Roca

#INCLUDE ONCE "ImgFtoBM.bi"

'
%AC_SRC_OVER             = &H00
%AC_SRC_ALPHA            = &H01
'
TYPE BLENDFUNCTION BYTE
   BlendOp             AS BYTE
   BlendFlags          AS BYTE
   SourceConstantAlpha AS BYTE
   AlphaFormat         AS BYTE
END TYPE

DECLARE FUNCTION AlphaBlendIt LIB "MSIMG32.DLL" ALIAS "AlphaBlend" ( _
   BYVAL hdc AS DWORD _                                 ' __in HDC hdcDest
, BYVAL xoriginDest AS LONG _                          ' __in int xoriginDest
, BYVAL yoriginDest AS LONG _                          ' __in int yoriginDest
, BYVAL wDest AS LONG _                                ' __in int wDest
, BYVAL hDest AS LONG _                                ' __in int hDest
, BYVAL hdcSrc AS DWORD _                              ' __in HDC hdcSrc
, BYVAL xoriginSrc AS LONG _                           ' __in int xoriginSrc
, BYVAL yoriginSrc AS LONG _                           ' __in int yoriginSrc
, BYVAL wSrc AS LONG _                                 ' __in int wSrc
, BYVAL hSrc AS LONG _                                 ' __in int hSrc
, BYVAL ftn AS BLENDFUNCTION _                         ' __in BLENDFUNCTION ftn
) AS LONG


FUNCTION PBMAIN () AS LONG

   
    LOCAL hWin,hWDC,hBMP,hBMPDC AS DWORD
    LOCAL bf AS BLENDFUNCTION
    LOCAL DialogWidth%,DialogHeight%
    LOCAL GdipToken AS DWORD
    LOCAL StartupInput AS GdiplusStartupInput

    'Initialise GDI+ - this is required ONCE in app if any GDI+ stuff is used
    StartupInput.GdiplusVersion = 1
    IF GdiplusStartup(GdipToken,StartupInput, BYVAL %NULL) THEN
        MSGBOX "Error initialising GDI+ ... (Also, program needs XP or later)"
        EXIT FUNCTION
    END IF

    bf.BlendOp = %AC_SRC_OVER
    bf.BlendFlags = 0
    bf.SourceConstantAlpha = 125
    bf.AlphaFormat = %AC_SRC_ALPHA

    hBmp = GraphicLoadImageFileToBitmap("TransDialog.png",0,0,0) 'NB No stretch / distort
    hWDC = GraphicLoadImageFileToBitmap("Screne1.png",0,0,0) 'NB No stretch / distort

    IF ISFALSE AlphaBlendIt(hWDC,0,0,800,600,hBMP,0,0,800,600,bf) THEN MSGBOX "Error in AlphaBlend!"
    'IF ISFALSE AlphaBlend(hWDC,0,0,800,600,hBMP,0,0,800,600,BYVAL VARPTR(bf)) THEN MSGBOX "Error in AlphaBlend!"


    GRAPHIC WINDOW "AlphaBlend plus Transparent Blt",0,0,800,600 TO hWIn
    GRAPHIC ATTACH hWin,0,REDRAW
    GRAPHIC COPY hWDC, 0 TO (0,0) , %MIX_COPYSRC

    GRAPHIC REDRAW
    SLEEP 10000
    GRAPHIC WINDOW END
    GRAPHIC ATTACH hBMP,0
    GRAPHIC BITMAP END
    GdiplusShutdown GdipToken       'Shutdown GDI plus
END FUNCTION

Lassar

RadioTelephone Tutor : Get your FCC GROL License plus Radar Endorsement
http://radiotelephonetutor.com

José Roca

And which error do you get? GraphicLoadImageFileToBitmap uses declares that were appropiate for PB9, that had not unicode support, but not for my current headers for PB10.

Be careful when using old code. A lot of it is not longer compatible.

Randall Glass

No problem with GraphicLoadImageFileToBitmap

The png files load okay.

I get a error from the AlphaBlend function.

It returns 0 meaning a error.
Lassar

RadioTelephone Tutor : Get your FCC GROL License plus Radar Endorsement
http://radiotelephonetutor.com

José Roca

But GraphicLoadImageFileToBitmap returns DDT bitmap handles, and the AlphaBlend function used device contexts.