Page 1 of 1
Save brush with transparency
Posted: Sun Oct 09, 2016 1:07 pm
by Lerio69
I have create a brush (not from file) with BLACK color background and draw in it.
Now I want to save it in PNG with transparency, so i try to use command:
Code: Select all
SaveBrush(1, image$, #BLACK, #IMGFMT_PNG)
But the image saved not have transparency.
If I try to use AlphaChannel
Code: Select all
CreateBrush(1, wX, hY, #BLACK, {AlphaChannel = True, Clear = True})
The image saved is all black.
How can create and save brush with transparency?
Re: Save brush with transparency
Posted: Sun Oct 09, 2016 3:30 pm
by Lerio69
Saving to GIF format work, image saved have transparency. So this is a bug?
Re: Save brush with transparency
Posted: Thu Oct 13, 2016 5:38 pm
by airsoftsoftwair
It doesn't really make sense to use the "transcol" argument if your brush already has an alpha channel. The "transcol" argument is meant to mask out areas of an opaque brush. If your brush isn't opaque, don't use the "transcol" argument at all, i.e. do this:
Code: Select all
CreateBrush(1, 640, 480, #BLACK, {AlphaChannel = True, Clear = True})
SaveBrush(1, "test.png", #NOTRANSPARENCY, #IMGFMT_PNG)
This works fine here.
Re: Save brush with transparency
Posted: Sun Oct 16, 2016 1:02 am
by Lerio69
Yes, this save a PNG without transparency,
the question is that I want a PNG with transparency, but I cant.
I try to create two function.
One that read a waypoints from a file and draw its in a brush.
Second that save brush in all image format.
Code: Select all
Function DrawAIW(wX, hY)
...
CreateBrush(1, wX, hY)
...
EndFunction
Function Save_Brush()
fname$ = UnleftStr(FilePart(file$), 3).."png"
pname$ = PathPart(file$)
image$ = FileRequest("Save Image", "png|jpg|gif|bmp", #REQ_SAVEMODE, pname$, fname$)
var$ = RightStr(image$, 3)
If image$<>""
Switch var$
Case "png":
fmt = #IMGFMT_PNG
Case "jpg":
fmt = #IMGFMT_JPEG
Case "bmp":
fmt = #IMGFMT_BMP
Case "gif":
fmt = #IMGFMT_GIF
EndSwitch
SaveBrush(brush, image$, #BLACK, fmt, {dither=True})
EndIf
EndFunction
With this code, when I select to save brush as PNG, the image file
not have transparency.
But if I select to save in GIF format, image file have transparency (this is ok and what I want)
Re: Save brush with transparency
Posted: Sun Oct 16, 2016 12:12 pm
by Allanon
mmm...
Could you try to create you brush with:
Code: Select all
CreateBrush(1, wX, hY, #BLACK, { AlphaChannel = True, Clear = True })
This way at creation time you enable the transparency channel and you also clear all the brush contents, making it full transparent.
Re: Save brush with transparency
Posted: Sun Oct 16, 2016 3:31 pm
by Lerio69
I made this app for testing whats happen.
Code: Select all
@REQUIRE "RapaGUI"
@DISPLAY {Width = 600, Height = 400, color = #BLACK}
CreateBrush(1, 600, 400)
Function p_Save_Brush()
image$ = FileRequest("Save Image", "png|jpg|gif|bmp", #REQ_SAVEMODE)
var$ = RightStr(image$, 3)
If image$<>""
Switch var$
Case "png":
fmt = #IMGFMT_PNG
Case "jpg":
fmt = #IMGFMT_JPEG
Case "bmp":
fmt = #IMGFMT_BMP
Case "gif":
fmt = #IMGFMT_GIF
EndSwitch
SaveBrush(1, image$, #BLACK, fmt, {dither=True})
EndIf
EndFunction
Function p_Draw(W,H)
FreeBrush(1)
CreateBrush(1, W, H)
SelectBrush(1)
SetFillStyle(#FILLCOLOR)
Box(W/2, H/2, 2+Rnd(200), 2+Rnd(100), #WHITE)
SetFillStyle(#FILLNONE)
Circle(100, 100, 2+Rnd(80), #RED)
DisplayBrush(1, #CENTER, #CENTER)
EndFunction
Function p_EventFunc(msg)
Switch msg.Class
Case "Button":
Switch msg.attribute
Case "Pressed":
Switch msg.ID
Case "draw":
p_Draw(600, 400)
Case "save":
p_Save_Brush
EndSwitch
EndSwitch
EndSwitch
EndFunction
AppStr$=[[<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
<window id="win" title="AIW Converter" sizegadget="False">
<hgroup>
<vgroup>
<hgroup frame="true">
<hollywood id="hwmcc1" display="1"/>
<rectangle/>
</hgroup>
</vgroup>
<vgroup>
<button fixwidth="true" width="135" id="draw">Draw</button>
<rectangle />
<button fixwidth="true" width="135" id="save">Save</button>
</vgroup>
</hgroup>
</window>
</application>]]
InstallEventHandler({RapaGUI = p_EventFunc})
moai.CreateApp(AppStr$)
Repeat
WaitEvent
Forever
In my main App, p_Draw is called after Loading a File or change graphics option (colors and/or line width and/or image dimensions)
If in p_Draw I change the line
in
Code: Select all
CreateBrush(1, W, H, #BLACK, { AlphaChannel = True, Clear = True })
I have another Issue: the brush result completly Black and not displayed.
Re: Save brush with transparency
Posted: Mon Oct 17, 2016 6:25 pm
by Allanon
Hi Lerio69,
I've tried your script on my machine (Windows10) and every time I press [draw] a box and a circle are drawn...
Re: Save brush with transparency
Posted: Mon Oct 17, 2016 6:56 pm
by Lerio69
Yes, this is only a simulation of my App.
Have you tried to save the image in PNG and GIF formats to see the differences?
Re: Save brush with transparency
Posted: Tue Oct 18, 2016 12:59 am
by Allanon
Here is the fixed version
Have a look at SelectBrush() documentation to check varius #SELMODE_COMBO modes
Code: Select all
Function p_Draw(W,H)
; Ad ogni redraw devi cancellare lo schermo
SetFillStyle(#FILLCOLOR)
Box(0, 0, w, h, #BLUE)
FreeBrush(1)
CreateBrush(1, W, H, #BLACK, { AlphaChannel = True, Clear = True })
; Il brush va selezionato in modalità combo perchè così
; puoi disegnare anche nell'alpha channel
SelectBrush(1, #SELMODE_COMBO, 1)
Box(W/2, H/2, 2+Rnd(200), 2+Rnd(100), #WHITE)
SetFillStyle(#FILLNONE)
Circle(100, 100, 2+Rnd(80), #RED)
; Con EndSelect() riporti il display come dispositivo di
; output
EndSelect()
DisplayBrush(1, #CENTER, #CENTER)
EndFunction
Re: Save brush with transparency
Posted: Tue Oct 18, 2016 2:43 pm
by Lerio69
Thanks a lot, I have to learn many things.