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

Notification

Icon
Error

Options
Go to last post Go to first unread
jneyens  
#1 Posted : Thursday, July 12, 2007 9:00:55 PM(UTC)
jneyens

Rank: Member

Groups: Member
Joined: 7/12/2007(UTC)
Posts: 8

Thanks: 2 times
For Microsoft Belgium we need to develop an application that enables users to upload an image of their selves and cut their head so that it can mapped on other pictures. We will develop a Flash application to highlight the path around the head but need a server component to cut it out. Can this be done with Graphics Mill for .NET?

[Image was removed]

Edited by user Friday, December 18, 2009 8:33:57 PM(UTC)  | Reason: Not specified

Alex Kon  
#2 Posted : Friday, July 13, 2007 3:00:29 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,

Yes, this operation is easy to implement with Graphics Mill for .NET. You should draw Bezier curve entered by user with white color on the black 8bppGrayscale bitmap and assign it as alpha channel to the image. Optionally you may crop image to cut off transparent area around the face. However it depends on your further processing.
KClaes  
#3 Posted : Thursday, July 19, 2007 3:23:23 PM(UTC)
KClaes

Rank: Member

Groups: Member
Joined: 7/18/2007(UTC)
Posts: 3

Alex,

Yesterday I was trying to test the approach you suggested. Instead of beginning with a bezier curve, I thought it would be easier to just use a 8bit grayscale bitmap as the alpha channel.

Code:
Aurigma.GraphicsMill.Bitmap bmpSource = new Aurigma.GraphicsMill.Bitmap(Server.MapPath("/input.jpg"));
Aurigma.GraphicsMill.Bitmap bmpMask = new Aurigma.GraphicsMill.Bitmap(Server.MapPath("/mask.bmp"));


Unfortunately, that's as far as I got :)

I browsed through the documentation, but I was unable to find anything related to assingen a bitmap as the alphachannel of another bitmap.

Can you give some more information on how to achieve that?

Below are the images I used. The left one is "input.jpg" and the right one is "mask.bmp":
UserPostedImage UserPostedImage

Edited by user Monday, December 17, 2007 7:40:40 PM(UTC)  | Reason: Not specified

Alex Kon  
#4 Posted : Thursday, July 19, 2007 9:01:19 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,

Oh, of course! Here is small code sample which should help you. Feel free to contact us in case of any problems with GraphicsMill for .NET.
Code:
	Aurigma.GraphicsMill.Bitmap input = new Aurigma.GraphicsMill.Bitmap("x:/input.jpg");
	Aurigma.GraphicsMill.Bitmap mask = new Aurigma.GraphicsMill.Bitmap("x:/mask.bmp");

	//Mask should be 8bppGrayscale bitmap, so we have to convert to this format. 
	mask.ColorManagement.Convert(Aurigma.GraphicsMill.PixelFormat.Format8bppGrayScale);			

	//Loaded input image has no alpha channel, so we should add it manually.
	input.Channels.AddAlpha(0);

	//That's the main string in this sample :)
	input.Channels[Aurigma.GraphicsMill.ColorChannel.Alpha] = mask;

	//Save the result - 32bppArgb image with specified mask.
	input.Save("x:/result.png");

Edited by user Monday, December 17, 2007 7:37:51 PM(UTC)  | Reason: Not specified

KClaes  
#5 Posted : Thursday, July 19, 2007 11:11:11 PM(UTC)
KClaes

Rank: Member

Groups: Member
Joined: 7/18/2007(UTC)
Posts: 3

Hello Alex,

Thanks for the help.

This is the code I now have:
Code:

Aurigma.GraphicsMill.Bitmap bmpSource = new Aurigma.GraphicsMill.Bitmap(Server.MapPath("/input.jpg"));
Aurigma.GraphicsMill.Bitmap bmpMask = new Aurigma.GraphicsMill.Bitmap(Server.MapPath("/mask.bmp"));
	
bmpMask.ColorManagement.Convert(Aurigma.GraphicsMill.PixelFormat.Format8bppGrayScale);
		
bmpSource.Channels.AddAlpha(0);
bmpSource.Channels[Aurigma.GraphicsMill.ColorChannel.Alpha] = bmpMask;

bmpSource.Save(Server.MapPath("/result.png"), new AGM.Codecs.PngEncoderOptions());


The result.png is identical to the input.jpg. Apparently no mask is applied or saved. Am I missing something?

Kind regards,
Kristof

Edited by user Monday, December 17, 2007 7:40:18 PM(UTC)  | Reason: Not specified

Alex Kon  
#6 Posted : Friday, July 20, 2007 1:59:44 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 Kristof,

Which viewer do you use to check result.png? Maybe it just doesn't display image transparency? Try to open the result file in Adobe Photoshop or Windows Picture and Fax Viewer.

I don't know what you intend to do with the masked image, but I suppose that it should be something like this (where input is the Aurigma.GraphicsMill.Bitmap object from the previous code snippet):
Code:
	Aurigma.GraphicsMill.Bitmap mergedImage = new Aurigma.GraphicsMill.Bitmap("x:/faceBackground.jpg");
	input.Draw(mergedImage, 
		0, 
		0, 
		input.Width, 
		input.Height, 
		Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 
		1.0f, 
		Aurigma.GraphicsMill.Transforms.InterpolationMode.HighSpeed);

	mergedImage.Save("x:/merged.png");

Edited by user Monday, December 17, 2007 7:39:52 PM(UTC)  | Reason: Not specified

KClaes  
#7 Posted : Monday, July 23, 2007 3:32:20 PM(UTC)
KClaes

Rank: Member

Groups: Member
Joined: 7/18/2007(UTC)
Posts: 3

Hello Alex,

You were right! I was using Irfanview to display the created image. When I open it in Firework, I can see the transparency. Everything seems to be working ok.

Thanks a lot for your help!

Kind regards,
Kristof
Users browsing this topic
Guest
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.