Import paint with mask

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Import paint with mask

Post by doobox » Fri Mar 30, 2012 9:38 am

Hi there i wonder where i am going wrong here...

I have :

Code: Select all

import paint from file dragData["files"] with mask specialfolderpath("desktop") & "/exhibit.pbm"
the dragged image in my test is a .jpg 300px x 300px
the mask is a .pbm plain black tile 300px x 300px

So i would have assumed i would get as a result a completely transparent image in my test.
I don't..!
What i get is the image in it's original appearance.

The docs say :
import type from file filePath [with mask maskFilePath]
eg: import paint from file it with mask "/etc/res/oval.pbm"
The maskFilePath specifies the name and location of a one-bit mask file for an image. You can use a mask file only if the file being imported is in the PBM format.
Am i misinterpreting this.. and i actually need the dragged in image file to also be in the .pbm format...?
Mind.. i tried this and it throws an error..!

??
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Import paint with mask

Post by doobox » Fri Mar 30, 2012 9:44 am

I wonder if my mask is correctly formatted...
I used a copy of contenta converta.. to create this .pbm file...

Link to .pbm file : http://dl.dropbox.com/u/6308635/exhibit.pbm
Kind Regards
Gary

https://www.doobox.co.uk

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Import paint with mask

Post by Klaus » Fri Mar 30, 2012 12:17 pm

Hi Gary,

I am sure there is a reason for you to deal with graphics formats from the last century!?
Is there? 8)

No chance you can deal with PNG or GIF files etc.?

Support for exotic formats like XWD, XBM, XPM, PBM, PGM, or PPM is a relict from the ancient days
way before 2000, when MetaCard, the grandpa of LiveCode, was UNIX only. :)


Best

Klaus

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Import paint with mask

Post by doobox » Fri Mar 30, 2012 12:30 pm

Hi Klaus,

I have never tried manipulating image data before. What i aim to do is clip out a transparent border of an image.
An example would be the way those ios icon apps work. I had assumed they were masking the rounded corners from the image data. And when i stumbled upon this in the docs :
import paint from file it with mask "/etc/res/oval.pbm"
I thought the black pixels in the oval.pbm mask there would make the pixels of the image in the it variable transparent. (like the way a photoshop vector mask appears to work).

Is there a way to have a black and white image overlay another image as a mask in this fashion..?
I had obviously optimistically thought i had stumbled on a free ride :-)
Kind Regards
Gary

https://www.doobox.co.uk

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Import paint with mask

Post by Klaus » Fri Mar 30, 2012 12:42 pm

Hi Gary,

you could use some "template" PNG files with the transparency you need in them
and then you could apply that mask to other images like this:
...
set the alphadata of img "the one without ranparency" to the alphadata of img "transparency template1"
...
Done it works fine! :D
BUT this requires that both images have IDENTICAL dimensions (w/h)!

Check "alphadata" in the dictionary.

EDIT:
I added a tiny demo stack :)


Best

Klaus
Attachments
alphadata1.rev.zip
(8.33 KiB) Downloaded 295 times

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Import paint with mask

Post by doobox » Fri Mar 30, 2012 12:49 pm

Thanks Klaus,

That sounds like the job :-)

Mean time i just discovered inks :-) :-)
Christmas has come early.. wow these are great.. i wont get another thing done in the current project today now :-)
Kind Regards
Gary

https://www.doobox.co.uk

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Import paint with mask

Post by Klaus » Fri Mar 30, 2012 12:52 pm

:)

Check the tiny stack I just added for a quick and dirty example...

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Import paint with mask

Post by doobox » Fri Mar 30, 2012 1:00 pm

Totally my goal when i started the day.. Thanks a million Klaus.
Kind Regards
Gary

https://www.doobox.co.uk

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Import paint with mask

Post by Klaus » Fri Mar 30, 2012 1:13 pm

Hi Gary,

my pleasure!

OK, next on my todo list: universal peace...
:D


Best

Klaus

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Import paint with mask

Post by doobox » Fri Mar 30, 2012 1:19 pm

All sorted for any image size now thanks to you...

Code: Select all

      import paint from file dragData["files"] 
      
      set the visible of last img to false
      put last img into fullSizeImageData -- save the origonal for later
      delete last img
      put fullSizeImageData into me
      
      rescaleIcon "photoDropZone", 300
      setBackgroundFrame
      put the width of image "photoDropZone" into tImageWidth
      put the height of image "photoDropZone" into tImageHeight
      set the width of image "mask" to tImageWidth
      set the height of image "mask" to tImageHeight
      set the alphadata of img "photoDropZone" to the alphadata of img "mask"
If you need a hand with universal peace, just shout :-)
Kind Regards
Gary

https://www.doobox.co.uk

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Import paint with mask

Post by Klaus » Fri Mar 30, 2012 3:19 pm

Hi Gary,
doobox wrote:All sorted for any image size now thanks to you...
glad you got it working!
doobox wrote:... If you need a hand with universal peace, just shout :-)
Ah, great, might be the case, thank you :D


Best

Klaus

Post Reply