This first one is pretty standard, and I'm working with ccit4 compressed tiff files, so they're one bit images (black and white) and when I'm done with the resize, I have to change them back to one bit... now the ScaleToGrey method of resizing is particular to that, and depending on the quality you need you can adjust that to other methods of resizing for varied performance.. Also, intWidth contains the width I want in the end, I found out not too long ago that Aurigma will calculate that for me but haven't had a chance to change it yet, so ignore the aspect ratio calculation I'm doing...
Dim tnfResize As Aurigma.GraphicsMill.Transforms.Resize
Try
bmpImage.Load(strFileName)
Catch Ex As Exception
Throw New Exception("Unable to load the requested image.", Ex)
End Try
tnfResize = New Aurigma.GraphicsMill.Transforms.Resize
tnfResize.Width = intWidth
tnfResize.Height = CInt(intWidth / (bmpImage.Width / bmpImage.Height))
tnfResize.Priority = Threading.ThreadPriority.Highest
tnfResize.ResizeMode = GraphicsMill.Transforms.ResizeMode.Fit
tnfResize.InterpolationMode = GraphicsMill.Transforms.InterpolationMode.ScaleToGray
Try
tnfResize.ApplyTransform(bmpImage)
Catch ex As Exception
Throw New Exception("Error resizing image to " & tnfResize.Width & " width.")
End Try
Try
bmpImage.ColorManagement.ConvertToIndexed(1, GraphicsMill.ColorPaletteType.GrayScale, Nothing)
Catch Ex As Exception
Throw New Exception("Error adapting color index to 1bpp.", Ex)
End Try
tnfResize.Dispose()
tnfResize = Nothing
Here's a second method which usuaully seems to work better.. from my understanding its because the image is read and resized in one pass or there's less memory used or something like that?
But i think the usage of this syntax may be less flexible (in conversion quality etc..) so you'd have to try and see if it worked better for what you're doing.. the nice thing is its easy to try since its not hard to code up 🙂
Try
bmpImage.LoadThumbnail(strFileName, intWidth, 0)
Catch Ex As Exception
Throw New Exception("Unable to load the requested image.", Ex)
End Try
The images I work with are probably 2500x3000 pixels or so and trying to resize them to about 50% is too expensive to use on a server, so i've actually removed the code from the server.. (it was a dual core P4 2.8 Ghz) and with it was probably taking about one second per resize (with 35 users that pegged the CPU)
Now I don't know if there's another way to do it that is more efficient? I'd love to know if that were the case 🙂 but my images are only 75K-250K, so with a 30MB image I'd imagine it'd be slow... ?
My application is written using .NET C#. This is a normal windows application that does the image creation for the web site.
From an original image (around 30MB) I have to create A3, A4, and A5 images Thumbnail (130x130, 72dpi) Enlargement (389x265, 72dpi) with water mark Composite image (500x500, 150dpi)
I have to process close to 15000 images (from our old website).
The way I did this was open original image, resize it, save it. Did that 6 times to create those 6 images.
I found that the process was very slow. It would take ages to process them all.
I have attached the file with the functions I used to for this task.
BuildHiResImages – function is used to create A3, A4, and A5 images from the original image
BuildBasicImages - used to create thumbnail, Enlargement and Composite images, from the original image
when creating these images (BuildBasicImages) I have to convert the color mode to SRGB, for better viewing through web
Your source code is very good but I can advise the following:
You should load source image once only;
Color management is very time expensive operation, you should apply it once;
You should create source image for thumbnail, enlargement and composite image of reduced size from source image because of resizing of huge image works long time. And then create your small images from this interim source image. I have defined A4 image as interim image of reduced size in my code sample.
If you need to preserve EXIF/IPTC metadata, you should load it from source image before resize and save it along with resized images. Bitmap.Load doesn't support metadata handling, so you should use some reader instead of this. You can read more information in the articles: "Loading EXIF and IPTC Metadata" and "Saving EXIF and IPTC Metadata".