Line

Just starting out? Need help? Post your questions and find answers here.
spacebuddy
Enthusiast
Enthusiast
Posts: 361
Joined: Thu Jul 02, 2009 5:42 am

Line

Post by spacebuddy »

Hi All,

I am using the line command to draw lines on a image. This works well except when the image
has a transparent background, the line command does not work on transparent backgrounds.

Is there anyway to make it show on a transparent background?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Line

Post by RASHAD »

Hi

Code: Select all

OpenWindow(0,0,0,800,600,"Contrast 4 Image",#PB_Window_SystemMenu |#PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
ImageGadget(0,10,10,780,580,0)
CreateImage(0,780,580,32,#PB_Image_Transparent )
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels )
Line(10,10,700,500,$FF0000FF) ;Use RGBA colors with alpha = 255
StopDrawing()
SetGadgetState(0,ImageID(0))
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1      
 
  EndSelect
Until Quit = 1
Egypt my love
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Line

Post by Saki »

Better Quality and more flexible

Code: Select all

OpenWindow(0, 0, 0, 800, 600, "", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)
ImageGadget(0, 10, 10, 780, 580, 0)
CreateImage(0, 780, 580, 32, #PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(0))
MovePathCursor(10, 10)
AddPathLine(700, 500)
VectorSourceColor(#Red|$FF000000)
StrokePath(1)
StopVectorDrawing()
SetGadgetState(0,ImageID(0))
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
地球上の平和
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Line

Post by TI-994A »

spacebuddy wrote:...the line command does not work on transparent backgrounds...
A simple working example:

Code: Select all

UsePNGImageDecoder()

Enumeration
  #MainWindow
  #Canvas
  #Image
EndEnumeration

transparentImage.s = OpenFileRequester("Select Transparent Image:", "", "PNG |*.png", 0)
If transparentImage And LoadImage(#Image, transparentImage)
  
  imgWidth = ImageWidth(#Image)
  imgHeight = ImageHeight(#Image)
  wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
  OpenWindow(#MainWindow, 0, 0, imgWidth, imgHeight, "Draw On Transparent Image", wFlags)
  CanvasGadget(#Canvas, 0, 0, imgWidth, imgHeight)
  
  StartDrawing(ImageOutput(#Image))
    DrawingMode(#PB_2DDrawing_AllChannels)
    FrontColor(RGBA(220, 100, 100, 255))
    LineXY(10, 10, imgWidth - 10, 10)
    LineXY(10, 10, 10, imgHeight - 10)
    LineXY(10, imgHeight - 10, imgWidth - 10, imgHeight - 10)
    LineXY(imgWidth - 10, 10, imgWidth - 10, imgHeight - 10)
  StopDrawing()
  
  StartDrawing(CanvasOutput(#Canvas))
    Box(0, 0, imgWidth, imgHeight, RGB(255, 255, 220))
    DrawAlphaImage(ImageID(#Image), 0, 0)
  StopDrawing()
  
  While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
  
EndIf
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
spacebuddy
Enthusiast
Enthusiast
Posts: 361
Joined: Thu Jul 02, 2009 5:42 am

Re: Line

Post by spacebuddy »

Thank you all for the help, but I still can't get this to work. I am thinking there could be
some thing wrong with my image.

I put the image in my dropbox if someone has time to check it out.

https://www.dropbox.com/s/1zcr5nzionb03 ... n.png?dl=0

It works on other images I have tried, but not this one.

Thanks
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Line

Post by TI-994A »

spacebuddy wrote:...It works on other images I have tried, but not this one.
This is the output of your image using my example. Seems to work.

Image
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Line

Post by Saki »

I think you have forget : UsePNGImageDecoder()

If you don't think about it , this is the most common mistake, as there is no usable feedback.

Code: Select all

UsePNGImageDecoder()
image_ID=LoadImage(#PB_Any, "C:\Users\Tanaka\Desktop\VJJmCVaD.png")
OpenWindow(0, 0, 0, 800, 600, "", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)
ImageGadget(0, 10, 10, 780, 580, 0)
StartVectorDrawing(ImageVectorOutput(image_ID))
MovePathCursor(10, 10)
AddPathLine(700, 500)
VectorSourceColor(#Red|$FF000000)
StrokePath(1)
StopVectorDrawing()
SetGadgetState(0,ImageID(image_ID))
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
地球上の平和
spacebuddy
Enthusiast
Enthusiast
Posts: 361
Joined: Thu Jul 02, 2009 5:42 am

Re: Line

Post by spacebuddy »

Okay, I just tested it under Windows and it does work. But when I try the same code on my Mac
it does not work. I think this is a bug under Mac OS/X

Thanks all
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Line

Post by Saki »

Under MacOS the event processing is a bit different.
Try before the final output
While WindowEvent() : Wend, so that all events are processed.

Also the output to "Hidden" does not work on all OS, but always on Windows.
地球上の平和
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Line

Post by Shardik »

spacebuddy wrote:Okay, I just tested it under Windows and it does work. But when I try the same code on my Mac
it does not work. I think this is a bug under Mac OS/X
I have taken TI-994A's example and loaded the goblin.png from spacebuddy and tested it on MacOS 10.14.6 'Mojave' with PB 5.73 x64. It shows a similar output as the output image posted by TI-994A. I only had to change the x1 value in LineXY from 10 to 40 and also adapt the respective x2 value.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Line

Post by Saki »

If this didn't work, almost none of my codes for PB on Mac would work.
Since everything is checked on Mac, PB bug is excluded.
There remains only the possibility that perhaps a VM is used which triggers the bug.
地球上の平和
spacebuddy
Enthusiast
Enthusiast
Posts: 361
Joined: Thu Jul 02, 2009 5:42 am

Re: Line

Post by spacebuddy »

I am using Big Sur on a Mac mini m1, the program is running under rosetta2, I am wondering if that is the problem.

Under Windows 10 it works perfectly.

Thanks
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Line

Post by RASHAD »

Use all you can get from 2DDrawing lib
Use carefully DrawingMode() you can get lot of effects
Simple and straight forward

Code: Select all

UsePNGImageDecoder()

LoadImage(0,"I:\goblin.png")

OpenWindow(0,0,0,ImageWidth(0)+20,ImageHeight(0)+20,"Test", #PB_Window_SystemMenu |#PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
ImageGadget(0,10,10,780,580,ImageID(0))
StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels |#PB_2DDrawing_Outlined )
  Box(10,10,ImageWidth(0)-20,ImageHeight(0)-20,$FF0000FF) ;Use RGBA colors with alpha = 255
  LineXY(20,20,ImageWidth(0) - 20,370,$FFFF0000)
  DrawingMode(#PB_2DDrawing_AllChannels) 
  Box(140,20,4,ImageHeight(0)-40,$FF00FF00)
StopDrawing()
SetGadgetState(0,ImageID(0))
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1     
 
  EndSelect
Until Quit = 1
Egypt my love
User avatar
TI-994A
Addict
Addict
Posts: 2740
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Line

Post by TI-994A »

spacebuddy wrote:I am using Big Sur on a Mac mini m1, the program is running under rosetta2...
In that case, this could simply be a compatibility issue with the new OS, processor, or translator.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Line

Post by Shardik »

TI-994A wrote:
spacebuddy wrote:I am using Big Sur on a Mac mini m1, the program is running under rosetta2...
In that case, this could simply be a compatibility issue with the new OS, processor, or translator.
That seems indeed to be the problem. I did the same test described above for Mojave on my Intel iMac 5K 2019 with MacOS 11.1 'Big Sur' and PB 5.73 x64 and it works like a charm.
Last edited by Shardik on Sat Jan 30, 2021 10:02 am, edited 1 time in total.
Post Reply