Author Topic: Is there a way to get the _rgb32 values of a background  (Read 3890 times)

0 Members and 1 Guest are viewing this topic.

Offline random1

  • Newbie
  • Posts: 86
    • View Profile
Is there a way to get the _rgb32 values of a background
« on: September 27, 2021, 02:20:02 pm »
Hi all

I load a image and then want to print some text over the image, the problem is that I need
to set the background color so that the text prints transparently over the image.  I have tried
matching using the color dialog box with no luck.  I was thinking there was a way to get the
color of a pixel.  I could make a transparent image of the text and then lay that over the image
but wanted to know if there is a easier way.

Thanks
R1

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Is there a way to get the _rgb32 values of a background
« Reply #1 on: September 27, 2021, 02:21:46 pm »
_PRINTMODE _KEEPBACKGROUND

Try that for transparent printing.
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Is there a way to get the _rgb32 values of a background
« Reply #2 on: September 27, 2021, 02:43:59 pm »
Quote
I need
to set the background color so that the text prints transparently over the image.

What Cobalt says or when you set color for text to print, set background color to transparent eg

Code: QB64: [Select]
  1. color &hffffffff, &h00000000  ' white fore color on transparent background
  2. _printstring(x,y), text$

OR

Code: QB64: [Select]
  1. Color _RGB32(255, 255, 255, 255), _RGB32(0,0,0,0)


Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Is there a way to get the _rgb32 values of a background
« Reply #3 on: September 27, 2021, 02:46:43 pm »
_PRINTMODE _KEEPBACKGROUND
PRINT "Some text"
_PRINTMODE _FILLBACKGROUND

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Is there a way to get the _rgb32 values of a background
« Reply #4 on: September 27, 2021, 02:49:43 pm »
To get a pixel color use:

Code: QB64: [Select]
  1. pixelColor~& = Point(x,y)  'unsigned long is best type for colors

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Is there a way to get the _rgb32 values of a background
« Reply #5 on: September 27, 2021, 04:20:34 pm »
'_keepbackground'? Cool  Tha'ts good to know... I had cobbled together a work-a-round. I defined a variable 'trans' and gave it the colour _rgba32(0,0,0,0) (fully transparent black). Then when printing text... Color foreground, trans. So much for that idea. Keepbackground is obviously a time saver... Cool.  I am curious also... How does keepbackground detect the colour of the background?
Logic is the beginning of wisdom.

FellippeHeitor

  • Guest
Re: Is there a way to get the _rgb32 values of a background
« Reply #6 on: September 27, 2021, 04:25:50 pm »
.  I am curious also... How does keepbackground detect the colour of the background?

It doesn't. Without _KeepBackground, both characters and bg are drawn pixel by pixel. With _KeepBackground only letters are drawn, so it literally keeps the BG untouched.

You can also draw transparent letters and opaque BG with _PrintMode _OnlyBackground

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Is there a way to get the _rgb32 values of a background
« Reply #7 on: September 27, 2021, 05:54:01 pm »
Cool... Looks like I need to do some more 'help' surfing... lol

Thank you.

J
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is there a way to get the _rgb32 values of a background
« Reply #8 on: September 27, 2021, 06:33:23 pm »
My trick for no background is usually just:

COLOR , 0

0, in 32-bit mode, is 0 alpha, 0 red, 0 green, 0 blue — it’s transparent nothing!

Another quick trick is the polar opposite of that: COLOR -1

-1, in 32-bit mode, because of overflow calculations, is 255 alpha, 255 red, 255 green, 255 blue — it’s solid white!

-1 = bright white.
0 = transparent.  (Not to be confused with black, which has 255 alpha and not 0.)

Two quick values to easily pop in when are where needs.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline random1

  • Newbie
  • Posts: 86
    • View Profile
Re: Is there a way to get the _rgb32 values of a background
« Reply #9 on: September 28, 2021, 10:50:03 pm »
Thanks for all the replies.

_PRINTMODE _KEEPBACKGROUND
and
_PRINTMODE _FILLBACKGROUND

Work perfect for my needs, I need to get out more.  0 = transparent, have to try that one.

R1