How to use the mask color with a bmp image on freebasic?
How to use the mask color with a bmp image on freebasic?
Hello World!
I want to know how to use the mask color freebasic BUT with a BMP image with magenta (RGB 255, 0, 255)
for delete this background color when i put a BMP image
Is it possible?
Because , i unable to use the alpha channel ..
Thank. :)
I want to know how to use the mask color freebasic BUT with a BMP image with magenta (RGB 255, 0, 255)
for delete this background color when i put a BMP image
Is it possible?
Because , i unable to use the alpha channel ..
Thank. :)
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: How to use the mask color with a bmp image on freebasic?
Hi,
If you are using a full-colour graphics mode, then you can mask out magenta in PUT using the TRANS modifier. See KeyPgTransGfx for an example.
Otherwise (for palette modes) the mask colour is always the 0th index, whatever colour that is.
If you are using a full-colour graphics mode, then you can mask out magenta in PUT using the TRANS modifier. See KeyPgTransGfx for an example.
Otherwise (for palette modes) the mask colour is always the 0th index, whatever colour that is.
Re: How to use the mask color with a bmp image on freebasic?
Thank you for your reply
but, i have always a problem
i cannot mask out magenta with a BMP image loaded..
i tested with this code (any image with magenta [255,0,255] )
but, i have always a problem
i cannot mask out magenta with a BMP image loaded..
i tested with this code (any image with magenta [255,0,255] )
Code: Select all
declare function bmp_load( ByRef filename As Const String ) As Any Ptr
Const NULL As Any Ptr = 0
ScreenRes 320, 200, 16
'' set up an image with the mask color as the background.
Dim img As Any Ptr = ImageCreate( 32, 32, RGB(255, 0, 255) )
img = bmp_load("img.bmp" )
If img = NULL Then
Print "bmp_load failed"
Else
Put (10, 10), img , Trans
ImageDestroy( img )
End If
'' free the image memory
ImageDestroy img
Sleep
'' file:///H:/FreeBASIC/doc/FreeBASIC/KeyPgBload.html
Function bmp_load( ByRef filename As Const String ) As Any Ptr
Dim As Integer filenum, bmpwidth, bmpheight
Dim As Any Ptr img
'' open BMP file
filenum = FreeFile()
If Open( filename For Binary Access Read As #filenum ) <> 0 Then Return NULL
'' retrieve BMP dimensions
Get #filenum, 19, bmpwidth
Get #filenum, 23, bmpheight
Close #filenum
'' create image with BMP dimensions
img = ImageCreate( bmpwidth, Abs(bmpheight) )
If img = NULL Then Return NULL
'' load BMP file into image buffer
If BLoad( filename, img ) <> 0 Then ImageDestroy( img ): Return NULL
Return img
End Function
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: How to use the mask color with a bmp image on freebasic?
Perhaps the colour is not exactly magenta.. Try using Hex(Point(x, y, img)); magenta pixels should have FF00FF for the last 6 digits.
By the way, the effects of using ImageDestroy on NULL are undefined, so you should only use it when bmp_load succeeds.
By the way, the effects of using ImageDestroy on NULL are undefined, so you should only use it when bmp_load succeeds.
Re: How to use the mask color with a bmp image on freebasic?
Hi,
HEX( Point(10, 10, img ))
make me " Error 41 : Variable required "
what do I do?
HEX( Point(10, 10, img ))
make me " Error 41 : Variable required "
what do I do?
Re: How to use the mask color with a bmp image on freebasic?
dim as uinteger valu = Hex( Point( 10,10, img ) ): print valu
Re: How to use the mask color with a bmp image on freebasic?
On microsoft paint , i have assigned le magenta at 255 , 0 , 255
but on this freebasic program , i don't have FF00FF value ..
i just have 9CC742, That do ? :(
ps : i'm use "ScreenRes 320, 200, 16"
but on this freebasic program , i don't have FF00FF value ..
i just have 9CC742, That do ? :(
ps : i'm use "ScreenRes 320, 200, 16"
Re: How to use the mask color with a bmp image on freebasic?
I believe, as counting_pine suggested, that the magenta in your bmp is off.
This might fix it
This might fix it
Code: Select all
Const NULL As Any Ptr = 0
Const Magenta565 = (31 shl 11) or 31
'' file:///H:/FreeBASIC/doc/FreeBASIC/KeyPgBload.html
Function bmp_load( ByRef filename As Const String ) As Any Ptr
Dim As Integer filenum, bmpwidth, bmpheight
Dim As Any Ptr img
'' open BMP file
filenum = FreeFile()
If Open( filename For Binary Access Read As #filenum ) <> 0 Then Return NULL
'' retrieve BMP dimensions
Get #filenum, 19, bmpwidth
Get #filenum, 23, bmpheight
Close #filenum
'' create image with BMP dimensions
img = ImageCreate( bmpwidth, Abs(bmpheight) )
If img = NULL Then Return NULL
'' load BMP file into image buffer
If BLoad( filename, img ) <> NULL Then ImageDestroy( img ): Return NULL
Return img
End Function
Sub ColReplace16( byval img as any ptr, _OldCol as UInteger, NewCol as ushort = Magenta565 )
if img = NULL then exit sub
dim as any ptr pixels
dim as integer wid,hgt,bypp,pitch, pitchBy2
ImageInfo img, wid, hgt, bypp, pitch, pixels: pitchBy2 = pitch \ 2
Union UnionARGB
Type
As UByte B
As UByte G
As UByte R
As UByte A
End Type
As UInteger ARGB
End Union
dim as UnionARGB OldCol32: OldCol32.ARGB = _OldCol
with OldCol32
dim as ushort OldCol16 = ((.R Shr 3) Shl 11) or ((.G Shr 2) Shl 5) or .B Shr 3
end with
for y as short ptr = pixels to pixels + (hgt-1)*pitch step pitchBy2
for x as short ptr = y to y + wid-1
if *x = OldCol16 then *x = NewCol
Next
Next
End Sub
'' -------
'' Main
'' -------
ScreenRes 320, 200, 16
Dim As Any Ptr img = bmp_load("img.bmp" )
ColReplace16( img, point( 10, 10, img ), Magenta565 )
If img = NULL Then
Print "bmp_load failed"
Else
Put (10, 10), img , Trans
ImageDestroy( img )
End If
Sleep
Last edited by dafhi on Mar 13, 2013 9:14, edited 1 time in total.
Re: How to use the mask color with a bmp image on freebasic?
Thank you for your code, he work!
But i have 3 warning (see picture)
it's normal ?
But i have 3 warning (see picture)
it's normal ?
Re: How to use the mask color with a bmp image on freebasic?
Try to declare 'pixels' as a 'short ptr':
Code: Select all
dim as integer wid,hgt,bypp,pitch,pitchBy2
dim as short ptr pixels
Re: How to use the mask color with a bmp image on freebasic?
sample updated. thanks
Re: How to use the mask color with a bmp image on freebasic?
Thank you, it work ! :D
And last question (see picture)
why green color (RGB : 152,199,68 ) it's transparent ? :S
(zoom for good see)
And last question (see picture)
why green color (RGB : 152,199,68 ) it's transparent ? :S
(zoom for good see)
Re: How to use the mask color with a bmp image on freebasic?
google Pixelformer, a simple program which will show u the alpha channel
Re: How to use the mask color with a bmp image on freebasic?
Okay :)
Thank you very much at all people for your help!
Bye
Thank you very much at all people for your help!
Bye
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: How to use the mask color with a bmp image on freebasic?
Just to say, if we need to do direct memory manipulation then something's going wrong somewhere, either with your code or in FB. It should be pretty much as straightforward as the code in the Trans example above.
Could you switch to a 32-bit graphics mode and see if it works there, and also give me the Hex(Point(...)) value again in 32-bit mode?
Can you also confirm what version of FreeBASIC you're using?
Could you switch to a 32-bit graphics mode and see if it works there, and also give me the Hex(Point(...)) value again in 32-bit mode?
Can you also confirm what version of FreeBASIC you're using?