Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Eelze  
#1 Posted : Tuesday, January 15, 2008 5:04:33 PM(UTC)
Eelze

Rank: Newbie

Groups: Member
Joined: 1/15/2008(UTC)
Posts: 4

Hi,

I am looking for a solution of the following. We have an image where we want to create rounded edges. These edges must be transparant.

Therefore I see two possible solutions:
1) Draw an polygoon and fill that with transparancy
2) Use a sort of mask to lay above the image.

For that last method I have added see these example.
UserPostedImage

The problem is that for both methods I am not sure they are possible, because the edges must be transparant. Have you an example for the way this can be done? And may be there is another solution?

Kind regards,

Eelze
Eelze attached the following image(s):
transparancy.JPG
Eelze  
#2 Posted : Wednesday, January 16, 2008 5:00:32 PM(UTC)
Eelze

Rank: Newbie

Groups: Member
Joined: 1/15/2008(UTC)
Posts: 4

Has someone an suggestion?
undead80  
#3 Posted : Wednesday, January 16, 2008 6:14:41 PM(UTC)
undead80

Rank: Member

Groups: Member
Joined: 1/7/2008(UTC)
Posts: 28

You may consider using the MaskTransform feature. Put black color in the mask picture on where you would like it to be transparent, while white color on the area you would prefer to keep the image.

Hope this will help.

Code:
        Dim UserImage As New Aurigma.GraphicsMill.Bitmap(Image)
        Dim MaskImage As New Aurigma.GraphicsMill.Bitmap(Image2)
        Dim resultImage As New Aurigma.GraphicsMill.Bitmap(UserImage.Width, UserImage.Height, Aurigma.GraphicsMill.PixelFormat.Format32bppArgb)

        MaskImage.ColorManagement.Convert(PixelFormat.Format8bppGrayScale)

        Dim rf As New RectangleF(0, 0, UserImage.Width, UserImage.Height)
        Using combiner As New Combiner(UserImage, rf, rf, CombineMode.Copy, 1, InterpolationMode.HighSpeed)
            combiner.ApplyMaskTransform(resultImage, MaskImage, BitmapViewerMainView.Bitmap)
        End Using

Edited by user Thursday, January 17, 2008 7:00:44 PM(UTC)  | Reason: Not specified

Alex Kon  
#4 Posted : Wednesday, January 16, 2008 7:41:28 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello Eelse,

Here is another small code sample:

Code:
//
// Loading source image.
// 

Aurigma.GraphicsMill.Bitmap image = 
	new Aurigma.GraphicsMill.Bitmap("x:/allformats/24bppRgb.jpg");

//
// In your case you will load mask from some external source.
// Just for demonstration I'll create it by myself here:
//
Aurigma.GraphicsMill.Bitmap mask = new Aurigma.GraphicsMill.Bitmap(
		image.Width, 
		image.Height, 
		Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);
using (System.Drawing.Graphics g = mask.GetGdiplusGraphics())
	g.FillEllipse(
		System.Drawing.Brushes.White, 
		0, 
		0, 
		mask.Width, 
		mask.Height);

//
// Now we should just add alpha channel and assign mask into it.
// Please note, that mask should have the same dimensions, as image and
// it should be 8bppGrayscale.
//
mask.ColorManagement.Convert(
	Aurigma.GraphicsMill.PixelFormat.Format8bppGrayScale);
image.Channels.AddAlpha(0);
image.Channels[Aurigma.GraphicsMill.ColorChannel.Alpha] = mask;

// Thats all, saving the result.

image.Save("y:/maskedImage.png");

Eelze  
#5 Posted : Thursday, January 17, 2008 4:15:27 PM(UTC)
Eelze

Rank: Newbie

Groups: Member
Joined: 1/15/2008(UTC)
Posts: 4

Both thanks for you reaction.

@undead80. Replacing a color in an alpha-channel is not useable for me, because there is a chance that in the result also transparancy is added inside the elipse.

@alex. With the solution you suggested, the edges (outside the elips) will not become transparent. Do I see that right?
Alex Kon  
#6 Posted : Thursday, January 17, 2008 4:38:30 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello,

Hm... Are you sure? I've checked the result in Adobe Photoshop - it had transparency.

Edited by user Thursday, January 17, 2008 4:39:11 PM(UTC)  | Reason: Not specified

Eelze  
#7 Posted : Thursday, January 17, 2008 6:28:27 PM(UTC)
Eelze

Rank: Newbie

Groups: Member
Joined: 1/15/2008(UTC)
Posts: 4

@Alex

I have tested it, and it works great! When I use an image as mask, it also work fine.

Thanks for your input!

Kind regards,

Eelze
Alex Kon  
#8 Posted : Thursday, January 17, 2008 8:59:14 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
You are welcome! ;)
undead80  
#9 Posted : Friday, January 18, 2008 9:21:42 AM(UTC)
undead80

Rank: Member

Groups: Member
Joined: 1/7/2008(UTC)
Posts: 28

Cool...

But is there any way to check if the photo already having an alpha channel?

As
image.Channels.AddAlpha(0); <- this line will get into error if the image already having an alpha channel.

Please advice.
Alex Kon  
#10 Posted : Friday, January 18, 2008 1:03:48 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Member
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Aurigma.GraphicsMill.Bitmap.HasAlpha?...
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.