Need Help in Picture

Hi, nothing important. I just would like to understand picture.
I copy paste in the project attached the part of one of my program.
I have a Canvas and I draw in it the icon of my application (a PNG with transparency : IconApp_128.png).
I draw above another icon with transparency (2 PNG , the picture DragDrop_128i.png and its Mask DragDrop_128m.png ).
And when I fly over with my mouse (or drag something because my canvas receipt files user drop on it) I draw a text with transparency too.

I wrote this code long time ago copying example I found I don’t remember where.
I update this code for API2, but update is not the right word, I did what I could in order to make it work.

Then it work, run the project and fly over the canvas. If someone know how to write the code as it should be, because I guess my code is not optimum.
I don’t know if it is possible to do the same thing with only a PNG with transparency DragDrop_128.png (without the mask in another file).

For help (depending on the context / user interface help), I use a Label at the window botton, not above the object.

Look at how the Xojo IDE Code Editor do (nearly the same as I do).

I will check that after a good night, tomorrow, if needed.

Hello Thomas Robisson

my code is

Paint:

Var pic,maske As picture

pic = New picture(dragdrop_128i.Width,dragdrop_128i.height)
pic.Graphics.drawpicture dragdrop_128i,0,0
maske = pic.copymask
maske.Graphics.ClearRectangle(0,0,pic.Width,pic.height)
maske.Graphics.drawpicture DragDrop_128m,0,0
pic.ApplyMask(maske)

g.drawpicture IconApp_128,10,10,canvas1.Width-20,canvas1.height-20,0,0,IconApp_128.Width,IconApp_128.height

g.drawpicture pic,10,10,canvas1.Width-10,canvas1.height-10,10,10,dragdrop_128i.Width,dragdrop_128i.height

g.PenSize=3
g.DrawRoundRectangle(0,0,canvas1.Width,canvas1.height,10,10)

new example :

https://www.dropbox.com/s/8q6j31u04n6sien/TestCanvasChange2.xojo_binary_project?dl=1

Thank you. I will look into this. The second picture above the first in transparent.
If you look at line 62 :

g.DrawPicture(PictTransp(DragDrop_128i, DragDrop_128m, [b]30[/b]), MarB, MarB, Wdd - (2 * MarB), Hdd - (2 * MarB), 0, 0, 128, 128)
Replace 30 by 80 and you will see it.

I’ll try to make it transparent with your code. Thanks again.

Hello Thomas,

I overlooked the transparency of the second picture.

I like to use pixmap shapes for my design. These are easy
change in size, transparency, rotation.

in your example I inserted the 5 lines

try it

I use the New Picture to indicate the depth, 32 no longer to be transparent
Get picture
I do not know if this is also possible with Windows.

Var pic,maske As picture

pic = New picture(dragdrop_128i.Width,dragdrop_128i.height)
pic.Graphics.drawpicture dragdrop_128i,0,0
maske = pic.copymask
maske.Graphics.ClearRectangle(0,0,pic.Width,pic.height)
maske.Graphics.drawpicture DragDrop_128m,0,0
pic.ApplyMask(maske)
//--------------
Var px As PixmapShape
px = New PixmapShape(pic)
px.FillOpacity = 80
px.scale =0.70
g.drawpicture IconApp_128,6,5,canvas1.Width-14,canvas1.height-10,0,0,IconApp_128.Width,IconApp_128.height

g.drawobject px,canvas1.Width/2,canvas1.height/2

//g.drawpicture pic,10,5,canvas1.Width-15,canvas1.height-10,5,0,dragdrop_128i.Width,dragdrop_128i.height

g.PenSize=3
g.DrawRoundRectangle(0,0,canvas1.Width,canvas1.height,10,10)
If textpic <> Nil Then
g.DrawPicture textpic,3,11
End If

I did some try today and I now use dragdrop_128.png with transparency instead of dragdrop_128i.png and dragdrop_128m.png. I saw that I can’t do .CopyMask and .ApplyMask to an image ( dragdrop_128 ). Even if I send this image to a Method.

MyPict2 = MyMethod(dragdrop_128)

and in MyMethod :

MyMethod(MyPic as picture) MyMask = MyPic.CopyMask
I got an error “CopyMask is not supported for images” but MyPic is a picture. Not clear.
And I understand now it’s normal and logic. If I want to CopyMask, I have to do it from a picture with NO Depth (then Transparency). And if I want to ApplyMask to a picture, I have to do it to a picture with Depth (then no transparency).

MyPic = New Picture(MyWidth, MyHight) ' NO ,32 MyPic.Graphics.DrawPicture(DragDrop_128, 0, 0) MyMask = MyPic.CopyMask
in this case it works. But if I put the “, 32” then the transparency of DragDrop_128 is lost and the Mask has no transparency (logic I now know).
And if I want to apply mask, I must apply it to a picture with depth :

MyPic = New Picture(MyWidth, MyHight, 32) MyPic.Graphics.DrawPicture(DragDrop_128, 0, 0) MyPic.ApplyMask(MyMask)
If I don’t put the “,32”, the instruction does not report an error, but it doesn’t work.

Like to learn bicycle, once we know we feel silly to do not know before.

Thank you for your help, I didn’t do with your code PixmapShape but with your example I reach to make my code more efficient. And more than that, I understand what I code.

One last thing, during my test I did MyPic.HasAlphaChannel and the application crash (no report in Xojo, it crash with a Finder alert).

Hello Thomas,
with the switch to API 2 I have
with my pictures a little effort to redesign them
API 1 had image and mask on 2 levels and I was able to
Mask in and hide the image parts.
in API 2 the mask is in the picture
if something is hidden this part is deleted = black
and cannot be brought back.
to your problem picture.HasAlphaChannel solves
the little example.

Rem Methode: HELLdark (Pic as Picture)

rem Picture light/dark
Var surf,burf As RGBSurface
Var i,ii,b,h,w As Integer
Var maske As picture
Var c,c2 As Color
If Pic <> Nil Then

b= Pic.Width
h=Pic.height
surf = Pic.RGBSurface
If Pic.HasAlphaChannel Then
maske = Pic.copymask // new (Picture(w,h)
Else
maske = Pic.mask // old (Picture(w,h,32)
End If
burf = maske.RGBSurface
w=10
For i = 0 To b
For ii = 0 To h
c2 = burf.Pixel(i,ii) // Maske White/Black
c = surf.Pixel(i,ii)
If c2.red < 252 And c2.green < 252 And c2. blue < 252 Then // not color.White
If checkdark.value Then
surf.pixel(i,ii)= Color.RGB(c.red-w,c.green-w,c.Blue-w,c.alpha)
Else
surf.pixel(i,ii)= Color.RGB(c.red+w,c.green+w,c.Blue+w,c.alpha)
End If
End If
Next
Next
End If

canvas1.Invalidate(False)