I encountered a strange behavior when doing ‘new Bitmap’:
The following code works fine and the given bitmap file is shown on the
PictureBox (the m_DrawArea) in the correct bitmap sizes:
private Graphics m_gMapImg;
private Bitmap m_backroundImag e;
private Bitmap MapImg;
private PictureBox m_DrawArea;
protected void OnResize(object sender, System.EventArg s e)
{
if( m_MapImg != null )
{
m_MapImg.Dispos e();
m_gMapImg.Dispo se();
}
if( m_DrawArea.Widt h != 0 && m_DrawArea.Heig ht != 0 )
{
m_MapImg = new Bitmap(m_DrawAr ea.Width, m_DrawArea.Heig ht);
m_gMapImg = Graphics.FromIm age(m_MapImg);
}
}
protected override void OnPaint(PaintEv entArgs e)
{
m_gMapImg.Clear (Color.Transpar ent);
m_gMapImg.DrawI mage(m_backroun dImage, 0, 0);
m_DrawArea.Imag e = m_MapImg;
base.OnPaint(e) ;
}
public Bitmap BackImage
{
set {
if( value != null )
m_backroundImag e = new Bitmap(value);
}
}
public string BackgroundImage Path
{
set {
if( System.IO.File. Exists(value) )
BackImage = new Bitmap(value);
}
}
But as you can see, the ‘new Bitmap’ is done twice when the
BackgroundImage Path property is called. And the BackImage property is
creating a new bitmap out of the given bitmap.
So I changed the code of the BackImage to:
public Bitmap BackImage
{
set {
if( value != null )
m_backroundImag e = value;
}
}
And now the bitmap file that is given to me by the BackgroundImage Path
property is shown on the PictureBox (the DrawArea) control as a thumbnail and
not in his original size.
The same problem occurs if only change the BackgroundImage Path property to:
public string BackgroundImage Path
{
set {
if( System.IO.File. Exists(value) )
m_backroundImag e = new Bitmap(value);
}
}
I can’t make sense of it.
Can anybody tell me why or how it acts so strangely?
---------
Thanks
Sharon