473,608 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bitmap to PictureBox control problem

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
Nov 17 '05 #1
2 3014
Hello,

m_gMapImg.DrawI mage(m_backroun dImage, 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.DrawI mage(m_backroun dImage, 0, 0, m_backroundImag e.Width,
m_backroundImag e.Height)

--
With best regards,
Andrew

http://www.codeproject.com/script/pr...asp?id=1181072
"Sharon" <Sh*****@newsgr oups.nospam> wrote in message
news:39******** *************** ***********@mic rosoft.com...
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

Nov 17 '05 #2
Surprisingly for me it works as you said.
Thanks a lot
Sharon
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
1807
by: Jose Michael Meo R. Barrido | last post by:
Hi! Can u please tech me a way to know if the image in the picturebox has changed? what event should i catch the chage?
5
5774
by: Sharon | last post by:
I’m writing a Windows application. In the form I have a Panel and inside the panel I have a PictureBox control. I’m loading the PictureBox control with BMP image that has the following criteria: 14174 x 7874 Pixels (111.61MPixels), 1 BitsPerPixel, 3200x3200 DPI, No Compression. The memory consumption for loading this image should be 13.31 MB (13,952,776 Bytes) (this is what IrfanView takes, http://www.irfanview.com/). I’m loading...
2
2428
by: David Ricker | last post by:
I have created a PictureBox control which can have it's Image property directly bound to an image field in a database. This works perfectly for showing the images that are in the database. When I paste a new image into my control, it shows the new image and updates the image property. Problem is... It doesn't update the bound field! Any thoughts as to what I've done wrong? Any help would be greatly appreciated. The code for the...
3
3933
by: Tyson Ackland | last post by:
Can someone tell me how you go about handling events where your window might be obscured and then when you bring it to the foreground, you want your picturebox control to be repainted instead of showing large, blocked out areas created by overlapping windows. I have seen numerous references to onpaint etc but I haven't found an example to follow or at least my own efforts with onpaint haven't been fruitful as yet.
5
4892
by: BrianW | last post by:
I am working on a program that has multiple picturebox controls that a user is allowed to move around which are contained within a panel control for visual placement. In my mousedown event, I set the picturebox control's borderstyle to Fixed3D, but upon doing so, I am not able to track the picturebox control through mousemove events (if you move the mouse off of the control too quickly, the control no longer receives mouse events). If I...
3
2013
by: ktcute | last post by:
I'm trying to write a simple drawing tool that saves images out as jpgs. I've been using the paint event on the Panel control to draw the objects, however I couldn't get the same drawing functionality when I switched to use a Picturebox control. I found that after all the objects had been painted on the control, they "disappeared". I'm wondering if this is deliberate, and if someone can suggest another way I can go about saving my...
14
9903
by: GSSI | last post by:
I have an image data field in a datarow (as in the Northwinds demo sql database). What is the C# instruction syntax to display it in a Winform picturebox control. -- GSSI
3
12348
by: prynhart | last post by:
I have a PictureBox Control which is 96*96 pixels. I want to display nine 32*32 pixel bitmaps in this control arranged in a 3X3 square. How can I do this ? All the examples I've seen load only one image in the PictureBox. The code: board.ClientSize = new Size(96, 96); board.Image = (Image)image1;
10
2234
Samishii23
by: Samishii23 | last post by:
Ok so, I'm trying to make an .exe version of a World of Warcraft system. The Talent builder. I'm hoping that no one points and laughs too much... But anyways, this is the problem I'm having... Theres 11 tiers of my PictureBox Control, 44 total. The 1st tier is "Free" while each subsequent tier needs 5 points into the previous tier to make the next tier available. Right now I have the intentions of putting this code into a TextChanged()...
0
8063
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8003
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8498
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1331
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.