Hello,
m_gMapImg.DrawImage(m_backroundImage, 0, 0) will draw the specified image,
using its original physical size according to it's DPI and screen
resolution.
Here is a note from MSDN:
"The physical width, measured in inches, of an image is the pixel width
divided by the horizontal resolution. For example, an image with a pixel
width of 216 and a horizontal resolution of 72 dots per inch has a physical
width of 3 inches. Similar remarks apply to pixel height and physical
height."
So, if you want to draw image using it's width and height in pixels, you
can:
m_gMapImg.DrawImage(m_backroundImage, 0, 0, m_backroundImage.Width,
m_backroundImage.Height)
--
With best regards,
Andrew
http://www.codeproject.com/script/pr...asp?id=1181072
"Sharon" <(E-Mail Removed)> wrote in message
news:39869334-E24F-4979-8A0F-(E-Mail Removed)...
>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_backroundImage;
> private Bitmap MapImg;
> private PictureBox m_DrawArea;
>
> protected void OnResize(object sender, System.EventArgs e)
> {
> if( m_MapImg != null )
> {
> m_MapImg.Dispose();
> m_gMapImg.Dispose();
> }
> if( m_DrawArea.Width != 0 && m_DrawArea.Height != 0 )
> {
> m_MapImg = new Bitmap(m_DrawArea.Width, m_DrawArea.Height);
> m_gMapImg = Graphics.FromImage(m_MapImg);
> }
> }
>
> protected override void OnPaint(PaintEventArgs e)
> {
> m_gMapImg.Clear(Color.Transparent);
> m_gMapImg.DrawImage(m_backroundImage, 0, 0);
>
> m_DrawArea.Image = m_MapImg;
>
> base.OnPaint(e);
> }
>
> public Bitmap BackImage
> {
> set {
> if( value != null )
> m_backroundImage = new Bitmap(value);
> }
> }
>
> public string BackgroundImagePath
> {
> set {
> if( System.IO.File.Exists(value) )
> BackImage = new Bitmap(value);
> }
> }
>
>
> But as you can see, the 'new Bitmap' is done twice when the
> BackgroundImagePath 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_backroundImage = value;
> }
> }
>
> And now the bitmap file that is given to me by the BackgroundImagePath
> 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 BackgroundImagePath property
> to:
> public string BackgroundImagePath
> {
> set {
> if( System.IO.File.Exists(value) )
> m_backroundImage = new Bitmap(value);
> }
> }
>
> I can't make sense of it.
> Can anybody tell me why or how it acts so strangely?
>
> ---------
> Thanks
> Sharon