473,796 Members | 2,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Option Strict and .Save with an Image

The following code works when Option Strict is off:
Dim thumbSize As New Size
thumbSize = CType(NewthumbS ize(g.Width, g.Height, 100), System.Drawing. Size)
Dim imgThumbOutput As New Bitmap(g, thumbSize.Width , thumbSize.Heigh t)
imgThumbOutput. Save(Server.Map Path(ThumbnailP ath), 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.Strea m, format As
System.Drawing. Imaging.ImageFo rmat)': Value of type 'String' cannot be
converted to 'System.IO.Stre am'.
'Public Sub Save(stream As System.IO.Strea m, format As
System.Drawing. Imaging.ImageFo rmat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing .Imaging.ImageF ormat'.
'Public Sub Save(filename As String, format As
System.Drawing. Imaging.ImageFo rmat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing .Imaging.ImageF ormat'.

Tried converting the path:
imgThumbOutput. Save(CType(Serv er.MapPath(Thum bnailPath), System.IO.Strea m),
thisFormat)

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

Is there a way of rewriting this line to work with Option Strict? Thanks.
Nov 21 '05 #1
4 2963
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.ImageFo rmat type first:

---
imgThumbOutput. Save(Server.Map Path(ThumbnailP ath), CType(thisForma t,
System.Drawing. Imaging.ImageFo rmat))
---

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(NewthumbS ize(g.Width, g.Height, 100), System.Drawing. Size)
Dim imgThumbOutput As New Bitmap(g, thumbSize.Width , thumbSize.Heigh t)
imgThumbOutput. Save(Server.Map Path(ThumbnailP ath), 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.Strea m, format As
System.Drawing. Imaging.ImageFo rmat)': Value of type 'String' cannot be
converted to 'System.IO.Stre am'.
'Public Sub Save(stream As System.IO.Strea m, format As
System.Drawing. Imaging.ImageFo rmat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing .Imaging.ImageF ormat'.
'Public Sub Save(filename As String, format As
System.Drawing. Imaging.ImageFo rmat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing .Imaging.ImageF ormat'.

Tried converting the path:
imgThumbOutput. Save(CType(Serv er.MapPath(Thum bnailPath), System.IO.Strea m),
thisFormat)

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

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.nos pam> 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.Strea m, format As
System.Drawing. Imaging.ImageFo rmat)': Value of type 'String' cannot be
converted to 'System.IO.Stre am'.
'Public Sub Save(stream As System.IO.Strea m, format As
System.Drawing. Imaging.ImageFo rmat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing .Imaging.ImageF ormat'.
'Public Sub Save(filename As String, format As
System.Drawing. Imaging.ImageFo rmat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing .Imaging.ImageF ormat'.


\\\
imgThumbOutput. Save(Server.Map Path(ThumbnailP ath), 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.ImageFo rmat = 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.ImageFo rmat type first:

---
imgThumbOutput. Save(Server.Map Path(ThumbnailP ath), CType(thisForma t,
System.Drawing. Imaging.ImageFo rmat))
---

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(NewthumbS ize(g.Width, g.Height, 100), System.Drawing. Size)
Dim imgThumbOutput As New Bitmap(g, thumbSize.Width , thumbSize.Heigh t)
imgThumbOutput. Save(Server.Map Path(ThumbnailP ath), 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.Strea m, format As
System.Drawing. Imaging.ImageFo rmat)': Value of type 'String' cannot be
converted to 'System.IO.Stre am'.
'Public Sub Save(stream As System.IO.Strea m, format As
System.Drawing. Imaging.ImageFo rmat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing .Imaging.ImageF ormat'.
'Public Sub Save(filename As String, format As
System.Drawing. Imaging.ImageFo rmat)': Option Strict On disallows implicit
conversions from 'System.Object' to 'System.Drawing .Imaging.ImageF ormat'.

Tried converting the path:
imgThumbOutput. Save(CType(Serv er.MapPath(Thum bnailPath), System.IO.Strea m),
thisFormat)

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

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
2147
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 about Option Strict? What advantages do I get with Option Strict On? Does better type statement make my code run faster? If anyone knows THE ANSWERS! please fill me in. I have ideas and belief but I would once and for all like to know what the...
11
2119
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. if i have class CCar and interface ICar when im doing this : ICar = new CCar
4
398
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 Strict Off, how do I get rid of this error? The code example is below... Dim oExcel As Object Dim oBook As Object Dim oSheet As Object
4
1947
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 DBNull.Value Then b = dsSupp.Tables(0).Rows(0).Item("BITMAP") end if
17
4494
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 binding. What should I do? Public Sub MyMnuHandler(ByVal sender As Object, ByVal e As System.EventArgs) If sender.checked = True Then sender.checked = False Else sender.checked = True
0
5703
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 however with Excel returning some weak-typed objects we are having problems. The only problem we have is with line (full code below) oExcel.ActiveSheet.Pictures.Insert("C:\Images\AB1.jpg").Select()
13
2327
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 of each and every single code module. Am I missing something here? -- -C. Moya www.cmoya.com
18
2897
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 I have option strict on. In my .vb file I have:
8
2427
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 man in question, in "Option Strict On" by default. Actually I don't believe I have code where this is not the case.
0
9529
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
10457
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
10231
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
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...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4119
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
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.