Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
wijesena  
#1 Posted : Tuesday, August 15, 2006 5:53:05 PM(UTC)
wijesena

Rank: Member

Groups: Member
Joined: 8/15/2006(UTC)
Posts: 13

I am using Aurigma.GraphicsMill library to create different size of images from a single image. My application is written using .NET C#. The images are very large (around 30MB) What I did was open image 3 times and resize and save it. It takes long time for this process. I am sure there must be an efficient way of doing this. Can anyone point me in the right direction? If you can provide a sample code that would be great. Janaka
wijesena  
#2 Posted : Wednesday, August 16, 2006 3:04:06 PM(UTC)
wijesena

Rank: Member

Groups: Member
Joined: 8/15/2006(UTC)
Posts: 13

Come on guys, some one must have done this before ...
Dmitry  
#3 Posted : Wednesday, August 16, 2006 3:27:47 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello, To say something we should look through your code. Could you post your code sample here or submit case with it?

Edited by user Thursday, May 22, 2008 10:33:39 PM(UTC)  | Reason: Not specified

Sincerely yours, Dmitry Sevostyanov UserPostedImage Follow Aurigma on Twitter!
Jdelagarza  
#4 Posted : Wednesday, August 16, 2006 11:52:33 PM(UTC)
Jdelagarza

Rank: Member

Groups: Member
Joined: 7/6/2005(UTC)
Posts: 16

Here are two methods I've tried: 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...
Code:
        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 :)
Code:

        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... ?

Edited by user Wednesday, December 19, 2007 2:53:37 PM(UTC)  | Reason: Not specified

wijesena  
#5 Posted : Thursday, August 17, 2006 6:22:06 PM(UTC)
wijesena

Rank: Member

Groups: Member
Joined: 8/15/2006(UTC)
Posts: 13

Let me clarify things little bit more … 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
File Attachment(s):
Class1.zip (3kb) downloaded 193 time(s).
wijesena  
#6 Posted : Thursday, August 17, 2006 6:24:59 PM(UTC)
wijesena

Rank: Member

Groups: Member
Joined: 8/15/2006(UTC)
Posts: 13

Jdelagarza, thanks for your post. I am doing something similar to what you have posted. My problem is I am doing it 6 times to create 6 different images. I wanted to improve that.
Dmitry  
#7 Posted : Thursday, August 17, 2006 8:07:53 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello, 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. Here is updated code sample:
    Code:
    System.String strSrcPath = @"d:/images/test/";
    System.String strDestPath = @"d:/temp/resize";
    	
    Aurigma.GraphicsMill.Drawing.Font font = new Aurigma.GraphicsMill.Drawing.Font("Arial", 20);
    Aurigma.GraphicsMill.Drawing.SolidBrush brush = new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Red);
    	
    Aurigma.GraphicsMill.Transforms.Resize resize = new Aurigma.GraphicsMill.Transforms.Resize();
    resize.InterpolationMode = Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality;
    resize.ResizeMode = Aurigma.GraphicsMill.Transforms.ResizeMode.Fit;
    	
    // Load source image once
    Aurigma.GraphicsMill.Bitmap srcBitmap = new Aurigma.GraphicsMill.Bitmap(strSrcPath + "pict0001.jpg");
    srcBitmap.HorizontalResolution = 72.0f;
    srcBitmap.VerticalResolution = 72.0f;
    	
    // A3
    using(Aurigma.GraphicsMill.Bitmap a3Bitmap = new Aurigma.GraphicsMill.Bitmap())
    {
    	resize.Width = 846;
    	resize.Height = 1188;
    	resize.ApplyTransform(srcBitmap, a3Bitmap);
    	a3Bitmap.Save(strDestPath + "a3.jpg");
    }
    	
    // A4
    Aurigma.GraphicsMill.Bitmap a4Bitmap = new Aurigma.GraphicsMill.Bitmap();
    resize.Width = 594;
    resize.Height = 846;
    resize.ApplyTransform(srcBitmap, a4Bitmap);
    a4Bitmap.Save(strDestPath + "a4.jpg");
    	
    // A5
    using(Aurigma.GraphicsMill.Bitmap a5Bitmap = new Aurigma.GraphicsMill.Bitmap())
    {
    	resize.Width = 423;
    	resize.Height = 594;
    	resize.ApplyTransform(srcBitmap, a5Bitmap);
    	a5Bitmap.Save(strDestPath + "a5.jpg");
    }
    	
    // Source bitmap for thumbnail, enlargement and composite image.
    Aurigma.GraphicsMill.Bitmap srcThumbnailBitmap = a4Bitmap;
    	
    // Convert color space to RGB once
    if(srcThumbnailBitmap.ColorSpace != Aurigma.GraphicsMill.ColorSpace.Rgb)
    {
    	srcThumbnailBitmap.ColorManagement.RgbColorProfile = Aurigma.GraphicsMill.ColorProfile.FromSrgb();
    	srcThumbnailBitmap.ColorManagement.ColorManagementEnabled = true;
    	srcThumbnailBitmap.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.Rgb, false, srcThumbnailBitmap.IsExtended);
    }
    	
    // Thumbnail
    using(Aurigma.GraphicsMill.Bitmap thumbnail = new Aurigma.GraphicsMill.Bitmap())
    {
    	resize.Width = 130;
    	resize.Height = 130;
    	resize.ApplyTransform(srcThumbnailBitmap, thumbnail);
    	thumbnail.HorizontalResolution = 72.0f;
    	thumbnail.VerticalResolution = 72.0f;
    	thumbnail.Save(strDestPath + "thumbnail.jpg");
    }
    	
    // Enlargement
    using(Aurigma.GraphicsMill.Bitmap enlargement = new Aurigma.GraphicsMill.Bitmap())
    {
    	resize.Width = 389;
    	resize.Height = 265;
    	resize.ApplyTransform(srcThumbnailBitmap, enlargement);
    	enlargement.HorizontalResolution = 72.0f;
    	enlargement.VerticalResolution = 72.0f;
    
    	using(Aurigma.GraphicsMill.Drawing.GdiGraphics gr = enlargement.GetGdiGraphics())
    	{
    		gr.DrawString("Aurigma Inc.", font, brush, 0, 0);
    	}
    
    	enlargement.Save(strDestPath + "enlargement.jpg");
    }
    	
    // Composite image
    using(Aurigma.GraphicsMill.Bitmap composite = new Aurigma.GraphicsMill.Bitmap())
    {
    	resize.Width = 500;
    	resize.Height = 500;
    	resize.ApplyTransform(srcThumbnailBitmap, composite);
    	composite.HorizontalResolution = 150.0f;
    	composite.VerticalResolution = 150.0f;
    	composite.Save(strDestPath + "composite.jpg");
    }
    
  • Edited by user Wednesday, December 19, 2007 2:53:59 PM(UTC)  | Reason: Not specified

    Sincerely yours, Dmitry Sevostyanov UserPostedImage Follow Aurigma on Twitter!
    wijesena  
    #8 Posted : Sunday, August 20, 2006 3:38:55 PM(UTC)
    wijesena

    Rank: Member

    Groups: Member
    Joined: 8/15/2006(UTC)
    Posts: 13

    Dmitry thanks for your help. Your suggestions really improve the program. Janaka
    wijesena  
    #9 Posted : Sunday, September 03, 2006 5:21:38 PM(UTC)
    wijesena

    Rank: Member

    Groups: Member
    Joined: 8/15/2006(UTC)
    Posts: 13

    I have come across a small problem regarding the code. The original image contains metadata, but the resize images do not have them. How do we get the metadata to the new images we are creating?
    Dmitry  
    #10 Posted : Sunday, September 03, 2006 5:36:29 PM(UTC)
    Dmitry

    Rank: Advanced Member

    Groups: Member, Administration, Moderator
    Joined: 8/3/2003(UTC)
    Posts: 1,070

    Thanks: 1 times
    Was thanked: 12 time(s) in 12 post(s)
    Hello, 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".

    Edited by user Monday, October 27, 2008 11:49:50 PM(UTC)  | Reason: Not specified

    Sincerely yours, Dmitry Sevostyanov UserPostedImage Follow Aurigma on Twitter!
    wijesena  
    #11 Posted : Sunday, September 03, 2006 9:12:22 PM(UTC)
    wijesena

    Rank: Member

    Groups: Member
    Joined: 8/15/2006(UTC)
    Posts: 13

    I used the following code to resize the images with metadata. After resizing I could not open the image. The error was unexpected end-of-file was encountered. Any thoughts why it is happening? Janaka
    Code:
    
    Aurigma.GraphicsMill.Transforms.Resize resize               = new Aurigma.GraphicsMill.Transforms.Resize(); 
                resize.InterpolationMode                                    = Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality; 
                resize.ResizeMode                                           = Aurigma.GraphicsMill.Transforms.ResizeMode.Fit;
    
                Aurigma.GraphicsMill.Codecs.ExifDictionary exif             = null;
                Aurigma.GraphicsMill.Codecs.IptcDictionary iptc             = null;
    
                Aurigma.GraphicsMill.Codecs.JpegEncoderOptions encoderOptions = 
                                    new Aurigma.GraphicsMill.Codecs.JpegEncoderOptions(70,false);
    
    
                using (Aurigma.GraphicsMill.Codecs.JpegReader jpegReader    = new Aurigma.GraphicsMill.Codecs.JpegReader(strSourceFileName))
                {
    
                    encoderOptions.Iptc                                         = jpegReader.Iptc;
                    encoderOptions.Exif                                         = jpegReader.Exif;
    
                }
                            
    
                Aurigma.GraphicsMill.Bitmap srcBitmap                       = new Aurigma.GraphicsMill.Bitmap(strSourceFileName);
    
    
                
                float size                                                  = ((float)srcBitmap.BitsPerPixel*srcBitmap.Width*srcBitmap.Height)/8388608;
                srcBitmap.Save(strDest + strA3, encoderOptions);
    
    

    Edited by user Wednesday, December 19, 2007 2:54:27 PM(UTC)  | Reason: Not specified

    wijesena  
    #12 Posted : Monday, September 04, 2006 4:06:58 PM(UTC)
    wijesena

    Rank: Member

    Groups: Member
    Joined: 8/15/2006(UTC)
    Posts: 13

    I have tried the sample code in page http://www.aurigma.com/d...gEXIFandIPTCMetadata.htm The program runs with out any problem. I can also see the image created. But when I tried to open the new image using Photoshop to check the metadata written it gives the error, unexpected end-of-file was encountered. Can you advice how to solve this problem. Janaka

    Edited by user Wednesday, October 29, 2008 2:33:06 AM(UTC)  | Reason: Not specified

    Dmitry  
    #13 Posted : Tuesday, September 05, 2006 5:44:26 PM(UTC)
    Dmitry

    Rank: Advanced Member

    Groups: Member, Administration, Moderator
    Joined: 8/3/2003(UTC)
    Posts: 1,070

    Thanks: 1 times
    Was thanked: 12 time(s) in 12 post(s)
    Hello, Sorry for delayed answer. Please, View post.
    Sincerely yours, Dmitry Sevostyanov UserPostedImage Follow Aurigma on Twitter!
    Users browsing this topic
    Forum Jump  
    You cannot post new topics in this forum.
    You cannot reply to topics in this forum.
    You cannot delete your posts in this forum.
    You cannot edit your posts in this forum.
    You cannot create polls in this forum.
    You cannot vote in polls in this forum.