473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

thumbnail conundrum

How do you create a thumbnail constrained to a box, without distorting and
but making where it doesn't fill the box transparent.

I'm two thirds there :

Size fitImageSize = this.GetScaledImageDimensions(
myBitmap.Width, myBitmap.Height, intThumbWidth,
intThumbHeight);

Bitmap imgOutput = new Bitmap(myBitmap, fitImageSize.Width,
fitImageSize.Height);

imgOutput.Save(Server.MapPath(sSavePath + sThumbFile),
System.Drawing.Imaging.ImageFormat.Jpeg);

But its the third aspect that is tricky,

Cheers all.
Nov 16 '05 #1
7 1156
You should calculate the resizing Ratio... It is not possible to fit it in a
box exactly unless all your images have the width=height
otherwise you find out what the ratio is for the new width to the old width,
then you use that ratio to calculate the new height.

This will ensure that your image is proportional. I have some code that does
that, if you want I'll post it here
Hope that helps

--
Abdellah Elamiri
..net Developer
Efficacy through simplicity
"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
How do you create a thumbnail constrained to a box, without distorting and
but making where it doesn't fill the box transparent.

I'm two thirds there :

Size fitImageSize = this.GetScaledImageDimensions(
myBitmap.Width, myBitmap.Height, intThumbWidth, intThumbHeight);

Bitmap imgOutput = new Bitmap(myBitmap, fitImageSize.Width,
fitImageSize.Height);

imgOutput.Save(Server.MapPath(sSavePath + sThumbFile),
System.Drawing.Imaging.ImageFormat.Jpeg);

But its the third aspect that is tricky,

Cheers all.

Nov 16 '05 #2
Hi Abdellah,

Thanks for your reply. I do have a function that calculates the best fit for
the thumbnail,. thats my 'GetScaledImageDimensions'

However I want the total thumbnail size to be the size of the 'box' but
contain the scaled image inside it and have the parts where it's too small
be white or tranparent.

Its so I dont break the designers precious layout ;)
----------------------------
| |<----- transparent
| |
|-------------------------- |
| |
| thumb |
|-------------------------- |
| |
|-------------------------- |

Thanks
"A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message
news:eU**************@TK2MSFTNGP12.phx.gbl...
You should calculate the resizing Ratio... It is not possible to fit it in a box exactly unless all your images have the width=height
otherwise you find out what the ratio is for the new width to the old width, then you use that ratio to calculate the new height.

This will ensure that your image is proportional. I have some code that does that, if you want I'll post it here
Hope that helps

--
Abdellah Elamiri
.net Developer
Efficacy through simplicity
"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
How do you create a thumbnail constrained to a box, without distorting and but making where it doesn't fill the box transparent.

I'm two thirds there :

Size fitImageSize = this.GetScaledImageDimensions(
myBitmap.Width, myBitmap.Height,

intThumbWidth,
intThumbHeight);

Bitmap imgOutput = new Bitmap(myBitmap, fitImageSize.Width,
fitImageSize.Height);

imgOutput.Save(Server.MapPath(sSavePath + sThumbFile),
System.Drawing.Imaging.ImageFormat.Jpeg);

But its the third aspect that is tricky,

Cheers all.


Nov 16 '05 #3
distorting it by a pixel or two wouldn't hurt if it's just a thumbnail

--
Abdellah Elamiri
..net Developer
Efficacy through simplicity
"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:ue*************@TK2MSFTNGP12.phx.gbl...
Hi Abdellah,

Thanks for your reply. I do have a function that calculates the best fit for the thumbnail,. thats my 'GetScaledImageDimensions'

However I want the total thumbnail size to be the size of the 'box' but
contain the scaled image inside it and have the parts where it's too small
be white or tranparent.

Its so I dont break the designers precious layout ;)
----------------------------
| |<----- transparent
| |
|-------------------------- |
| |
| thumb |
|-------------------------- |
| |
|-------------------------- |

Thanks
"A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message
news:eU**************@TK2MSFTNGP12.phx.gbl...
You should calculate the resizing Ratio... It is not possible to fit it in
a
box exactly unless all your images have the width=height
otherwise you find out what the ratio is for the new width to the old

width,
then you use that ratio to calculate the new height.

This will ensure that your image is proportional. I have some code that

does
that, if you want I'll post it here
Hope that helps

--
Abdellah Elamiri
.net Developer
Efficacy through simplicity
"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
How do you create a thumbnail constrained to a box, without distorting

and but making where it doesn't fill the box transparent.

I'm two thirds there :

Size fitImageSize = this.GetScaledImageDimensions(
myBitmap.Width, myBitmap.Height,

intThumbWidth,
intThumbHeight);

Bitmap imgOutput = new Bitmap(myBitmap, fitImageSize.Width,
fitImageSize.Height);

imgOutput.Save(Server.MapPath(sSavePath + sThumbFile),
System.Drawing.Imaging.ImageFormat.Jpeg);

But its the third aspect that is tricky,

Cheers all.



Nov 16 '05 #4
You should be able to create a new bitmap which is the exact size of the box
your are trying to fill. Make that bitmap one solid color, white for
example, and then copy your thumbnail into the center of the new bitmap.
Then save the new bitmap as your thumbnail. You'd have to calculate where to
place your thumbnail based on which of it's dimensions are too small.

"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:ue*************@TK2MSFTNGP12.phx.gbl...
Hi Abdellah,

Thanks for your reply. I do have a function that calculates the best fit for the thumbnail,. thats my 'GetScaledImageDimensions'

However I want the total thumbnail size to be the size of the 'box' but
contain the scaled image inside it and have the parts where it's too small
be white or tranparent.

Its so I dont break the designers precious layout ;)
----------------------------
| |<----- transparent
| |
|-------------------------- |
| |
| thumb |
|-------------------------- |
| |
|-------------------------- |

Thanks
"A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message
news:eU**************@TK2MSFTNGP12.phx.gbl...
You should calculate the resizing Ratio... It is not possible to fit it in
a
box exactly unless all your images have the width=height
otherwise you find out what the ratio is for the new width to the old

width,
then you use that ratio to calculate the new height.

This will ensure that your image is proportional. I have some code that

does
that, if you want I'll post it here
Hope that helps

--
Abdellah Elamiri
.net Developer
Efficacy through simplicity
"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
How do you create a thumbnail constrained to a box, without distorting

and but making where it doesn't fill the box transparent.

I'm two thirds there :

Size fitImageSize = this.GetScaledImageDimensions(
myBitmap.Width, myBitmap.Height,

intThumbWidth,
intThumbHeight);

Bitmap imgOutput = new Bitmap(myBitmap, fitImageSize.Width,
fitImageSize.Height);

imgOutput.Save(Server.MapPath(sSavePath + sThumbFile),
System.Drawing.Imaging.ImageFormat.Jpeg);

But its the third aspect that is tricky,

Cheers all.



Nov 16 '05 #5
Hi Matt,

Thats a great idea but I can't seem to find any suitable methods for copying
into the second bitmap.

Can anyone help ?

Thanks,

Chris.
"Matt Burland" <wjousts@[no spam]hotmail.com> wrote in message
news:eh*************@tk2msftngp13.phx.gbl...
You should be able to create a new bitmap which is the exact size of the box your are trying to fill. Make that bitmap one solid color, white for
example, and then copy your thumbnail into the center of the new bitmap.
Then save the new bitmap as your thumbnail. You'd have to calculate where to place your thumbnail based on which of it's dimensions are too small.

"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:ue*************@TK2MSFTNGP12.phx.gbl...
Hi Abdellah,

Thanks for your reply. I do have a function that calculates the best fit for
the thumbnail,. thats my 'GetScaledImageDimensions'

However I want the total thumbnail size to be the size of the 'box' but
contain the scaled image inside it and have the parts where it's too small be white or tranparent.

Its so I dont break the designers precious layout ;)
----------------------------
| |<----- transparent
| |
|-------------------------- |
| |
| thumb |
|-------------------------- |
| |
|-------------------------- |

Thanks
"A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message
news:eU**************@TK2MSFTNGP12.phx.gbl...
You should calculate the resizing Ratio... It is not possible to fit
it in
a
box exactly unless all your images have the width=height
otherwise you find out what the ratio is for the new width to the old

width,
then you use that ratio to calculate the new height.

This will ensure that your image is proportional. I have some code

that does
that, if you want I'll post it here
Hope that helps

--
Abdellah Elamiri
.net Developer
Efficacy through simplicity
"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...
> How do you create a thumbnail constrained to a box, without
distorting and
> but making where it doesn't fill the box transparent.
>
> I'm two thirds there :
>
> Size fitImageSize = this.GetScaledImageDimensions(
> myBitmap.Width, myBitmap.Height,
intThumbWidth,
> intThumbHeight);
>
> Bitmap imgOutput = new Bitmap(myBitmap, fitImageSize.Width,
> fitImageSize.Height);
>
> imgOutput.Save(Server.MapPath(sSavePath + sThumbFile),
> System.Drawing.Imaging.ImageFormat.Jpeg);
>
> But its the third aspect that is tricky,
>
> Cheers all.
>
>



Nov 16 '05 #6
Chris,

I believe you need the DrawImage function of the Graphics object. You can
create a Graphics object using Graphics.FromImage (using your new image) and
draw your thumbnail onto it. Check out the Graphics object in MSDN.
I did something similar myself a while back, but I don't remember exactly
what I did and I don't have the code handy right now.

Matt

"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:uH**************@TK2MSFTNGP10.phx.gbl...
Hi Matt,

Thats a great idea but I can't seem to find any suitable methods for copying into the second bitmap.

Can anyone help ?

Thanks,

Chris.
"Matt Burland" <wjousts@[no spam]hotmail.com> wrote in message
news:eh*************@tk2msftngp13.phx.gbl...
You should be able to create a new bitmap which is the exact size of the box
your are trying to fill. Make that bitmap one solid color, white for
example, and then copy your thumbnail into the center of the new bitmap.
Then save the new bitmap as your thumbnail. You'd have to calculate where to
place your thumbnail based on which of it's dimensions are too small.

"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:ue*************@TK2MSFTNGP12.phx.gbl...
Hi Abdellah,

Thanks for your reply. I do have a function that calculates the best fit
for
the thumbnail,. thats my 'GetScaledImageDimensions'

However I want the total thumbnail size to be the size of the 'box'

but contain the scaled image inside it and have the parts where it's too

small be white or tranparent.

Its so I dont break the designers precious layout ;)
----------------------------
| |<----- transparent
| |
|-------------------------- |
| |
| thumb |
|-------------------------- |
| |
|-------------------------- |

Thanks
"A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message news:eU**************@TK2MSFTNGP12.phx.gbl...
> You should calculate the resizing Ratio... It is not possible to fit it
in
a
> box exactly unless all your images have the width=height
> otherwise you find out what the ratio is for the new width to the old width,
> then you use that ratio to calculate the new height.
>
> This will ensure that your image is proportional. I have some code

that does
> that, if you want I'll post it here
>
>
> Hope that helps
>
> --
> Abdellah Elamiri
> .net Developer
> Efficacy through simplicity
> "Chris Perry" <ch***@pushnet.co.uk> wrote in message
> news:uo**************@TK2MSFTNGP12.phx.gbl...
> > How do you create a thumbnail constrained to a box, without distorting and
> > but making where it doesn't fill the box transparent.
> >
> > I'm two thirds there :
> >
> > Size fitImageSize = this.GetScaledImageDimensions(
> > myBitmap.Width, myBitmap.Height,
> intThumbWidth,
> > intThumbHeight);
> >
> > Bitmap imgOutput = new Bitmap(myBitmap, fitImageSize.Width,
> > fitImageSize.Height);
> >
> > imgOutput.Save(Server.MapPath(sSavePath + sThumbFile),
> > System.Drawing.Imaging.ImageFormat.Jpeg);
> >
> > But its the third aspect that is tricky,
> >
> > Cheers all.
> >
> >
>
>



Nov 16 '05 #7
Hi Matt,

Thank you very much for your help, I'm sure i have enough info now :D

"Matt Burland" <wjousts@[no spam]hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP09.phx.gbl...
Chris,

I believe you need the DrawImage function of the Graphics object. You can
create a Graphics object using Graphics.FromImage (using your new image) and draw your thumbnail onto it. Check out the Graphics object in MSDN.
I did something similar myself a while back, but I don't remember exactly
what I did and I don't have the code handy right now.

Matt

"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:uH**************@TK2MSFTNGP10.phx.gbl...
Hi Matt,

Thats a great idea but I can't seem to find any suitable methods for

copying
into the second bitmap.

Can anyone help ?

Thanks,

Chris.
"Matt Burland" <wjousts@[no spam]hotmail.com> wrote in message
news:eh*************@tk2msftngp13.phx.gbl...
You should be able to create a new bitmap which is the exact size of the
box
your are trying to fill. Make that bitmap one solid color, white for
example, and then copy your thumbnail into the center of the new
bitmap. Then save the new bitmap as your thumbnail. You'd have to calculate where
to
place your thumbnail based on which of it's dimensions are too small.

"Chris Perry" <ch***@pushnet.co.uk> wrote in message
news:ue*************@TK2MSFTNGP12.phx.gbl...
> Hi Abdellah,
>
> Thanks for your reply. I do have a function that calculates the best

fit for
> the thumbnail,. thats my 'GetScaledImageDimensions'
>
> However I want the total thumbnail size to be the size of the 'box' but > contain the scaled image inside it and have the parts where it's too

small
> be white or tranparent.
>
> Its so I dont break the designers precious layout ;)
>
>
> ----------------------------
> | |<----- transparent
> | |
> |-------------------------- |
> | |
> | thumb |
> |-------------------------- |
> | |
> |-------------------------- |
>
> Thanks
>
>
> "A. Elamiri" <abdellahDOTelamiriATclintonDOTedutNOSPAM> wrote in message > news:eU**************@TK2MSFTNGP12.phx.gbl...
> > You should calculate the resizing Ratio... It is not possible to
fit it
in
> a
> > box exactly unless all your images have the width=height
> > otherwise you find out what the ratio is for the new width to the

old > width,
> > then you use that ratio to calculate the new height.
> >
> > This will ensure that your image is proportional. I have some code

that
> does
> > that, if you want I'll post it here
> >
> >
> > Hope that helps
> >
> > --
> > Abdellah Elamiri
> > .net Developer
> > Efficacy through simplicity
> > "Chris Perry" <ch***@pushnet.co.uk> wrote in message
> > news:uo**************@TK2MSFTNGP12.phx.gbl...
> > > How do you create a thumbnail constrained to a box, without

distorting
> and
> > > but making where it doesn't fill the box transparent.
> > >
> > > I'm two thirds there :
> > >
> > > Size fitImageSize = this.GetScaledImageDimensions(
> > > myBitmap.Width, myBitmap.Height,
> > intThumbWidth,
> > > intThumbHeight);
> > >
> > > Bitmap imgOutput = new Bitmap(myBitmap, fitImageSize.Width,
> > > fitImageSize.Height);
> > >
> > > imgOutput.Save(Server.MapPath(sSavePath + sThumbFile),
> > > System.Drawing.Imaging.ImageFormat.Jpeg);
> > >
> > > But its the third aspect that is tricky,
> > >
> > > Cheers all.
> > >
> > >
> >
> >
>
>



Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike | last post by:
Sites using thumbnail preview for world wide web file navigation and searching. Below are list of sites that are either researching or providing thumbnail preview images for online web...
4
by: Jim Ford | last post by:
I have a single C file with the following code: int f2() { /* Blah-blah */ } int f1() { /* Blah-blah */
1
by: Xah Lee | last post by:
The following is a program to generate thumbnail images for a website. Useful, if you want to do that. It is used to generate the thumbnails for my “Banners, Damsels, and Mores” project...
8
by: barb | last post by:
So that the world at large benefits from our efforts, here is one fully documented way to use Windows Irfanview freeware to create thumbnail web galleries (http://www.irfanview.com). STEP 1:...
11
by: Jane | last post by:
Hi, I need some help (php rookie) to build a thumbnail page using php. I'v a mysql database containing links to the original image files. No thumbnails created so far. It would be nice when...
7
by: oscartheduck | last post by:
Hi folks, I'm trying to alter a program I posted about a few days ago. It creates thumbnail images from master images. Nice and simple. To make sure I can match all variations in spelling of...
8
by: Arno R | last post by:
Hi all. When I need to search for pictures, I always have too choose thumbnail-view manually. Is it possible to open the common dialog in thumbnail-view programmatically? Example ?? At the...
15
tlhintoq
by: tlhintoq | last post by:
I'd like to think I can work out most issues, but this one is kicking my butt. What's worse, is that I know I can't be the first guy to want to add a thumbnail to jpg that doesn't already have one. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.