hi all,
i'm using a page called ShowImage.aspx in my project. The page's doing a crop for each picture and shrink them.
when i show a picture in my another pages as above way, i can't delete them.
File.Delete(Server.MapPath("path")) is not work.
Error Message : ..... the file is using another project.....
for example, i call a pictue as this way :
<img src='ShowImage.aspx?src=path&width=50&height=50&comp=80(0-100)'>
i'm writing below my ShowImage.aspx page's content.
already now thanks...
Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class ShowImage
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strFilename As String
Dim i As System.Drawing.Image
strFilename = Server.MapPath(Request.QueryString("src"))
i = System.Drawing.Image.FromFile(strFilename)
Dim Thumbnail As New System.drawing.Bitmap(Request.QueryString("width"), Request.QueryString("height"), PixelFormat.Format24bppRgb)
Dim g As Graphics = Graphics.FromImage(Thumbnail)
If (i.Width / i.Height) < (Request.QueryString("width") / Request.QueryString("height")) Then
' portrait image processing
g.DrawImage(i, New Rectangle(0, 0, Request("width"), Request("height")), New Rectangle(0, 0, i.Width, i.Width / Request("width") * Request("height")), GraphicsUnit.Pixel)
Else
' landscape image processing
g.DrawImage(i, New Rectangle(0, 0, Request("width"), Request("height")), New Rectangle(0, 0, i.Height / Request("height") * Request("width"), i.Height), GraphicsUnit.Pixel)
End If
Dim encoderParams As System.Drawing.Imaging.EncoderParameters = New System.Drawing.Imaging.EncoderParameters
Dim quality As Long
Dim comp As Integer = 0
If Not (Request.QueryString("comp") = "") Then comp = CInt(Request.QueryString("comp"))
quality = comp ' 0 to 100 - 100 highest quality
Dim encoderParam As System.Drawing.Imaging.EncoderParameter = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality)
encoderParams.Param(0) = encoderParam
Dim arrayICI As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
Dim jpegICI As ImageCodecInfo
Dim x As Integer
For x = 0 To arrayICI.Length - 1
If (arrayICI(x).FormatDescription.Equals("JPEG")) Then
jpegICI = arrayICI(x)
Exit For
End If
Next
If Not jpegICI Is Nothing Then
Thumbnail.Save(Response.OutputStream, jpegICI, encoderParams)
End If
'Response.ContentType = "image/jpg"
'Thumbnail.Save(Response.OutputStream, ImageFormat.Jpeg)
'i.Save(Response.OutputStream, ImageFormat.Jpeg)
Thumbnail.Dispose()
End Sub
End Class