This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Watermark Image

Hi,

I way trying to change the opacity of one bitmap by using the following code

Dim image as New Aurigma.GrphicMaill.Bitmap("C:\mypic.jpg")
Dim TransBitmap As New Aurigma.GraphicsMill.Bitmap(image.Width, image.Height, Aurigma.GraphicsMill.PixelFormat.Format32bppArgb)

image.Draw(TransBitmap, 0, 0, image.Width, image.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 0.3F, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality)

What I would like to do is load this semi transparent image into VObject so that it could be use in the multilayer viewer.

but seems like it doesn't work. Anyone could help out with this please?

Thanks.
Hi,

Current implementation of the Graphics Mill for .NET doesn't change alpha channel of the destination bitmap, so you cannot perform this with Bitmap.Draw(...) method.

But! 😉 If you are loading image without alpha channel and want to create partially-transparent image you can do this that way:

Dim image As New Aurigma.GraphicsMill.Bitmap("x:\allformats\24bppRgb.jpg")
image.Channels.AddAlpha(0.7)

Alex Kon
Hi,

Current implementation of the Graphics Mill for .NET doesn't change alpha channel of the destination bitmap, so you cannot perform this with Bitmap.Draw(...) method.

But! 😉 If you are loading image without alpha channel and want to create partially-transparent image you can do this that way:

Dim image As New Aurigma.GraphicsMill.Bitmap("x:\allformats\24bppRgb.jpg")
image.Channels.AddAlpha(0.7)



Cool..
But is there any way to detect the Alpha Value from a bitmap? Please advice.

Regards
Hello,

What do you mean by phrase "detect the Alpha Value"? If you want to determine whether bitmap has alpha channel or not - you may use Bitmap.HasAlpha property. Or you mean something else?

Alex Kon
Hello,

What do you mean by phrase "detect the Alpha Value"? If you want to determine whether bitmap has alpha channel or not - you may use Bitmap.HasAlpha property. Or you mean something else?



What I want to know is the value we set for the Alpha (example 0.7F)
Hello,

You can read any bitmap's pixel color and check the alpha value. Of course, if you sure that alphas of all pixels are the same (e.g. if you set it by Bitmap.Channels.AddAlpha(...) call).

You can use Bitmap.GetPixel(...) method to read color value.


Alex Kon
Hello,

You can read any bitmap's pixel color and check the alpha value. Of course, if you sure that alphas of all pixels are the same (e.g. if you set it by Bitmap.Channels.AddAlpha(...) call).

You can use Bitmap.GetPixel(...) method to read color value.




Hi,

Thanks....
But, for unknown reason, the getPixel only work once

Public Function getAlphaValue(ByVal backgroundImage As Aurigma.GraphicsMill.Bitmap) As Double
Dim _color As System.Drawing.Color
Dim dblRet As Double = 1
Dim myBitmap As Aurigma.GraphicsMill.Bitmap

Try
myBitmap = CType(backgroundImage, Aurigma.GraphicsMill.Bitmap)
_color = myBitmap.GetPixel(10, 10)
dblRet = _color.A / 255
Catch ex As Exception

Finally
dblRet = dblRet * 100
End Try

Return dblRet

End Function

I had a function as above, while, the backgroundImage will be called from a VObject.tag

It works fine while I am working on it. While I save the file (serialized the .tag, and deserialized the bitmap back to the vobject.tag)
then @ this line
_color = myBitmap.GetPixel(10, 10)
I will get the err.Description of
"Object reference not set to an instance of an object."

Please advice.
Hello,

We confirm the issue with Bitmap.GetPixel() method after object's deserialization. If this is critical for you, please submit case.
beside getPixel, is there any alternative way to get the Alpha Value of the image?

Please advice.
Hello,

Yeap, here is workaround code:

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

image.Channels.AddAlpha(0.5f);

Aurigma.GraphicsMill.BitmapData imageData = image.LockBits(0, 0, 1, 1);
try
{
	Aurigma.GraphicsMill.RgbColor pixColor = 
		(Aurigma.GraphicsMill.RgbColor)imageData.GetPixel(0, 0);
	
	System.Windows.Forms.MessageBox.Show(pixColor.ToString());
}
finally
{
	image.UnlockBits(imageData);
}
Alex Kon
Hello,

Yeap, here is workaround code:

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

image.Channels.AddAlpha(0.5f);

Aurigma.GraphicsMill.BitmapData imageData = image.LockBits(0, 0, 1, 1);
try
{
	Aurigma.GraphicsMill.RgbColor pixColor = 
		(Aurigma.GraphicsMill.RgbColor)imageData.GetPixel(0, 0);
	
	System.Windows.Forms.MessageBox.Show(pixColor.ToString());
}
finally
{
	image.UnlockBits(imageData);
}


Hi,

Seems like the issue is still there. It will still goes into same error message on
Aurigma.GraphicsMill.RgbColor pixColor =
(Aurigma.GraphicsMill.RgbColor)imageData.GetPixel(0, 0);
Hello,

Its very strange! Which version of Graphics Mill for .NET do you use? Here is full code of my test application:

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

image.Channels.AddAlpha(0.5f);

//Serialization
System.IO.FileStream fs = 
	new System.IO.FileStream("y:/data.dat", System.IO.FileMode.Create);
image.Serialize(fs);
image.Dispose();

//Deserialization
image = new Aurigma.GraphicsMill.Bitmap();
fs = new System.IO.FileStream("y:/data.dat", System.IO.FileMode.Open);
image.Deserialize(fs);
fs.Close();

//Now this code throws NullReference exception 
//System.Windows.Forms.MessageBox.Show(image.GetPixel(10, 10).ToString());

Aurigma.GraphicsMill.BitmapData imageData = image.LockBits(10, 10, 1, 1);
try
{
	//And this code works correctly on my machine 
	//with 4.1.11, 4.5.16 and 4.5.17 versions
	Aurigma.GraphicsMill.RgbColor pixColor =
		  (Aurigma.GraphicsMill.RgbColor)imageData.GetPixel(0, 0);

	System.Windows.Forms.MessageBox.Show(pixColor.ToString());
}
finally
{
	image.UnlockBits(imageData);
}


Could you test this sample and let me know whether the issue can be reproduced on your machine?

    Public Function getAlphaValue(ByVal backgroundImage As Aurigma.GraphicsMill.Bitmap) As Double
        Dim _color As System.Drawing.Color
        Dim dblRet As Double = 1
        'Dim myBitmap As Aurigma.GraphicsMill.Bitmap
        Dim imageData As Aurigma.GraphicsMill.BitmapData = backgroundImage.LockBits(0, 0, 1, 1)
        Try
            _color = backgroundImage.GetPixel(0, 0)
            dblRet = _color.A / 255
        Catch ex As Exception

        Finally
            backgroundImage.UnlockBits(imageData)
            dblRet = dblRet * 100
        End Try

        Return dblRet

    End Function
Hello,

You should call GetPixel(...) method of the Aurigma.GraphicsMill.BitmapData class, not Aurigma.GraphicsMill.Bitmap one. Please, look at the code sample I've posted above.