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

Image Size

Hi,

I have the location of an image in the database and I'm displaying it with
a repeater control. I'd like to add the width and height and I'm not sure
what the best way to do it is. I could add the fields to the database and
lookup the size and enter it. I know with .Net there's a way to find out
the size but I'm not sure how to go about doing it. This is the repeater
control:

<ASP:Repeater id="RepeaterMediaName" runat="server" DataSource="GetImage()">
<ItemTemplate>
<img src='images/<%# DataBinder.Eval (Container.DataItem, "MediaName") %>'
border='0' />
</ItemTemplate>
</ASP:Repeater>

Thanks

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
3 1415
Jim:
You can dynamically get the size of an image via code like:

Bitmap b = new Bitmap(@"c:\karl\test.jpg");
Response.Write(b.Width);
Response.Write(b.Height);
b.Dispose()

Where I to do this, I'd create a custom server control that looked something
like this:

public class MediaImage : HtmlImage
{
private string _mediaImage;

public string mediaImage
{
get { return _mediaImage; }
set { _mediaImage = value; }
}

protected override void Render(HtmlTextWriter writer)
{
base.Src = "images/" + mediaImage;
string filePath = Page.Server.MapPath(base.Src);
Bitmap b = null;
try
{
b = new Bitmap(filePath);
base.Width = b.Width;
base.Height = b.Height;
}
finally
{
if (b != null)
{
b.Dispose();
}
}
base.Render (writer);
}

}
But to be honest, this is a lot of work...you are having to load the image
into memory and get the size. As far as I'm concerned it's (a) better to
store them in the database or (b) not render a width/height and let the
browser deal with it. I don't think I'd ever load an entire bitmap into
memory just to get the width/height...and if I had to specify it, I'd
certainly consider using the database first..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jim via DotNetMonster.com" <fo***@nospam.DotNetMonster.com> wrote in
message news:d8******************************@DotNetMonste r.com...
Hi,

I have the location of an image in the database and I'm displaying it with
a repeater control. I'd like to add the width and height and I'm not sure
what the best way to do it is. I could add the fields to the database and
lookup the size and enter it. I know with .Net there's a way to find out
the size but I'm not sure how to go about doing it. This is the repeater
control:

<ASP:Repeater id="RepeaterMediaName" runat="server" DataSource="GetImage()"> <ItemTemplate>
<img src='images/<%# DataBinder.Eval (Container.DataItem, "MediaName") %>'
border='0' />
</ItemTemplate>
</ASP:Repeater>

Thanks

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #2
Karl,

Thank so much, that's what I was wondering whether it was better and faster
to store the sizes in the database or whether it was more efficient to
retrieve the size dynamically. I've always specified the image size as I
believe the page loads faster if you do. Thanks again.

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #3
If you can store it in the database, do it...the page does load faster if
you specify a width/height for an <img, but you have to ask yourself at what
cost? if you have 50 requests and all are having to do 5-15 width lookups,
you're page might render fast on the browser 'cuz you specified a
width/height, but the server might slow down...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jim via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:6c******************************@DotNetMonste r.com...
Karl,

Thank so much, that's what I was wondering whether it was better and faster to store the sizes in the database or whether it was more efficient to
retrieve the size dynamically. I've always specified the image size as I
believe the page loads faster if you do. Thanks again.

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #4

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

Similar topics

4
by: Ruby Tuesday | last post by:
I have a section(185pixelsx 185pixels) in my web page to display an image that is stored in a directory. Using php, how do you resize so if: the image dimension is smaller(width and height is...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
4
by: no-spam | last post by:
Hello, I have an HTML question that I'm not sure can be solved. I want to restrict the maximum size of an inline image. For example, I can force the image to be 200x200 if I do this: <img...
8
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client...
1
by: John Thompson | last post by:
We're sooo close. When we load the page to upload the image, all of the prms go through except the binary image data. Using SQL server with the data type set to "image". Please help! Thanks-...
6
by: nichughes | last post by:
Hello all, A question relating to http://www.entrust-systems.net/ Just for a change I have run into a problem that seems to be OS specific rather than browser specific - the box image that is...
3
by: =?Utf-8?B?SlIx?= | last post by:
I would like to add text to an image. I have tried to use DrawString and it works on some images but on others it is very very small. I am pretty sure it has something to do with the size of the...
2
by: Adam Teale | last post by:
hey guys Is there a builtin/standard install method in python for retrieving or finding out an image's dimensions? A quick google found me this:...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
2
by: studentofknowledge | last post by:
For some unknown reason ie is placing images I have in a div in a weird way. One image is overlapping another but this problem is not occuring in mozilla. I have looked at my code over and over again...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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.