TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
vijayaasri palaniappan
NA
117
10.1k
Compressed Image Uploading
May 12 2021 5:17 AM
Hi,
I want to compress my image while I'm Uploading. With the help of the C#Corner Website I got that code. But, I facing the Issue in
Stream strm = ImageFile.PostedFile.InputStream;
// Here It shows error in Input stream
using
(var image = System.Drawing.Image.FromStream(strm))
{
My Full code is here :
public
ActionResult DetailsEdit(EmployeeData___TBL e,
string
id, HttpPostedFileBase ImageFile)
{
var data = Session[
"userid"
].ToString();
if
(e.ImageFile !=
null
)
{
string
filename = Path.GetFileNameWithoutExtension(e.ImageFile.FileName);
string
extension = Path.GetExtension(e.ImageFile.FileName);
HttpPostedFileBase postedfile = e.ImageFile;
int
length = postedfile.ContentLength;
if
(extension.ToLower() ==
".jpg"
|| extension.ToLower() ==
".jpeg"
|| extension.ToLower() ==
".png"
)
{
if
(length <= 1000000)
{
filename = filename + extension;
Stream strm = ImageFile.PostedFile.InputStream;
using
(var image = System.Drawing.Image.FromStream(strm))
{
int
newWidth = 240;
// New Width of Image in Pixel
int
newHeight = 240;
// New Height of Image in Pixel
var thumbImg =
new
Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imgRectangle =
new
Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imgRectangle);
e.ProfileImage =
"~/AppFiles/"
+ filename;
filename = Path.Combine(Server.MapPath(
"~/AppFiles/"
), filename);
e.ImageFile.SaveAs(filename);
// db.Entry(e).State = EntityState.Modified;
// int a = db.SaveChanges();
db.SP_EditUserInfo(data, e.Name, e.EmailID, e.PhoneNo, e.Address, e.ProfileImage);
//TempData["UpdateMessage"] = "<script>alert('Data Updated Successfully.')</script>";
ModelState.Clear();
return
RedirectToAction(
"Details"
,
"Home"
);
}
}
}
else
{
e.ProfileImage = Session[
"Image"
].ToString();
//db.SP_UpdateUserInfo(e.UserId, e.Name, e.EmailID, e.PhoneNo, e.Address, e.ProfileImage);
//db.Entry(e).State = EntityState.Modified;
ModelState.Clear();
return
RedirectToAction(
"List"
,
"Home"
);
}
return
View();
}
}
Reply
Answers (
7
)
CS1056 -Unexpected character "" What does it mean?
Gridview Sorting in C#