We can't to set the Image Height and Width to 302PX
For this I have a code for File Upload,When a image is large it should be re-sized.
if (FileUpload1.HasFile)
{
//create instance for image class
System.Drawing.Image myimg = default(System.Drawing.Image);
//get uploaded image input stream
myimg = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
//resize it using thumbnailimage method
myimg = myimg.GetThumbnailImage(302, 302, null, IntPtr.Zero);
MemoryStream str = new MemoryStream();
//Save it in the server images folder
myimg.Save(Server.MapPath("~\\images\\" + FileUpload1.FileName), myimg.RawFormat);
Response.Write("Resized image is successfully uploaded in to server images folder");
}
But,When the small image is File Upload it is enlarging the file.I don't want to enlarge the file.
You want to resize the image itself, not just the display?
I did some work on file-upload and resizing some time ago. The routine creates and sizes a thumbnail with maximum width and height, but from an image saved to disk. I've converted the routine to C# - maybe you could adapt it to your situation.
public System.Drawing.Image getAThumb(string theBigImagePath, int intMaxWidth, int intMaxHeight)
{
// We need to determine whether the image is portrait, landscape or square. With this information we can create a proportional thumbnail.
Bitmap theBigImage = new Bitmap(theBigImagePath);
int theBigimageHeight = theBigImage.Height;
int theBigimageWidth = theBigImage.Width;
int newImageHeight = theBigimageHeight;
int newImageWidth = theBigimageWidth;
if ((theBigimageHeight > intMaxHeight) | (theBigimageWidth > intMaxWidth)) {
// The uploded image is bigger than the maximum permitted size.
if ((theBigimageHeight > theBigimageWidth)) {
// Portrait, so calculate the propotional width.
newImageHeight = intMaxHeight;
newImageWidth = Convert.ToInt32(theBigimageWidth / (theBigimageHeight / newImageHeight));
} else if ((theBigimageWidth > theBigimageHeight)) {
// Landscape, so calculate the propotional height.
newImageWidth = intMaxWidth;
newImageHeight = Convert.ToInt32(theBigimageHeight / (theBigimageWidth / newImageWidth));
} else {
// Square, so we'll set the height and width to the smallest of the two defined values.
if ((intMaxWidth >= intMaxHeight)) {
newImageWidth = intMaxHeight;
newImageHeight = intMaxHeight;
} else {
newImageWidth = intMaxWidth;
newImageHeight = intMaxWidth;
}
}
}
System.Drawing.Image pThumbnail = theBigImage.GetThumbnailImage(newImageWidth, newImageHeight, null, IntPtr.Zero);
return pThumbnail;
}
Yashwanths
Member
4 Points
42 Posts
Image
Aug 18, 2012 02:34 PM|LINK
Hi,
In my Web page,I have a Div section with height=302PX and width=302PX.
In another page,I had a File Upload control. When we will upload the image,then the image will be displayed in that Div section.
1.When the image is large,it should be re-size and display in that particular Div section completely.
For Eg:The image size like 350PX*350PX and 1024PX*1024PX, it should be re-size to Div Section size has 302PX*302PX.
2.When the image is Small,it shouldn't be re-size and display in that particular Div section completely.
For Eg:The image size like 50PX*50PX,100PX*100PX and 302PX*302PX ,it shouldn't be re-size and display in that Div section.
For Eg:The image size like 15PX*15PX these will appear very small.But When uploading the file these images also should displayed
completely with as it is in that Div section.But the image will displayed neatly.
3.If there are any tools for these type of conditions using ASP.Net.
Plz reply me ASAP.
<div></div> <div> </div>bpw
Contributor
2258 Points
490 Posts
Re: Image
Aug 18, 2012 09:03 PM|LINK
Hi,
The simplest way to do it would be to set max-width and max-height for the image.
For example:
Or you could assign a CSS class.
It it's a .NET image
These style properties are supported by all recent, major browsers.
Paul
mitja.GTI
Star
11157 Points
2094 Posts
Re: Image
Aug 18, 2012 11:24 PM|LINK
You can set image as a background and use style like in the example:
<%--This image size is 698px X 448px--%> <div style="width:302px;height:302px; background-image: url('http://blog.monitor.us/wp-content/uploads/2012/04/LogoAspNet2.png'); background-size: 100%; background-repeat:no-repeat; border:1px solid black;"> </div> <%--This image size is 142px X 58px--%> <div style="width:302px;height:302px; background-image: url('http://djsolid.net/Media/Default/BlogImages/mvc-logo.png'); background-size: 100%; background-repeat:no-repeat; border:1px solid black;"> </div>mitja.gti | www.mitjagti.com
Yashwanths
Member
4 Points
42 Posts
Re: Image
Aug 20, 2012 05:11 AM|LINK
Hi,
We can't to set the Image Height and Width to 302PX
For this I have a code for File Upload,When a image is large it should be re-sized.
if (FileUpload1.HasFile)
{
//create instance for image class
System.Drawing.Image myimg = default(System.Drawing.Image);
//get uploaded image input stream
myimg = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
//resize it using thumbnailimage method
myimg = myimg.GetThumbnailImage(302, 302, null, IntPtr.Zero);
MemoryStream str = new MemoryStream();
//Save it in the server images folder
myimg.Save(Server.MapPath("~\\images\\" + FileUpload1.FileName), myimg.RawFormat);
Response.Write("Resized image is successfully uploaded in to server images folder");
}
But,When the small image is File Upload it is enlarging the file.I don't want to enlarge the file.
shivanand G ...
Participant
1777 Points
537 Posts
Re: Image
Aug 20, 2012 05:48 AM|LINK
<div>
<image id="imageId" runat="server" ></image>
<div>
while loading page..
public void page_load_event()
{
get image width and height.
imageId.width=width ;
imageId.height=height;
imageId.imageUrl or imageId.src="Path of the image"
}
Thanks.
}
shivanand.G.N (shivu.betta@gmail.com)
bpw
Contributor
2258 Points
490 Posts
Re: Image
Aug 20, 2012 08:29 AM|LINK
You want to resize the image itself, not just the display?
I did some work on file-upload and resizing some time ago. The routine creates and sizes a thumbnail with maximum width and height, but from an image saved to disk. I've converted the routine to C# - maybe you could adapt it to your situation.
public System.Drawing.Image getAThumb(string theBigImagePath, int intMaxWidth, int intMaxHeight) { // We need to determine whether the image is portrait, landscape or square. With this information we can create a proportional thumbnail. Bitmap theBigImage = new Bitmap(theBigImagePath); int theBigimageHeight = theBigImage.Height; int theBigimageWidth = theBigImage.Width; int newImageHeight = theBigimageHeight; int newImageWidth = theBigimageWidth; if ((theBigimageHeight > intMaxHeight) | (theBigimageWidth > intMaxWidth)) { // The uploded image is bigger than the maximum permitted size. if ((theBigimageHeight > theBigimageWidth)) { // Portrait, so calculate the propotional width. newImageHeight = intMaxHeight; newImageWidth = Convert.ToInt32(theBigimageWidth / (theBigimageHeight / newImageHeight)); } else if ((theBigimageWidth > theBigimageHeight)) { // Landscape, so calculate the propotional height. newImageWidth = intMaxWidth; newImageHeight = Convert.ToInt32(theBigimageHeight / (theBigimageWidth / newImageWidth)); } else { // Square, so we'll set the height and width to the smallest of the two defined values. if ((intMaxWidth >= intMaxHeight)) { newImageWidth = intMaxHeight; newImageHeight = intMaxHeight; } else { newImageWidth = intMaxWidth; newImageHeight = intMaxWidth; } } } System.Drawing.Image pThumbnail = theBigImage.GetThumbnailImage(newImageWidth, newImageHeight, null, IntPtr.Zero); return pThumbnail; }