Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Small tip on using images
Message
 
To
11/04/2016 21:04:34
General information
Forum:
ASP.NET
Category:
Pictures and Image processing
Environment versions
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01634620
Message ID:
01634694
Views:
49
There's nothing really wrong with GDI+ it's just knowing the little tricks. I think with a few minor modifications you can make the code you have work.

I have a my own set of resizing routines that I've built and reuse in apps. They're part of the West Wind Toolkit (which is open source).

Here's the ImageUtils class that has a number of resizing routines in it:

https://github.com/RickStrahl/WestwindToolkit/blob/master/Westwind.Utilities/Utilities/ImageUtils.cs

or you can just use the Westwind.Utilities NuGet which includes this.

Here's the reference from the help file:
http://west-wind.com/westwindtoolkit/docs/_4ij04e9sl.htm

+++ Rick ---


>>There are a number of issues with this code. GDI+ uses unmanaged resources, so properly using Dispose() (or using as Viv points out) is key to ensure you get reliable results. One problem is that sometimes issues don't show up until you're in production because Dispose() timing issues can behave differently depending load and simple timing.
>>
>>The first is that you have to dispose the image explicitly before writing it again. It may work occasionally depending on how quick the garbage collector gets to the Gen0 collection, but more often than not the object likely isn't disposed.
>>
>>The second issue is that certain file formats - PNG in particular - can't be rewritten in a single go. So you can't for example, read a PNG from disk, resize it, then write it back in a single Bitmap/Graphics instance. You have to basically open, resize, write out to new (temp) file, close the first file, copy the temp file, delete the new (temp) file.
>
>Thanks, what alternative do you recommend to crop and/or resize.
>
>I never had those behaviors but it is always nice to know of additional mechanisms.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform