Click here to Skip to main content
15,907,326 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionThe underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel Pin
Bluebamboo8-Jul-08 2:46
Bluebamboo8-Jul-08 2:46 
QuestionProblem saving a resized image - HELP!! Pin
Member 34028868-Jul-08 2:38
Member 34028868-Jul-08 2:38 
AnswerRe: Problem saving a resized image - HELP!! Pin
windhopper8-Jul-08 2:46
windhopper8-Jul-08 2:46 
GeneralRe: Problem saving a resized image - HELP!! Pin
Member 34028868-Jul-08 2:52
Member 34028868-Jul-08 2:52 
GeneralRe: Problem saving a resized image - HELP!! Pin
Herman<T>.Instance8-Jul-08 2:55
Herman<T>.Instance8-Jul-08 2:55 
GeneralRe: Problem saving a resized image - HELP!! Pin
Member 34028868-Jul-08 3:01
Member 34028868-Jul-08 3:01 
GeneralRe: Problem saving a resized image - HELP!! Pin
Sherin Iranimose8-Jul-08 3:03
Sherin Iranimose8-Jul-08 3:03 
GeneralRe: Problem saving a resized image - HELP!! Pin
Member 34028868-Jul-08 3:19
Member 34028868-Jul-08 3:19 
I am using populating a ListBox with the files I want to resize and when the user clicks a button, the method goProcessImages is called and I traverse through each one resizing it (well I'm trying to!). Thanks - here is my code behind (sorry it's a bit of a mess but I've been commenting out things to find out what's going wrong):

using System;
using System.Collections;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;

public partial class ResizeImage : System.Web.UI.Page
{
ArrayList imageNames = new ArrayList();
string imagesDir = "D:\\Website\\BookImages\\";
//get path of Books dir in website

protected void Page_Load(object sender, EventArgs e)
{
string imgForLB = "";
if (!IsPostBack)
{
int i = 0;

try
{
foreach (string img in Directory.GetFiles(imagesDir, "*.jpg"))
{
imageNames.Add(img.Remove(0, 22));
}
foreach (string img in Directory.GetFiles(imagesDir, "*.jpeg"))
{
imageNames.Add(img.Remove(0, 22));
}
foreach (string img in Directory.GetFiles(imagesDir, "*.gif"))
{
imageNames.Add(img.Remove(0, 22));
}
}
catch
{
Response.Write("We are currently experiencing problems in obtaining images from the directory " +
imagesDir + "Make sure you are offline and this directory exists on your laptop and it is not empty.");
}

//write out image names to screen for Angell to check
for (i = 0; i &lt; imageNames.Count; i++)
lbFileNames.Items.Add(imageNames[i].ToString());
}

}

// Required by GetThumbnailImage() method, but not used
public bool ThumbnailCallback()
{
return true;
}

protected void goProcessImages(object sender, EventArgs e)
{
string imageName = "";

//resize each file listed in listbox
foreach (ListItem item in lbFileNames.Items)
{
imageName = item.ToString();

if (imageName != "")
{
//createThumbnail(imageName, 400);
createThumbnail(imageName, 100);
}
}
}



protected void createThumbnail(string imgName, int newHeight)
{
string pathToFile = Server.MapPath("Images/Books/");
int origHeight = 0;
int origWidth = 0;
string thumbImgName = "";
string existsFilePath = "";
bool imageExists = false;
//get path of Books dir in website

string imgFullPath = "";
string fullPath = "";

//Once we have an instance of the Image class we can determine the height and width
//of the image by checking the Height and Width properties.
if (newHeight == 100)
thumbImgName = imgName.Replace(".", "-s.");
else
thumbImgName = imgName;

//path of image to retrieve (before resizing)
imgFullPath = imagesDir + imgName;
Response.Write("full path of image is " + imgFullPath);
//path of image to save (after resizing)
fullPath = pathToFile + thumbImgName;

//imgFullPath = imagesDir + imgName;
//try
//{
// create an image object, using the filename we just retrieved
System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(imgFullPath);
//}
//catch
//{
//Response.Write("We are experiencing problems with the server at the moment.&lt;br /&gt;" +
//"Please try again later.");
//}

//get orig height
origHeight = fullSizeImg.Height;
//get orig width
origWidth = fullSizeImg.Width;
float newWidthFloat = ((float)newHeight / (float)origHeight) * (float)origWidth;
int newWidth = Convert.ToInt32(newWidthFloat);

//check in case there is already an image with this name in website
existsFilePath = pathToFile + thumbImgName;
Response.Write(existsFilePath);
if (File.Exists(existsFilePath))
{
imageExists = true;
//need confirmation message
}
//if image height &gt; the new target height, resize
//if (origHeight &gt; newHeight)
//{
try
{
// create the actual thumbnail image
System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
}
catch
{
if (newHeight == 100)
{
Response.Write("We are experiencing problems with the server at the moment.&lt;br /&gt;A thumbnail version of " + imgName + " has not been created. Please try again later.");
}
else
{
Response.Write("We are experiencing problems with the server at the moment.&lt;br /&gt;" + imgName + " has not been resized. Please try again later.");
}
}
//try
//{
//save to website Books dir
//if (thumbNailImg != null)
thumbNailImg.Save(fullPath);
//}
//catch
//{
// Response.Write("We are experiencing problems with the server at the moment.&lt;br /&gt;" + thumbImgName + " has not been saved to the website. Please try again later.");
//}
//Clean up / Dispose...
//thumbNailImg.Dispose();

//}
//else
//{
//try
//{
//save original image to website Books dir
//fullSizeImg.Save(fullPath);
//}
//catch
//{
//Response.Write("We are experiencing problems with the server at the moment.&lt;br /&gt;" + thumbImgName + " has not been saved to the website. Please try again later.");
//}
//Clean up / Dispose...
//fullSizeImg.Dispose();
//}
}
}
GeneralRe: Problem saving a resized image - HELP!! Pin
Sherin Iranimose8-Jul-08 4:24
Sherin Iranimose8-Jul-08 4:24 
GeneralRe: Problem saving a resized image - HELP!! Pin
Member 34028868-Jul-08 22:42
Member 34028868-Jul-08 22:42 
GeneralRe: Problem saving a resized image - HELP!! Pin
Sherin Iranimose8-Jul-08 3:02
Sherin Iranimose8-Jul-08 3:02 
AnswerRe: Problem saving a resized image - HELP!! Pin
N a v a n e e t h8-Jul-08 3:21
N a v a n e e t h8-Jul-08 3:21 
QuestionHow to convert decimal ? Pin
King Shez8-Jul-08 2:37
King Shez8-Jul-08 2:37 
AnswerRe: How to convert decimal ? Pin
Herman<T>.Instance8-Jul-08 2:53
Herman<T>.Instance8-Jul-08 2:53 
GeneralRe: How to convert decimal ? Pin
King Shez8-Jul-08 3:02
King Shez8-Jul-08 3:02 
GeneralRe: How to convert decimal ? Pin
King Shez8-Jul-08 3:03
King Shez8-Jul-08 3:03 
GeneralRe: How to convert decimal ? Pin
Herman<T>.Instance8-Jul-08 3:07
Herman<T>.Instance8-Jul-08 3:07 
GeneralRe: How to convert decimal ? Pin
King Shez8-Jul-08 3:09
King Shez8-Jul-08 3:09 
Questiondate function in as p.net 2.0 Pin
vijaylumar8-Jul-08 2:35
vijaylumar8-Jul-08 2:35 
AnswerRe: date function in as p.net 2.0 Pin
eyeseetee8-Jul-08 2:38
eyeseetee8-Jul-08 2:38 
QuestionSend email to multiple people from database (asp.net2 c#) Pin
AdamskiR8-Jul-08 2:33
AdamskiR8-Jul-08 2:33 
AnswerRe: Send email to multiple people from database (asp.net2 c#) Pin
eyeseetee8-Jul-08 2:40
eyeseetee8-Jul-08 2:40 
AnswerRe: Send email to multiple people from database (asp.net2 c#) Pin
Ashfield8-Jul-08 3:53
Ashfield8-Jul-08 3:53 
GeneralRe: Send email to multiple people from database (asp.net2 c#) Pin
AdamskiR9-Jul-08 3:09
AdamskiR9-Jul-08 3:09 
GeneralRe: Send email to multiple people from database (asp.net2 c#) Pin
Ashfield9-Jul-08 9:24
Ashfield9-Jul-08 9:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.