Masked image draws very slawly

S

Sharon

Hello Code Gurus,


I'm drawing two layers over a control.
The first bitmap as the background image and then I'm drawing the mask image
which should look like a gray masking with transparent rectangles.

I'm doing so as follow:
////////////////////////////////////////////////////////////
Bitmap m_backgroundBitmap;
Bitmap m_maskBitmap;
ImageAttributes m_attributes = new ImageAttributes();

// Invoked once at application start time.
private void InitMaskedImageAttributes()
{
Single[][] ptsArray = new Single[5][];
for( int i = 0; i < 5; ++i )
{
ptsArray = new Single[5];
for( int j = 0; j < 5; ++j )
{
if( i != j )
{
ptsArray[j] = 0;
}
else
{
if( i == 3 )
{
ptsArray[j] = 128;
}
else
{
ptsArray[j] = 1;
}
}
}
}
ColorMatrix colorMatrix = new ColorMatrix(ptsArray);
m_attributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
}

// Invoked at paint event.
private void Paint(Graphics g)
{
// g is the control Graphics.
// controlRect is the client rectangle of the control to draw on.
// m_backgroundBitmap is the background bitmap.
g.DrawImage(m_backgroundBitmap, controlRect, 0, 0,
m_backgroundBitmap.Width, m_backgroundBitmap.Height, GraphicsUnit.Pixel,
m_attributes);
m_maskBitmap.MakeTransparent(Color.White);
// the m_maskBitmap is a black image with white rectangles.
g.DrawImage(m_maskBitmap, controlRect, 0, 0, m_maskBitmap.Width,
m_maskBitmap.Height, GraphicsUnit.Pixel, m_attributes);
}
/////////////////////////////////////////////////////////////////////////

The trouble is that when drawing the m_maskBitmap it does so very slawly.

Is there a way to make it run at runtime smoothly and faster?
 
S

Sharon

Here is my post again but simpler one:

Hello Code Gurus,

I'm drawing two layers over a control.
The first bitmap as the background image and then I'm drawing the mask image
which should look like a gray masking with transparent rectangles.

I'm doing so as follow:
////////////////////////////////////////////////////////////
Bitmap m_backgroundBitmap;
Bitmap m_maskBitmap;
ImageAttributes m_attributes = new ImageAttributes();

// Invoked once at application start time.
private void InitMaskedImageAttributes()
{
float[][] ptsArray = { new float[] { 1, 0, 0, 0, 0 },
new float[] { 0, 1, 0, 0, 0 },
new float[] { 0, 0, 1, 0, 0 }, new
float[] { 0, 0, 0, 128, 0 }, new float[] {
0, 0, 0, 0, 1 } }; ColorMatrix colorMatrix = new ColorMatrix(ptsArray);
m_attributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
}

// Invoked at paint event.
private void Paint(Graphics g)
{
// g is the control Graphics.
// controlRect is the client rectangle of the control to draw on.
// m_backgroundBitmap is the background bitmap.
g.DrawImage(m_backgroundBitmap, controlRect, 0, 0,
m_backgroundBitmap.Width, m_backgroundBitmap.Height, GraphicsUnit.Pixel,
m_attributes);
m_maskBitmap.MakeTransparent(Color.White);
// The m_maskBitmap is a black image with white rectangles.
g.DrawImage(m_maskBitmap, controlRect, 0, 0, m_maskBitmap.Width,
m_maskBitmap.Height, GraphicsUnit.Pixel, m_attributes);
}
/////////////////////////////////////////////////////////////////////////

The trouble is that when drawing the m_maskBitmap it does so very slawly.

Is there a way to make it run at runtime smoothly and faster?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Graphics Question 4
Image Transparency in ASP.NET 7
A Little Help?? 2

Top