Page 1 of 2

Line

Posted: Fri Jan 29, 2021 6:19 pm
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?

Re: Line

Posted: Fri Jan 29, 2021 6:40 pm
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

Re: Line

Posted: Fri Jan 29, 2021 7:30 pm
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

Re: Line

Posted: Fri Jan 29, 2021 7:51 pm
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

Re: Line

Posted: Fri Jan 29, 2021 8:13 pm
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

Re: Line

Posted: Fri Jan 29, 2021 8:24 pm
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

Re: Line

Posted: Fri Jan 29, 2021 8:43 pm
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

Re: Line

Posted: Fri Jan 29, 2021 9:12 pm
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

Re: Line

Posted: Fri Jan 29, 2021 9:27 pm
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.

Re: Line

Posted: Fri Jan 29, 2021 10:10 pm
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.

Re: Line

Posted: Fri Jan 29, 2021 10:38 pm
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.

Re: Line

Posted: Sat Jan 30, 2021 12:01 am
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

Re: Line

Posted: Sat Jan 30, 2021 6:03 am
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

Re: Line

Posted: Sat Jan 30, 2021 7:44 am
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.

Re: Line

Posted: Sat Jan 30, 2021 9:54 am
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.