473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Displaying image

Hi

I am trying to display an image in a dialog using the following code;

Dim frm As New frmImage
Dim z As System.Drawing.Bitmap

z.FromFile("c:\temp\image.gif")
frm.picImage.Image = z
frm.ShowDialog()
frm.Dispose()

Trouble is that no image appears in the dialog. What am I doing wrong?

Thanks

Regards
Nov 20 '05 #1
18 1826
PS: picImage is a PictureBox.

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
Hi

I am trying to display an image in a dialog using the following code;

Dim frm As New frmImage
Dim z As System.Drawing.Bitmap

z.FromFile("c:\temp\image.gif")
frm.picImage.Image = z
frm.ShowDialog()
frm.Dispose()

Trouble is that no image appears in the dialog. What am I doing wrong?

Thanks

Regards

Nov 20 '05 #2
"John" <jo**@nospam.infovis.co.uk> wrote in news:OxEaex3kDHA.1284
@TK2MSFTNGP09.phx.gbl:
I am trying to display an image in a dialog using the following code;

Dim frm As New frmImage
Dim z As System.Drawing.Bitmap

z.FromFile("c:\temp\image.gif")
frm.picImage.Image = z
frm.ShowDialog()
frm.Dispose()

Trouble is that no image appears in the dialog. What am I doing wrong?


I presume from the fact that you aren't indicating that the compiler is
failing that you really mean

z = Image.FromFile("c:\temp\image.gif");

but there is another error. I think you are having a problem with your
backslashes in the filename... In general, you should always check a
variable before you use it. I would put money of the supposition that 'z'
is null after the call to FromFile(). To FIX the problem replace the line
with either:

z = Image.FromFile(@"c:\temp\image.gif");

(the @ tells the compiler not to interpret the '\' characters), OR

z = Image.FromFile("c:\\temp\\image.gif");

-mbray
Nov 20 '05 #3
Evening John,

Put a breakpoint on the Image = z line and check the value of z. You'll
find that it's Nothing.

z.FromFile() is calling a <shared> method. It's the same as calling
Bitmap.FromFile(..). In other words it doesn't (can't) change z.

What you need is either:
Dim z As System.Drawing.Bitmap
z = Bitmap.FromFile("c:\temp\image.gif")
or simply
Dim z As New System.Drawing.Bitmap ("c:\temp\image.gif")

Regards,
Fergus
Nov 20 '05 #4
Howdy Michael,

It's in VB so the syntax is fine, but it's true that the result should be
assigned to z.

Regards,
Fergus
Nov 20 '05 #5
"Fergus Cooney" <fi******@tesco.net> wrote in
news:u7**************@TK2MSFTNGP09.phx.gbl:
It's in VB so the syntax is fine, but it's true that the result
should be
assigned to z.


Yeah I realized that and knocked on my head a few times after I saw your
original reply. This is why I think we should just get rid of VB
altogether. *ducks* (just kidding, of course.)

-mbray
Nov 20 '05 #6
Hi Michael,

ROFL. Many a serious word spoken in jest.

Presumably you're from a framework group, so welcome to this glimpse of
languages.vb. ;-)

Regards,
Fergus
Nov 20 '05 #7
Thanks. That worked.

Anyway to zoom the image if it is too big to fit in picturebox's current
size? Ideally I would like a zoom level that a user can set, otherwise
whatever is possible.

Thanks

Regards
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:eh**************@tk2msftngp13.phx.gbl...
Evening John,

Put a breakpoint on the Image = z line and check the value of z. You'll find that it's Nothing.

z.FromFile() is calling a <shared> method. It's the same as calling
Bitmap.FromFile(..). In other words it doesn't (can't) change z.

What you need is either:
Dim z As System.Drawing.Bitmap
z = Bitmap.FromFile("c:\temp\image.gif")
or simply
Dim z As New System.Drawing.Bitmap ("c:\temp\image.gif")

Regards,
Fergus

Nov 20 '05 #8
* "John" <jo**@nospam.infovis.co.uk> scripsit:
PS: picImage is a PictureBox.


Problem solved?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
* "John" <jo**@nospam.infovis.co.uk> scripsit:
I am trying to display an image in a dialog using the following code;

Dim frm As New frmImage
Dim z As System.Drawing.Bitmap

z.FromFile("c:\temp\image.gif")


Use this instead: 'z = Image.FromFile(...)'

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #10
* "John" <jo**@nospam.infovis.co.uk> scripsit:
Anyway to zoom the image if it is too big to fit in picturebox's current
size? Ideally I would like a zoom level that a user can set, otherwise
whatever is possible.


\\\
Dim bmp As New Bitmap( _
"C:\Lagoon1024x768.bmp" _
)
Dim bmp2 As New Bitmap( _
bmp.Width * 0.1, _
bmp.Height * 0.1, _
Imaging.PixelFormat.Format24bppRgb _
)
Dim g As Graphics = Graphics.FromImage(bmp2)

' Select/change interpolation mode here.
g.InterpolationMode = _
Drawing.Drawing2D.InterpolationMode.HighQualityBic ubic

' Draw image using specified interpolation mode.
g.DrawImage(bmp, 0, 0, bmp2.Width, bmp2.Height)
g.Dispose()

Me.PictureBox1.Image = bmp2
bmp2.Save("C:\foo.bmp")
..
..
..
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #11
* Michael Bray <mb*******************@SkPiAlMl.ctiusa.com> scripsit:
z = Image.FromFile("c:\temp\image.gif");

but there is another error. I think you are having a problem with your
backslashes in the filename... In general, you should always check a
variable before you use it. I would put money of the supposition that 'z'
is null after the call to FromFile(). To FIX the problem replace the line
with either:

z = Image.FromFile(@"c:\temp\image.gif");


Not in VB.NET... We don't need the '@' prefix.

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #12
Michael: This means war. You'd better duck, or Me and Herfried will hunt you
down.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:um**************@tk2msftngp13.phx.gbl...
Hi Michael,

ROFL. Many a serious word spoken in jest.

Presumably you're from a framework group, so welcome to this glimpse of languages.vb. ;-)

Regards,
Fergus

Nov 20 '05 #13
* "Tom Spink" <th**********@ntlworld.com> scripsit:
Michael: This means war. You'd better duck, or Me and Herfried will hunt you
down.


VB.NET rules.

;-)))

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #14
These functions may be useful if you're still having trouble.

'VB.NET

Private Function ImageFromAbsolutePath(ByVal absolutePath As String) As
System.Drawing.Bitmap
Dim img As System.Drawing.Bitmap = New
System.Drawing.Bitmap(absolutePath)
Return img
End Function

Private Function ImageFromRelativePath(ByVal relativePath As String) As
System.Drawing.Bitmap
Dim executingPath As String =
System.IO.Path.GetDirectoryName(System.Reflection. Assembly.GetExecutingAssem
bly.Location)
Dim img As System.Drawing.Bitmap = New
System.Drawing.Bitmap(String.Concat(executingPath, "/", relativePath))
Return img
End Function

Private Function ImageFromEmbedded(ByVal embeddedPath As String) As
System.Drawing.Bitmap
Dim imageStream As System.IO.Stream =
System.Reflection.Assembly.GetExecutingAssembly.Ge tManifestResourceStream(em
beddedPath)
Dim img As System.Drawing.Bitmap = New
System.Drawing.Bitmap(imageStream)
Return img
End Function
//C#
private System.Drawing.Bitmap ImageFromAbsolutePath(string absolutePath)
{
System.Drawing.Bitmap img = new System.Drawing.Bitmap(absolutePath);
return img;
}

private System.Drawing.Bitmap ImageFromRelativePath(string relativePath)
{
string executingPath =
System.IO.Path.GetDirectoryName(System.Reflection. Assembly.GetExecutingAssem
bly().Location);
System.Drawing.Bitmap img = new
System.Drawing.Bitmap(string.Concat(executingPath, "/", relativePath));
return img;
}

private System.Drawing.Bitmap ImageFromEmbedded(string embeddedPath) {
System.IO.Stream imageStream =
System.Reflection.Assembly.GetExecutingAssembly(). GetManifestResourceStream(
embeddedPath);
System.Drawing.Bitmap img = new System.Drawing.Bitmap(imageStream);
return img;
}
}

--
Justin Weinberg

Designing a PrintDocument? Drawing to forms?
Check out GDI+ Architect at www.mrgsoft.com
"John" <jo**@nospam.infovis.co.uk> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
Hi

I am trying to display an image in a dialog using the following code;

Dim frm As New frmImage
Dim z As System.Drawing.Bitmap

z.FromFile("c:\temp\image.gif")
frm.picImage.Image = z
frm.ShowDialog()
frm.Dispose()

Trouble is that no image appears in the dialog. What am I doing wrong?

Thanks

Regards

Nov 20 '05 #15
Definitely. Thanks. Now I am trying to zoom/scale the image, when it is too
large to fit in the control/form.

Thanks

Regards
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bm************@ID-208219.news.uni-berlin.de...
* "John" <jo**@nospam.infovis.co.uk> scripsit:
PS: picImage is a PictureBox.


Problem solved?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #16
Thanks. I will try this.

Regards
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bm************@ID-208219.news.uni-berlin.de...
* "John" <jo**@nospam.infovis.co.uk> scripsit:
Anyway to zoom the image if it is too big to fit in picturebox's current
size? Ideally I would like a zoom level that a user can set, otherwise
whatever is possible.


\\\
Dim bmp As New Bitmap( _
"C:\Lagoon1024x768.bmp" _
)
Dim bmp2 As New Bitmap( _
bmp.Width * 0.1, _
bmp.Height * 0.1, _
Imaging.PixelFormat.Format24bppRgb _
)
Dim g As Graphics = Graphics.FromImage(bmp2)

' Select/change interpolation mode here.
g.InterpolationMode = _
Drawing.Drawing2D.InterpolationMode.HighQualityBic ubic

' Draw image using specified interpolation mode.
g.DrawImage(bmp, 0, 0, bmp2.Width, bmp2.Height)
g.Dispose()

Me.PictureBox1.Image = bmp2
bmp2.Save("C:\foo.bmp")
.
.
.
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #17
The GDI+ FAQ has an article on displaying images in a given rectangle while
maintaining the aspect ratio of the original.

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Blog http://bobpowelldotnet.blogspot.com

"John" <jo**@nospam.infovis.co.uk> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Definitely. Thanks. Now I am trying to zoom/scale the image, when it is too large to fit in the control/form.

Thanks

Regards
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bm************@ID-208219.news.uni-berlin.de...
* "John" <jo**@nospam.infovis.co.uk> scripsit:
PS: picImage is a PictureBox.


Problem solved?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>


Nov 20 '05 #18
Howdy Bob,

I've been a-browsing over the last few days- nice site you've got - lots
of goodies. ;-)

Regards,
Fergus
Nov 20 '05 #19

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

Similar topics

4
by: Gregory | last post by:
Hello, I've managed to build two web pages, one that can display images with associated text data in a table, and one that can resize and display images without the text. I'd like to resize the...
3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
2
by: marvin | last post by:
Hi, I am trying to display images in a repeater from a SQL database and do some transformations on the image prior to displaying them (such as thumbnail with a shadow). The problem is I can't...
3
by: CD | last post by:
An application is logging faxes sent in SQL2000 image column type. I have found code on the net but what it is doing is prompting to save to local which is fine for single page image. Not good...
5
by: ljuljacka | last post by:
I'm trying to display resized images. Locations of images are fetched from database. The problem is that with the following code, I get only the first image displayed: <?php...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
4
by: shahidrasul | last post by:
i display a pic on picture box and then i want to display another pic after some seconds but problem is that first image is not displaying only display 2nd image 1... display first picture from...
6
by: Jeff | last post by:
hi asp.net 2.0 I have a image (.jpeg) stored in sql server 2005 and now I want to display it on a webpage. So I created a webpage (Image.aspx) which just writes the buffer data to the...
3
by: mvijayrkumar | last post by:
Hi to all.... Guys pls help me..... I have an image issue in RLDC while hosting my project on server.The image displays or works fine with the local system.But when hosted on server,both the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.