473,385 Members | 2,274 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.

Scaling JPG files

I have done a Google search on this, and the hits seem to indicate
that there's probably not a computationally easy way to do it, but
I'll ask anyway before I go off and re-invent the wheel.

I have user control do display a specified image file (.jpg) from a
database. Files may have arbitrary height, width, and aspect ratios.
I have height and width properties on the control to fit the image
display into the appropriate space on the page. But I would like to
do that while maintaining the aspect ratio of the original image,
rather than just leaving it up to the browser to scale to the
specified height and width. This would require me to adjust the
requested height and width property to maintain the aspect ratio of
the original file, which I have no problem with... except that I don't
have an easy way get the original height and width.

Is there an easy way to do this in ASP.NET? I don't mind writing code
in the code-behind file to do it, but is there a way to do it without
reading in the whole JPG file (and then reading it again when it's
loaded by the HTML)? It seems like this would be a fairly common
problem, so I'm sure there are some classes out there to do it, maybe
even within .NET itself, though the impression I got from the Google
hits was that the JPEG file format definition is such that you're
going to have read the whole file (or most of it) to extract the
information.

Is this computationally intensive enough to make it worth storing in a
database table and looking it up first, only reading the file to find
it if it's not in the DB table (and then adding it)?
Sep 1 '08 #1
4 1499
daveh551 wrote:
I have done a Google search on this, and the hits seem to indicate
that there's probably not a computationally easy way to do it, but
I'll ask anyway before I go off and re-invent the wheel.

I have user control do display a specified image file (.jpg) from a
database. Files may have arbitrary height, width, and aspect ratios.
I have height and width properties on the control to fit the image
display into the appropriate space on the page. But I would like to
do that while maintaining the aspect ratio of the original image,
rather than just leaving it up to the browser to scale to the
specified height and width. This would require me to adjust the
requested height and width property to maintain the aspect ratio of
the original file, which I have no problem with... except that I don't
have an easy way get the original height and width.

Is there an easy way to do this in ASP.NET? I don't mind writing code
in the code-behind file to do it, but is there a way to do it without
reading in the whole JPG file (and then reading it again when it's
loaded by the HTML)? It seems like this would be a fairly common
problem, so I'm sure there are some classes out there to do it, maybe
even within .NET itself, though the impression I got from the Google
hits was that the JPEG file format definition is such that you're
going to have read the whole file (or most of it) to extract the
information.

Is this computationally intensive enough to make it worth storing in a
database table and looking it up first, only reading the file to find
it if it's not in the DB table (and then adding it)?
What you want to do is create a new aspx page. The whole purpose of
this page is to serve the images.

The following link will give you a start. In the link there is a
querystring used. That would be the key to your image in the database:

http://www.sitepoint.com/article/gen...net-images-fly
Hope this helps
LS
Sep 1 '08 #2
On Sep 1, 8:28*pm, daveh551 <gee...@gmail.comwrote:
I have done a Google search on this, and the hits seem to indicate
that there's probably not a computationally easy way to do it, but
I'll ask anyway before I go off and re-invent the wheel.

I have user control do display a specified image file (.jpg) *from a
database. Files may have arbitrary height, width, and aspect ratios.
I have height and width properties on the control to fit the image
display into the appropriate space on the page. *But I would like to
do that while maintaining the aspect ratio of the original image,
rather than just leaving it up to the browser to scale to the
specified height and width. *This would require me to adjust the
requested height and width property to maintain the aspect ratio of
the original file, which I have no problem with... except that I don't
have an easy way get the original height and width.

Is there an easy way to do this in ASP.NET? *I don't mind writing code
in the code-behind file to do it, but is there a way to do it without
reading in the whole JPG file (and then reading it again when it's
loaded by the HTML)? *It seems like this would be a fairly common
problem, so I'm sure there are some classes out there to do it, maybe
even within .NET itself, though the impression I got from the Google
hits was that the JPEG file format definition is such that *you're
going to have read the whole file (or most of it) to extract the
information.

Is this computationally intensive enough to make it worth storing in a
database table and looking it up first, only reading the file to find
it if it's not in the DB table (and then adding it)?
Try to read just some fist bytes and get the dimensions from header.
There's plenty of documentation about JPG format online. Here are some
examples on how to get the information from header:

http://quilt.ic.cz/tmp/devfus/ImageInfo.rar
http://sipostamas.spaces.live.com/blog/cns!F648CB161AEB2D04!157.entry
Sep 1 '08 #3
daveh551 wrote:
I have done a Google search on this, and the hits seem to indicate
that there's probably not a computationally easy way to do it, but
I'll ask anyway before I go off and re-invent the wheel.

I have user control do display a specified image file (.jpg) from a
database. Files may have arbitrary height, width, and aspect ratios.
I have height and width properties on the control to fit the image
display into the appropriate space on the page. But I would like to
do that while maintaining the aspect ratio of the original image,
rather than just leaving it up to the browser to scale to the
specified height and width. This would require me to adjust the
requested height and width property to maintain the aspect ratio of
the original file, which I have no problem with... except that I don't
have an easy way get the original height and width.

Is there an easy way to do this in ASP.NET? I don't mind writing code
in the code-behind file to do it, but is there a way to do it without
reading in the whole JPG file (and then reading it again when it's
loaded by the HTML)? It seems like this would be a fairly common
problem, so I'm sure there are some classes out there to do it, maybe
even within .NET itself,
There is nothing in the framework for this. You can easily get the
information, but not without also decompressing the image data.
though the impression I got from the Google
hits was that the JPEG file format definition is such that you're
going to have read the whole file (or most of it) to extract the
information.
You only need a small part of the file to get the image dimensions, but
as the JPEG format is flexible you don't know beforehand where in the
file that information is located. You may have to skip through several
sections of the file to get to the right one.
Is this computationally intensive enough to make it worth storing in a
database table and looking it up first, only reading the file to find
it if it's not in the DB table (and then adding it)?
Yes, I would definitely store the image dimensions in the database.

You should also consider creating the thumbnail images on the server
instead of letting the browser scale the image. This reduces the
bandwidth usage, and the image quality of the thumbnails gets much better.

--
Göran Andersson
_____
http://www.guffa.com
Sep 2 '08 #4
On Sep 2, 3:36*am, Göran Andersson <gu...@guffa.comwrote:
daveh551 wrote:
I have done a Google search on this, and the hits seem to indicate
that there's probably not a computationally easy way to do it, but
I'll ask anyway before I go off and re-invent the wheel.
I have user control do display a specified image file (.jpg) *from a
database. Files may have arbitrary height, width, and aspect ratios.
I have height and width properties on the control to fit the image
display into the appropriate space on the page. *But I would like to
do that while maintaining the aspect ratio of the original image,
rather than just leaving it up to the browser to scale to the
specified height and width. *This would require me to adjust the
requested height and width property to maintain the aspect ratio of
the original file, which I have no problem with... except that I don't
have an easy way get the original height and width.
Is there an easy way to do this in ASP.NET? *I don't mind writing code
in the code-behind file to do it, but is there a way to do it without
reading in the whole JPG file (and then reading it again when it's
loaded by the HTML)? *It seems like this would be a fairly common
problem, so I'm sure there are some classes out there to do it, maybe
even within .NET itself,

There is nothing in the framework for this. You can easily get the
information, but not without also decompressing the image data.
though the impression I got from the Google
hits was that the JPEG file format definition is such that *you're
going to have read the whole file (or most of it) to extract the
information.

You only need a small part of the file to get the image dimensions, but
as the JPEG format is flexible you don't know beforehand where in the
file that information is located. You may have to skip through several
sections of the file to get to the right one.
Is this computationally intensive enough to make it worth storing in a
database table and looking it up first, only reading the file to find
it if it's not in the DB table (and then adding it)?

Yes, I would definitely store the image dimensions in the database.

You should also consider creating the thumbnail images on the server
instead of letting the browser scale the image. This reduces the
bandwidth usage, and the image quality of the thumbnails gets much better..

--
Göran Andersson
_____http://www.guffa.com
Thank you all for your responses. This will give me some valuable
guidance as I implement this.
Sep 2 '08 #5

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

Similar topics

1
by: Atul Kshirsagar | last post by:
Hello, GIL prevents my C++ application embedding and extending python to scale even though I spawn multiple C++ threads. I read lot of references on internet about using multiple processes rather...
0
by: Colin | last post by:
Hi, It seems vs.net does some automatic scaling in the ide. like if i take a project develloped under 96 dpi low res and load it under 120 dpi hi res it does all kinds of automatic resizing. this...
1
by: susie_richie_30 | last post by:
Hi, I am trying to apply gray scaling to color as well as black/white images. I have tried using the pixel by pixel approach to achieve the scaling. But the particular approach has a issue with...
0
by: Steven | last post by:
Hello, I have a problem in scaling printing. I use standard print dialog. When I click the button of "Property" in this dialog, it shows the printer's property dialog. As usual, there is a...
0
by: Steven | last post by:
Hello, I have a problem in scaling printing. I use standard print dialog. When I click the button of "Property" in this dialog, it shows the printer's property dialog. As usual, there is a...
1
by: Suman | last post by:
Hi I have a application that connects to an ftp server and downloads documents. The application is multithreaded to bring in concurrency for downloading files from different source locations (not...
3
by: Larry Serflaten | last post by:
I am taking a 256 color bitmap from a file and scaling it up X 16 to a 32bppPARGB bitmap in memory. I copy that image to the screen. After scaling, the edges of all the lines and colors are...
17
by: IanIpp | last post by:
We have a 3 month old quad processor/dual core server running SQL Server 2005 and already it is getting close to hitting the CPU wall. An 8 way CPU box is prohibitively expensive and out of the...
2
by: therefor | last post by:
I have the following in Flash 8 BriefLook_mc.btnStudentLife_mc.onRelease = function():Void { this.createEmptyMovieClip("craveLoader_mc", this.getNextHighestDepth()); ...
4
by: xDrDoSx | last post by:
does any one have good tutorials or articles on PHP and database scaling?
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.