Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a _GETALPHA kind of method?
#1
I am adding alpha transparency parameter to a SUB using _SETALPHA to change the image, was wondering if there is a way to retrieve current alpha state of that image before I change it, so I can restore it what it was before after calling the SUB.

Thanks!

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#2
_ALPHA32(POINT(x,y))

Note that alpha is stored via pixel and not the whole image.    Wink

(Or just _ALPHA, if it's not a 32-bit screen.)
Reply
#3
Oh cool.  That was quick, and is easy.  Thanks!

- Dav

Find my programs here in Dav's QB64 Corner
Reply
#4
Yes, that works very well, Steve!  

I'm playing around with the original RotoZoom, adding some things, and setting the alpha of the image is one.  _SETALPHA calls slows down the SUB, but I would like that option for what I'm using it for.  This also has zoom factor apart from the xscale/yscale factor.  

In the program you can see the original image alpha being drawn by _PUTIMAGE at the bottom right was restored correctly by the SUB after using it.

EDIT: On second thought, maybe it would just be better to _COPYIMAGE a temp one to use and forget abut having to restore it.   Well, at least I know how to do that now.

- Dav

Code: (Select All)

Screen _NewImage(800, 600, 32)

'make an offscreen image to play with
image& = _NewImage(800, 600, 32)
_Dest image&
For o = 1 To 1000
    Color _RGB(Rnd * 255, Rnd * 255, Rnd * 255)
    Print Rnd;
Next
_Dest 0


Do
    Cls , _RGB(255, 255, 255)

    RotoZoomy 400, 300, image&, 1 + Sin(zoom), xscale, 1, angle, alpha
    RotoZoomy 100, 100, image&, .3, 1, xscale, -angle, 225
    RotoZoomy 700, 100, image&, .2, xscale, xscale, angle, 175
    RotoZoomy 300, 500, image&, .1, xscale, 1, -angle, 100

    Locate 1, 1
    Print "Angle :"; CInt(angle)
    Print "Zoom  :"; Using "##.###"; 1.5 + Sin(zoom)
    Print "Alpha :"; alpha

    'See im RotoZoomy restored original image alpa info
    _PutImage (650, 500)-(800, 600), image&

    _Display
    _Limit 60

    angle = angle + .5: If angle >= 360 Then angle = angle - 360
    If fadeway = 0 Then
        alpha = alpha + 1: If alpha > 254 Then fadeway = 1
    Else
        alpha = alpha - 1: If alpha < 1 Then fadeway = 0
    End If
    If xway = 0 Then
        xscale = xscale + .01: If xscale >= 1 Then xway = 1
    Else
        xscale = xscale - .01: If xscale <= 0 Then xway = 0
    End If

    zoom = zoom + .01
Loop Until InKey$ <> ""
End

Sub RotoZoomy (x&, y&, image&, zoom, xscale, yscale, angle, alpha)

    'Note: this isn't the original RotoZoom
    'I'm messing with it as an experiment. (Dav)

    _Dest image&
    origalpha = _Alpha32(Point(0, 0))
    _Dest 0

    If alpha < 0 Then alpha = 0
    If alpha > 255 Then alpha = 255
    _SetAlpha alpha, , image&

    w& = _Width(image&): h& = _Height(image&)

    Dim px(3) As Single: Dim py(3) As Single

    px(0) = -w& / 2: py(0) = -h& / 2 ' Top-left
    px(1) = -w& / 2: py(1) = h& / 2 ' Bottom-left
    px(2) = w& / 2: py(2) = h& / 2 ' Bottom-right
    px(3) = w& / 2: py(3) = -h& / 2 ' Top-right

    radianrotation = angle / 57.2957795131
    sinr = Sin(-radianrotation): cosr = Cos(-radianrotation)

    For i = 0 To 3
        x2 = (px(i) * cosr + py(i) * sinr) * zoom * xscale + x&
        y2 = (py(i) * cosr - px(i) * sinr) * zoom * yscale + y&
        px(i) = x2: py(i) = y2
    Next

    _MapTriangle _Seamless(0, 0)-(0, h& - 1)-(w& - 1, h& - 1), image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
    _MapTriangle _Seamless(0, 0)-(w& - 1, 0)-(w& - 1, h& - 1), image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))

    'restore alhpa
    _SetAlpha origalpha, , image&

End Sub

Find my programs here in Dav's QB64 Corner
Reply




Users browsing this thread: 1 Guest(s)