473,698 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1504
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.c omwrote:
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.spac es.live.com/blog/cns!F648CB161AE B2D04!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.co mwrote:
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
1868
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 than threads. In that direction I was searching for some examples/resources/tools which can help me create multi-process implementation. My application does need to pass userdefined class objects to python interpreter. So I guess my...
0
1619
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 is undesirable, how do you turn it off? I have a function that scales forms on the fly (form param). but now i realize that changing the dpi messes up the scaling. i need to take the dpi into consideration but the formulas i've tried don't scale...
1
1813
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 high mega pixel images. Is there any other approach that can be applied to achieve the gray scaling and also have a reasonable performance?
0
1275
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 function of "scaling" in the printer's property dialog. But how can I get the value of this "scaling" in C#.net? Could you tell me the method? Thanks.
0
1210
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 function of "scaling" in the printer's property dialog. But how can I get the value of this "scaling" in C#.net? Could you tell me the method? Thanks.
1
879
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 downloading files from one source location). I am unable to scale the application, while running it on a multiproc machines. So the thoughput i get across a 1 proc, 2 proc, 4 proc and 8 proc is the same. What do i need to look out for scaling...
3
2553
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 blurred. I want the edges all crisp, including inherent pixelation (jaggies). Setting smoothing to none, or adjusting the composting mode on the Graphics object still
17
2641
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 question. I am looking desperately for a way to TRULY scale out SQL server...in the same way that IIS can be scaled out via App Center. The "in the box" solution for SQL Server 2005 scaling out is the DMV. Unfortunately this solution makes...
2
4234
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()); this.craveLoader_mc.getURL("BWC_Crave.swf", "_blank"); } This opens a new window for BWC_Crave.swf ...like I want. But the window scales depending on my current window sizing. If I make my window bigger or smaller, it sizes the flash movie in the window. I want it...
4
1779
by: xDrDoSx | last post by:
does any one have good tutorials or articles on PHP and database scaling?
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.