Alec.
Alec.

Reputation: 5525

Converting Image VB.net

I have the following code

    Public Sub ConvertImage(ByVal Filename As String, _
ByVal DesiredFormat As System.Drawing.Imaging.ImageFormat, _
ByVal NewFilename As String)
        ' Takes a filename and saves the file in a new format
        Try
            Dim imgFile As System.Drawing.Image = _
              System.Drawing.Image.FromFile(Filename)
            imgFile.Save(NewFilename, DesiredFormat)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub btnPrintVC40_Click(sender As System.Object, e As System.EventArgs) Handles btnPrintVC40.Click
        Dim SigName As String
        Dim SigNameNew As String
        SigName = "SELECT Signature FROM vw_Report_VehicleCheckFTA WHERE VCID = " & CStr(lRiskAssessID)
        SigNameNew = SigName.PadLeft(SigName.Length - 4)
        ConvertImage(SigName, _
                     System.Drawing.Imaging.ImageFormat.Jpeg, _
                   SigNameNew & ".jpeg")
        runReport("SELECT * FROM vw_Report_VehicleCheckFTA WHERE VCID = " & CStr(lRiskAssessID), "FTAVehicleCheck2.rpt")
    End Sub

Basically what this should do is convert a png image to jpeg, then launch a crystal report. Instead I get the following exception:

Error

I just can't for the life of me figure out why.

Upvotes: 0

Views: 111

Answers (1)

David Sdot
David Sdot

Reputation: 2333

    SigName = "SELECT Signature FROM vw_Report_VehicleCheckFTA WHERE VCID = " & CStr(lRiskAssessID) ' lRiskAssessID is 3772 I guess
    SigNameNew = SigName.PadLeft(SigName.Length - 4) 'SignameNew will become "SELECT Signature FROM vw_Report_VehicleCheckFTA WHERE VCID = 3772", PadLeft will actually do nothing at all 

    ConvertImage(SigName, _
                 System.Drawing.Imaging.ImageFormat.Jpeg, _
               SigNameNew & ".jpeg")

Convert Image is called with Filename "SELECT Signature FROM vw_Report_VehicleCheckFTA WHERE VCID = 3772" and I guess that's not the real filename.

You should take a look on how to get data from your database, you can't just throw some string in the air to get it ;)

Upvotes: 1

Related Questions