CreateImage() with any color

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

CreateImage() with any color

Post by C64 »

Currently, CreateImage() defaults to black when used. Can an optional color be set, so we don't need to StartDrawing() a Box() with a specific color, after creating it?
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: CreateImage() with any color

Post by STARGÅTE »

The picture is after the create empty
empty = 0 = $000000 = black
so its black ;-)

You can use a macro to expand the command:

Code: Select all

Procedure CreateImageEx(Image.i, Width.i, Height.i, Depth.i=24, Color.l=$00000000)
  If Image = #PB_Any
    Image = CreateImage(Image, Width, Height, Depth)
  Else
    CreateImage(Image, Width, Height, Depth)
  EndIf
  If IsImage(Image)
    StartDrawing(ImageOutput(Image))
      DrawingMode(#PB_2DDrawing_AllChannels)
      Box(0, 0, Width, Height, Color)
    StopDrawing()
  EndIf
EndProcedure

Macro CreateImage(Image, Width, Height, Depth=24, Color=$00000000)
  CreateImageEx(Image, Width, Height, Depth, Color)
EndMacro
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: CreateImage() with any color

Post by C64 »

My request is to avoid using StartDrawing() after it, like I said in my first post. ;) Especially since I only use CreateImage() once in my program, so making a macro for it is a waste of space. It'd be nice just to be able to type in CreateImage(#PB_Any,w,h,color) instead.
User avatar
A.D.
User
User
Posts: 98
Joined: Tue Oct 06, 2009 9:11 pm

Re: CreateImage() with any color

Post by A.D. »

How can i make the background transparent ? I tried all alpha channels but the background remains black for me. I need an "empty" background
Repeat
PureBasic
ForEver
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: CreateImage() with any color

Post by STARGÅTE »

use the #PB_Image_Transparent constant

Code: Select all

CreateImage(#Image, Width, Height, 32|#PB_Image_Transparent)
this image is an empty image
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
A.D.
User
User
Posts: 98
Joined: Tue Oct 06, 2009 9:11 pm

Re: CreateImage() with any color

Post by A.D. »

Thx :-)
Repeat
PureBasic
ForEver
Post Reply