473,378 Members | 1,426 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,378 software developers and data experts.

Option Strict and .Save with an Image

The following code works when Option Strict is off:
Dim thumbSize As New Size
thumbSize = CType(NewthumbSize(g.Width, g.Height, 100), System.Drawing.Size)
Dim imgThumbOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
imgThumbOutput.Save(Server.MapPath(ThumbnailPath), thisFormat)

When I turn on Option Strict, I receive the following compile error:
Overload resolution failed because no accessible 'Save' can be called with
these arguments:
'Public Sub Save(stream As System.IO.Stream, format As
System.Drawing.Imaging.ImageFormat)': Value of type 'String' cannot be
converted to 'System.IO.Stream'.
'Public Sub Save(stream As System.IO.Stream, format As
System.Drawing.Imaging.ImageFormat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing.Imaging.ImageFormat'.
'Public Sub Save(filename As String, format As
System.Drawing.Imaging.ImageFormat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing.Imaging.ImageFormat'.

Tried converting the path:
imgThumbOutput.Save(CType(Server.MapPath(Thumbnail Path), System.IO.Stream),
thisFormat)

but it errored because you can't convert a string into a System.IO.Stream.

Is there a way of rewriting this line to work with Option Strict? Thanks.
Nov 21 '05 #1
4 2937
Hi,

I think the problem lies not in your path, but your format. If the
"thisFormat" variable is of type Object you need to cast it to the
System.Drawing.Imaging.ImageFormat type first:

---
imgThumbOutput.Save(Server.MapPath(ThumbnailPath), CType(thisFormat,
System.Drawing.Imaging.ImageFormat))
---

Let us know how you go.
Regards,
-Adam.

jmhmaine wrote:
The following code works when Option Strict is off:
Dim thumbSize As New Size
thumbSize = CType(NewthumbSize(g.Width, g.Height, 100), System.Drawing.Size)
Dim imgThumbOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
imgThumbOutput.Save(Server.MapPath(ThumbnailPath), thisFormat)

When I turn on Option Strict, I receive the following compile error:
Overload resolution failed because no accessible 'Save' can be called with
these arguments:
'Public Sub Save(stream As System.IO.Stream, format As
System.Drawing.Imaging.ImageFormat)': Value of type 'String' cannot be
converted to 'System.IO.Stream'.
'Public Sub Save(stream As System.IO.Stream, format As
System.Drawing.Imaging.ImageFormat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing.Imaging.ImageFormat'.
'Public Sub Save(filename As String, format As
System.Drawing.Imaging.ImageFormat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing.Imaging.ImageFormat'.

Tried converting the path:
imgThumbOutput.Save(CType(Server.MapPath(Thumbnail Path), System.IO.Stream),
thisFormat)

but it errored because you can't convert a string into a System.IO.Stream.

Is there a way of rewriting this line to work with Option Strict? Thanks.

Nov 21 '05 #2
JMHMaine.

The solution in this is mostly to break your instructions (for testing) in
smaller parts.

Than often you see yourself the best where the problem is.

Just an idea.

Cor
Nov 21 '05 #3
"jmhmaine" <jm*@online.nospam> schrieb:
When I turn on Option Strict, I receive the following compile error:
Overload resolution failed because no accessible 'Save' can be called with
these arguments:
'Public Sub Save(stream As System.IO.Stream, format As
System.Drawing.Imaging.ImageFormat)': Value of type 'String' cannot be
converted to 'System.IO.Stream'.
'Public Sub Save(stream As System.IO.Stream, format As
System.Drawing.Imaging.ImageFormat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing.Imaging.ImageFormat'.
'Public Sub Save(filename As String, format As
System.Drawing.Imaging.ImageFormat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing.Imaging.ImageFormat'.


\\\
imgThumbOutput.Save(Server.MapPath(ThumbnailPath), f)
///

should work if 'f' is of type 'ImageFomat'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Thanks, you were right, it was the second argument "thisFormat", not the
first one that was causing the error.

The lines above, which I forgot to include:
Dim g As System.Drawing.Image =
System.Drawing.Image.FromFile(Server.MapPath(Path) )
Dim thisFormat As Object = g.RawFormat

I changed the second line to:
Dim thisFormat As System.Drawing.Imaging.ImageFormat = g.RawFormat

and it worked! Thanks.

Josh.

"Adam Goossens" wrote:
Hi,

I think the problem lies not in your path, but your format. If the
"thisFormat" variable is of type Object you need to cast it to the
System.Drawing.Imaging.ImageFormat type first:

---
imgThumbOutput.Save(Server.MapPath(ThumbnailPath), CType(thisFormat,
System.Drawing.Imaging.ImageFormat))
---

Let us know how you go.
Regards,
-Adam.

jmhmaine wrote:
The following code works when Option Strict is off:
Dim thumbSize As New Size
thumbSize = CType(NewthumbSize(g.Width, g.Height, 100), System.Drawing.Size)
Dim imgThumbOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
imgThumbOutput.Save(Server.MapPath(ThumbnailPath), thisFormat)

When I turn on Option Strict, I receive the following compile error:
Overload resolution failed because no accessible 'Save' can be called with
these arguments:
'Public Sub Save(stream As System.IO.Stream, format As
System.Drawing.Imaging.ImageFormat)': Value of type 'String' cannot be
converted to 'System.IO.Stream'.
'Public Sub Save(stream As System.IO.Stream, format As
System.Drawing.Imaging.ImageFormat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing.Imaging.ImageFormat'.
'Public Sub Save(filename As String, format As
System.Drawing.Imaging.ImageFormat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing.Imaging.ImageFormat'.

Tried converting the path:
imgThumbOutput.Save(CType(Server.MapPath(Thumbnail Path), System.IO.Stream),
thisFormat)

but it errored because you can't convert a string into a System.IO.Stream.

Is there a way of rewriting this line to work with Option Strict? Thanks.

Nov 21 '05 #5

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

Similar topics

9
by: Microsoft News | last post by:
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of errors. My question, should I even care...
11
by: Daylor | last post by:
hi. im using option strict on. im doing in ,from the simple reason ,to be warn when there are implict conversion like string to int ,int to string. BUT. the price ,(now i see ), is very bad....
4
by: KC | last post by:
I'm trying to export data to Excel, and I found an example routine at microsoft, but I get an "Option Strict On disallows late binding." at 'oBook = oExcel.Workbooks.Add'. Without turning Option...
4
by: Piedro | last post by:
Hi group, how do I read a image/blob field in cas option strict is on? First I had it turned off and I read it like this: Dim b() As Byte If Not dsSupp.Tables(0).Rows(0).Item("BITMAP") Is...
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
0
by: Jedawi | last post by:
Hi, would anyone be able to point me in the right direction on how to import an image (.jpg file) into an Excel worksheet using VB.Net and Option Strict On. This should be straight forward...
13
by: C. Moya | last post by:
I fully expected the lack of a way to set Option Strict globally to be fixed in SP1. I can't seem to figure out if it has been fixed or not. It still seems we have to add the declaration at the top...
18
by: Poldie | last post by:
How do I turn it on? I'm using vb 2005 in visual studio 2005 sp1. In my web.config I have: <compilation debug="true" strict="true" /> In my Tools/Options/Projects and solutions/vb defaults...
8
by: Rory Becker | last post by:
A wise man once said: "Never put off until runtime what you can fix at compile time." Actually I think he said it about 10 minutes before I started this post. I am a firm believer, like the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.