locked
Too man arguments to 'Public Function Save() As System.Drawing.Drawing2D.GraphicsState' RRS feed

  • Question

  • User1810039979 posted

    This is my first time using the System.Drawing Namespace and I'm having an issue creating the image.  I keep getting the message that I have too many arguments when i try to save the image, although all the tutorials I've seen show a path argument and a file format argument.  When I remove one argument I still get the message.  When I remove both arguments I get no error which makes me think its saving the image somewhere without me specifying a location!  Here is my VB.NET codebehind.

     

    1    Imports System.Math
    2    Imports System.Drawing
    3    Imports System.Drawing.Imaging
    4    
    5    Partial Class nameofthepage
    6         Inherits System.Web.UI.Page
    7    
    8         Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) HAndles Me.Load
    9              Panel1.Visible = False
    10        End Sub
    11   
    12        Protected Sub MyQueryResults_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyQueryResults.SelectedIndexChanged
    13             Dim mapImage As New Bitmap(200, 220)
    14             Dim myMapObject As Graphics
    15             myMapObject = Graphics.FromImage(mapImage)
    16             myMapObject.Clear(Color.Gray)
    17   
    18             Dim mapTitle As String
    19             mapTitle = MyQueryResults.SelectedDataKey(2)
    20             myMapObject.Drawstring(mapTitle, New Font("Verdana", 12), Brushes.Black, New PointF(5, 5))
    21             
    22             Dim savefile As String = "http://domain/fold1/fold2/myimage.gif"
    23             myMapObject.Save(savefile, ImageFormat.Gif)
    24             queryResultsImage.ImageUrl = savefile
    25   
    26             Panel1.Visible = True
    27        End Sub
    28   End Class
    

     

    MyQueryResults is a Gridview control
    queryResultsImage is an asp Image control

     Can anyone tell me what I'm doing wrong?  Thanks.

    Friday, February 6, 2009 11:47 AM

Answers

  • User955742345 posted

    A little confusion goes a long way!

     You are trying to save the graphics object, not the Image.  Your examples should have you saving the Image object.

    <STRIKE>myMapObject.Save(savefile, ImageFormat.Gif)</STRIKE>

    mapImage.Save(savefile, ImageFormat.Gif)

    The graphics object makes changes directly to the image, so save the image and not the graphics.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 6, 2009 12:06 PM

All replies

  • User955742345 posted

    A little confusion goes a long way!

     You are trying to save the graphics object, not the Image.  Your examples should have you saving the Image object.

    <STRIKE>myMapObject.Save(savefile, ImageFormat.Gif)</STRIKE>

    mapImage.Save(savefile, ImageFormat.Gif)

    The graphics object makes changes directly to the image, so save the image and not the graphics.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 6, 2009 12:06 PM
  • User1810039979 posted

    Awesome. 

    Thanks!

    Friday, February 6, 2009 1:40 PM