Vampyre Imaging Library Forum

Imaging Category => Help & Questions => Topic started by: yapt on 1 February 2009, 15:00:27

Title: Resize image to a size limit
Post by: yapt on 1 February 2009, 15:00:27
Hello,

I am new to Vampyre Imaging library, I only want use imaging library to save an image to a sqlite database.  Then sqlite has a maximum size for the database image column.

I would like to know if I have any function to reduce (maintaining aspect ratio) the image memory size to any value I can specify.  I have read Resize and ResizeImage functions.  But both of them need an aspect limits (width or height).  But I would like to reduce any image to a 1Mb (ie) memory size.

Any clue about this ?
Title: Re: Resize image to a size limit
Post by: Galfar on 1 February 2009, 23:38:39
Well, I found this VB code that should do what you want to do: calculate
image dimensions given the max space they can occupy.
In what data format you want to save your images?
You would need to change first line to something like this (image.Width * image.Height * BytesPerPixel). 

shrinkFactor = MaxFieldLength / (image.Width * image.Height) 
outImageWidth = CInt(Math.Sqrt(shrinkFactor) * image.Width) 
outImageHeight = CInt(Math.Sqrt(shrinkFactor) * image.Height) 

Title: Re: Resize image to a size limit
Post by: yapt on 10 February 2009, 16:23:47
Sorry my delay Galfar....

The format to save my images maybe jpeg, but at last I would like to lookup a way to save the images on the original format (I am saving all of them on SQLite fields).

I will try this code in a few days (perhaps the weekend).

Thanks a lot for your answer and sorry my delay again...

Greetings.