I try to draw a red dotted line into a canvas. The smoothest line so far results from using MBS examples. However, I’m not able to create a transparent picture, the result is a red dotted line on either white or black background, but not transparent.
What would be the shortest way to draw such a line on a canvas, without losing transparency?
My code so far:
[code]Sub Resizing()
dim p as Picture
p=New Picture(Self.Canvas1.Width,Self.Canvas1.Height,32)
p.Transparent=1
Dim n As new NSImageMBS§
Dim g as new NSGraphicsMBS(n)
g.setFillColor NSColorMBS.redColor
Dim b as NSBezierPathMBS = NSBezierPathMBS.bezierPath
b.moveToPoint NSMakePointMBS(0, 0)
b.lineToPoint NSMakePointMBS(Self.Canvas1.Width, Self.Canvas1.Height)
dim pattern() as Double
pattern.Append 10
pattern.Append 4
b.lineWidth = 1
b.setLineDash pattern, 12
g.stroke(b)
g = nil
// assign to property
img = n.CopyPicture // red line with dash pattern
End Sub
[/code]
There is definitely some wonkiness going on here. When you create a picture with the optional depth parameter, you are using the older style Picture object that does not have any alpha ability. I believe the MBS plugins have been updated to expect and support the newer style, that uses alpha for determining transparency.
I’ve fiddled with your code a bit, and can’t get it to make the round trip without a solid background, though. Probably need to ask @Christian Schmitz for an example.
Yes, I tried the old and the new style, that is New Picture with and without passing in the depth (32) - but both resulted in the same non transparent picture at the end.
I tried to find more info in the MBS docu, and in fact the original example was supposed to create a transparent picture, which it does not (black instead).
I’m testing in OSX 10.9.1, rMBP.
I hope Christian will drop by and have a look at it …
Ok, I found a solution to get the transparent picture: CopyPictureWithMask!
I just changed the last line of the above code to this:
// assign to property
img = n.CopyPictureWithMask // red line with dash pattern
excellent.
but when you have code here like this:
[code]dim p as Picture
p=New Picture(Self.Canvas1.Width,Self.Canvas1.Height,32)
p.Transparent=1
Dim n As new NSImageMBS§[/code]
you create a white picture and than create a copy of it as NSImageMBS. No need for that. Simply create a NSImageMBS of the desired with.
[quote=65934:@Christian Schmitz]
you create a white picture and than create a copy of it as NSImageMBS. No need for that. Simply create a NSImageMBS of the desired with.[/quote]
Right.
I modified my canvas class method like this:
[code]Sub imDrawLine(x As Integer, y As Integer)
Dim n As New NSImageMBS(Me.Width,Me.Height)
Dim g As New NSGraphicsMBS(n)
g.setFillColor NSColorMBS.redColor
Dim b As NSBezierPathMBS = NSBezierPathMBS.bezierPath
b.moveToPoint NSMakePointMBS(Me.lastMouseX, Me.Height-Me.lastMouseY)
b.lineToPoint NSMakePointMBS(x, Me.Height-y)
Dim pattern() As Double
pattern.Append 10
pattern.Append 4
b.lineWidth = 1
b.setLineDash pattern, 12
g.stroke(b)
g = Nil
// assign to property
Me.img = n.CopyPictureWithMask // red line with dash pattern
End Sub
[/code]
The result looks like this:

And this is what you want?
Yes. in the actual App I use this as a visual indicator in order to create a link between two objects with drag&drop.