1

I'm trying to create an image based on an original image as a template.

a picture > kapak.jpg - resize to 1366x768 > orta.jpg - resize to 848x480

Code is working. Nothing wrong BUT when I use; code block 2 its locking the file which is kapak.jpg

I can't delete or rename etc. Even if I close the browser or vstudio or all. Nothing changes but restart the iis. I even cant delete it on the file browser as well. It's just locking it and doesnt allow anything. it says that; w3wp.exe or iis express worker is using this file so you cant delete or etc. Access denied.

I tried dispose or =nothing for bitmap moved code block 2 to another sub nothing changed.

If I dont use code block 2 it creates and allows me to delete or rename etc.

Any suggestions will be appreciated. How can I set free the file?

button_1_click

gelenIMG.ImageUrl = "\dene_2.jpg"

Dim uzatBOYfark As Integer
Dim uzatENfark As Integer
Dim kapakRESIMayar As New Rectangle(0, 0, 1366, 768)

uzatENfark = kapakRESIMayar.Width : uzatBOYfark = kapakRESIMayar.Height

Using orijinalRESIM = Image.FromFile(Server.MapPath(gelenIMG.ImageUrl))
If orijinalRESIM.Width < kapakRESIMayar.Width Then uzatENfark = kapakRESIMayar.Width * (kapakRESIMayar.Width / orijinalRESIM.Width)
If orijinalRESIM.Height < kapakRESIMayar.Height Then uzatBOYfark = kapakRESIMayar.Height * (kapakRESIMayar.Height / orijinalRESIM.Height)

Using kapakZEMINsablon = New Bitmap(kapakRESIMayar.Width, kapakRESIMayar.Height)
Using grp = Graphics.FromImage(kapakZEMINsablon)
grp.Clear(Color.Red)
grp.DrawImage(orijinalRESIM, New Rectangle(0, 0, uzatENfark, uzatBOYfark + 1), kapakRESIMayar, GraphicsUnit.Pixel)
End Using
kapakZEMINsablon.Save(Server.MapPath(geciciRESIMyeri & "\kapak.jpg"), Imaging.ImageFormat.Jpeg)
End Using
End Using
imgKAPAK.ImageUrl = geciciRESIMyeri & "\kapak.jpg"


code block 2:
Dim bitmapORTA As New Bitmap(Image.FromFile(Server.MapPath(imgKAPAK.ImageUrl), True), 848, 480)
bitmapORTA.Save(Server.MapPath(geciciRESIMyeri & "\orta.jpg"), Imaging.ImageFormat.Jpeg)
imgORTA.ImageUrl = geciciRESIMyeri & "\orta.jpg"
Akif
  • 7,098
  • 7
  • 27
  • 53
  • You have all this code wrapped inside of using blocks - this allows .net to PLAY nice and release resources. This is good! Then out of the blue, you have that 2nd code block, and for some amazing and staring reason you dump the use of "using blocks" which their VERY existence is to ensure that resources and files are released. Try your 2nd code block with using to release the file resources correctly - that should fix this. – Albert D. Kallal Dec 26 '20 at 19:05

0 Answers0