hi
i had been try save image from example
https://www.aspsnippets.com/questions/174102/Reduce-Image-Picture-size-in-ASPNet-using-C-and-VBNet/answers
but when save image i had have found error like this
Value cannot be null.
Parameter name: encoder
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: encoder
Source Error:
Line 810: Dim encoderParams As EncoderParameters = New EncoderParameters(1)
Line 811: encoderParams.Param(0) = encoderParameter
Line 812: inputImage.Save(path, imageCodecInfo, encoderParams)
Line 813: End Sub
Line 814:
thanks
<ASP:Button ID = "Button3" runat="server" Text="Button" OnClick="OnResize" />
Imports System.Data.SqlClient
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.IO
Imports System.Drawing
Imports System.Configuration
Imports ClosedXML.Excel
Imports System.Net
Imports System.Net.Mail
Imports System.Drawing.Imaging
Imports Microsoft.SqlServer
Protected Sub OnResize(ByVal sender As Object, ByVal e As EventArgs)
Dim inputImage As System.Drawing.Image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream)
Dim dirsimpan_ketsak As String = "/photo/sket/"
Me.SaveJpeg(inputImage, Server.MapPath(dirsimpan_ketsak & FileUpload1.FileName), 50)
End Sub
Public Sub SaveJpeg(ByVal inputImage As System.Drawing.Image, ByVal path As String, ByVal quality As Integer)
Dim encoderParameter As EncoderParameter = New EncoderParameter(Encoder.Quality, quality)
Dim imageCodecInfo As ImageCodecInfo = Me.GetEncoderInfo("/photo/sket/")
Dim encoderParams As EncoderParameters = New EncoderParameters(1)
encoderParams.Param(0) = encoderParameter
inputImage.Save(path, imageCodecInfo, encoderParams)
End Sub
Private Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
For i As Integer = 0 To codecs.Length - 1
If codecs(i).MimeType = mimeType Then
Return codecs(i)
End If
Next
Return Nothing
End Function