Groups | Blog | Home
all groups > dotnet drawing api > july 2007 >

dotnet drawing api : Clip image based on emf metafile


Mark
7/9/2007 2:18:50 PM
Hi,

I'm trying to clip an image to an irregular shape. I've come across some
advice from Bob Powell
(http://groups.google.co.uk/group/microsoft.public.dotnet.framework.drawing/browse_thread/thread/86485270f7a57ede/dd79ef1988191326?lnk=st&q=cropping+or+extracting+ellipse+from+image&rnum=1&hl=en#dd79ef1988191326)
that works nicely, but I'd like to replace the ellipse with a shape based on
an emf file for the clip region.

Can anyone point me in the right direction?

Thanks

Mark
Michael C
7/10/2007 12:00:00 AM
[quoted text, click to view]

I'm not sure if this is the ideal solution but you could draw the emf file
to a bitmap and use that as a mask.


[quoted text, click to view]

Mark
7/10/2007 12:00:00 AM
Thanks for your reply Michael. Why not ideal? Unfortunately I'm stuck with
having to use emf files. My assumption was that as Bob Powell's solution
used a GraphicsPath I could get the same from an emf file?

Could you give any more details on your idea as I'm quite new at this?

Thanks again.

Mark

[quoted text, click to view]
Michael C
7/11/2007 12:00:00 AM
[quoted text, click to view]

When I say not ideal I mean there might be a better method that I don't know
about, such as converting an emf to a path. Then again my idea might be the
only option seeing there have been no other replies.

[quoted text, click to view]

Assuming you start with a bitmap of 100x100 and want to set some areas to
transparent based on an emf file (correct me if I'm wrong) try something
like this:
Create a second bitmap of 100x100
Draw the emf to the second bitmap
Use LockBits to iterate through every pixel of both bitmaps (look up help on
lock bits or search bob's website)
Set pixels to transparent in the initial bitmap based on the second bitmap.

That's probably not enough detail again but give it a go and have a look at
LockBits and get back to me with any questions.

Michael

Mark
7/11/2007 6:31:17 PM
Hi Michael,

I see what you mean. That seems a good idea and I'll give it a go.

Thanks very much for the extra details.

Mark

[quoted text, click to view]
ohs
7/19/2007 10:12:14 PM
Hi Mark

Did you get anywhere with your graphicpath clipping ?

I'm trying to 'cut out' an area of an image using a graphics path so that I
can assign the clipped image to a button.


I posted here on 7/16/07 but no takers.

[quoted text, click to view]
Mark
7/26/2007 12:00:00 AM
Not yet I'm afraid.

Will post back when I make progress.

Mark


[quoted text, click to view]
AddThis Social Bookmark Button