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

Notification

Icon
Error

Options
Go to last post Go to first unread
ChingYen  
#1 Posted : Tuesday, May 10, 2011 6:54:21 AM(UTC)
ChingYen

Rank: Advanced Member

Groups: Member
Joined: 3/3/2008(UTC)
Posts: 185

Thanks: 8 times
Hi,

we are using the suggested masking method as below to increase the speed for masking. It works well until when the originalImage also having alpha channel. Example, the we set the opacity of the original image by
Code:
originalImage.Channels.AddAlpha((float)50 / 100);
, the result given by the ApplyMask will remove the 50% opacity and make it "solid".

Kindly advise how can we solve this? Thanks.


Code:

        private Aurigma.GraphicsMill.Bitmap ApplyMask(Aurigma.GraphicsMill.Bitmap originalImage, Aurigma.GraphicsMill.Bitmap maskImage)
        {
            Aurigma.GraphicsMill.Bitmap amResult = new Aurigma.GraphicsMill.Bitmap(originalImage.Width, originalImage.Height, PixelFormat.Format32bppArgb);

            if (originalImage.Width == maskImage.Width && originalImage.Height == maskImage.Height)
            {
                if (originalImage.PixelFormat != PixelFormat.Format32bppArgb)
                {
                    originalImage.ColorManagement.Convert(PixelFormat.Format32bppArgb);
                }

                if (maskImage.PixelFormat != PixelFormat.Format8bppGrayScale)
                {
                    maskImage.ColorManagement.Convert(PixelFormat.Format8bppGrayScale);
                }

                Aurigma.GraphicsMill.BitmapData amImageData = originalImage.LockBits();
                Aurigma.GraphicsMill.BitmapData amMaskData = maskImage.LockBits();
                Aurigma.GraphicsMill.BitmapData amResultData = amResult.LockBits();

                Byte[] amSrcScan = new byte[amImageData.Stride];
                Byte[] amDstScan = new byte[amResultData.Stride];
                Byte[] amMaskScan = new byte[amMaskData.Stride];

                try
                {
                    for (int i = 0; i <= amResultData.Height - 1; i=i+1)
                    {
                        Marshal.Copy(new IntPtr(amImageData.Scan0.ToInt32() + i * amImageData.Stride), amSrcScan, 0, amImageData.Stride);
                        Marshal.Copy(new IntPtr(amResultData.Scan0.ToInt32() + i * amResultData.Stride), amDstScan, 0, amResultData.Stride);
                        Marshal.Copy(new IntPtr(amMaskData.Scan0.ToInt32() + i * amMaskData.Stride), amMaskScan, 0, amMaskData.Stride);

                        int amSrcChannelIndex = 0;
                        int amDstChannelIndex = 0;

                        for (int j = 0; j <= amResultData.Width - 1; j = j + 1)
                        {
                            amDstScan[amDstChannelIndex] = amSrcScan[amSrcChannelIndex];
                            amDstChannelIndex += 1;
                            amSrcChannelIndex += 1;
                            amDstScan[amDstChannelIndex] = amSrcScan[amSrcChannelIndex];
                            amDstChannelIndex += 1;
                            amSrcChannelIndex += 1;
                            amDstScan[amDstChannelIndex] = amSrcScan[amSrcChannelIndex];
                            amDstChannelIndex += 1;
                            amSrcChannelIndex += 1;
                            amDstScan[amDstChannelIndex] = amMaskScan[j];
                            amDstChannelIndex += 1;

                        }
                        Marshal.Copy(amDstScan, 0, new IntPtr(amResultData.Scan0.ToInt32() + i * amResultData.Stride), amResultData.Stride);

                    }
                }
                catch
                {
                }
                finally
                {
                    amResult.UnlockBits(amResultData);
                    originalImage.UnlockBits(amImageData);
                    maskImage.UnlockBits(amMaskData);

                }           

            }

            return amResult;
        }
Dmitry.Obukhov  
#2 Posted : Friday, May 13, 2011 2:22:38 AM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups: Member
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello Ching-Yen,

Could you please let me know what you want to get at the end?
Best regards,
Dmitry Obukhov
Technical Support. Aurigma, Inc.
Dmitry.Obukhov  
#3 Posted : Friday, May 13, 2011 2:22:39 AM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups: Member
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello Ching-Yen,

Could you please let me know what you want to get at the end?
Best regards,
Dmitry Obukhov
Technical Support. Aurigma, Inc.
ChingYen  
#4 Posted : Friday, May 13, 2011 4:33:17 PM(UTC)
ChingYen

Rank: Advanced Member

Groups: Member
Joined: 3/3/2008(UTC)
Posts: 185

Thanks: 8 times
Dmitry.Obukhov wrote:
Hello Ching-Yen,

Could you please let me know what you want to get at the end? [/quote

The step we would like to do
1. Change the photo opacity
2. Masking it
Final Result: get a Masked image with different opacity.
Alex Kon  
#5 Posted : Friday, May 20, 2011 3:15:46 AM(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 ChingYen,

When you call AddAlpha(0.5) - you get image with 0.5 in alpha channel. So, you just shouldn't overwrite this value on the second step.

Here is the part of you code which applies mask with my comments:
Code:
for (int j = 0; j <= amResultData.Width - 1; j = j + 1)
{
	// Blue channel
	amDstScan[amDstChannelIndex] = amSrcScan[amSrcChannelIndex];
	amDstChannelIndex += 1;
	amSrcChannelIndex += 1;
	// Green channel
	amDstScan[amDstChannelIndex] = amSrcScan[amSrcChannelIndex];
	amDstChannelIndex += 1;
	amSrcChannelIndex += 1;
	// Red channel
	amDstScan[amDstChannelIndex] = amSrcScan[amSrcChannelIndex];
	amDstChannelIndex += 1;
	amSrcChannelIndex += 1;
	// Alpha! Don't simply overwrite your alpha with new value. 
	// For example, you can use multiplication:
	// was:
	//amDstScan[amDstChannelIndex] = amMaskScan[j];
	// new:
	amDstScan[amDstChannelIndex] = (byte)((int)amSrcScan[amSrcChannelIndex] * amMaskScan[j] / 255);
	amDstChannelIndex += 1;
	amSrcChannelIndex += 1;
}
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.