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