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
Kumar Ravishankar
NA
437
7.9k
crop 4-5 image,before saving in DB,C#,JQuery
Feb 6 2018 11:22 PM
I have to be upload 4-5 image, and have to upload all them , if size is larger then I have to crop all then then save details in db.if I have to upload one image and crop then its fine but getting issue with more than one Image.
public
void
ProcessRequest(HttpContext context)
{
Boolean FileOK =
false
;
Boolean SizeOK =
false
;
try
{
if
(context.Request.Files.Count > 0)
{
BEL_Package objBel =
new
BEL_Package();
string
Output =
string
.Empty;
HttpFileCollection files = context.Request.Files;
for
(
int
i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
string
sImageName = file.FileName;
file.SaveAs(HttpContext.Current.Server.MapPath(
"~/"
+ Path.GetFileName(file.FileName)));
System.Drawing.Bitmap bitmap =
new
System.Drawing.Bitmap(HttpContext.Current.Server.MapPath(
"~/"
+ Path.GetFileName(file.FileName)));
int
iwidth = bitmap.Width;
int
iheight = bitmap.Height;
bitmap.Dispose();
//Info.InnerHtml = "Original Image ";
//Info.InnerHtml = Info.InnerHtml + "
Width:
" + iwidth + "
, Height: " + iheight +
// "
" + hpf.ContentLength / 1024 + "
KB
";
// ONCE WE GOT ALL THE INFORMATION, WE'll NOW PROCESS IT.
// CREATE AN IMAGE OBJECT USING ORIGINAL WIDTH AND HEIGHT.
// ALSO DEFINE A PIXEL FORMAT (FOR RICH RGB COLOR).
System.Drawing.Image objOptImage =
new
System.Drawing.Bitmap(iwidth, iheight, System.Drawing.Imaging.
PixelFormat.Format16bppRgb555);
// GET THE ORIGINAL IMAGE.
using
(System.Drawing.Image objImg =
System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(
"~/"
+ sImageName)))
{
// RE-DRAW THE IMAGE USING THE NEWLY OBTAINED PIXEL FORMAT.
using
(System.Drawing.Graphics oGraphic = System.Drawing.Graphics.FromImage(objOptImage))
{
var _1 = oGraphic;
System.Drawing.Rectangle oRectangle =
new
System.Drawing.Rectangle(0, 0, iwidth, iheight);
_1.DrawImage(objImg, oRectangle);
}
// SAVE THE OPTIMIZED IMAGE.
objOptImage.Save(HttpContext.Current.Server.MapPath(
"~/images/"
+ sImageName), System.Drawing.Imaging.ImageFormat.Png);
objImg.Dispose();
}
objOptImage.Dispose();
// FINALLY SHOW THE OPTIMIZED IMAGE DETAILS WITH SIZE.
System.Drawing.Bitmap bitmap_Opt =
new
System.Drawing.Bitmap(HttpContext.Current.Server.MapPath(
"~/images/"
+ Path.GetFileName(sImageName)));
int
iwidth_Opt = bitmap_Opt.Width;
int
iheight_Opt = bitmap_Opt.Height;
bitmap_Opt.Dispose();
// FOR SIZE.
FileInfo OptImgInfo =
new
FileInfo(HttpContext.Current.Server.MapPath(
"~/images/"
+ Path.GetFileName(sImageName)));
long
lFileSize = OptImgInfo.Length;
// GET THE SIZE IN BYTES.
string
fname;
if
(HttpContext.Current.Request.Browser.Browser.ToUpper() ==
"IE"
|| HttpContext.Current.Request.Browser.Browser.ToUpper() ==
"INTERNETEXPLORER"
)
{
string
[] testfiles = file.FileName.Split(
new
char
[] {
'\\'
});
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
}
string
path = context.Server.MapPath(
"~/Admin/AllPackageImages/"
);
fname = Path.Combine(path, fname);
string
PackageId = HttpContext.Current.Request.Form[
"PackageId"
];
int
j;
bool
result =
int
.TryParse(PackageId,
out
j);
if
(result ==
false
)
{
j = GeticonsId(PackageId);
}
else
{
j = Convert.ToInt32(PackageId);
}
objBel.filename = file.FileName; ;
objBel.P_ID_N = Convert.ToInt32(j);
objBel.Mode =
"InsertBanner"
;
objBel.R_ID_N = i;
BAL_PackageINBandInternational objBalII =
new
BAL_PackageINBandInternational();
Output = objBalII.Insert_BannerImages(objBel);
if
(Output.ToLower().Contains(
"successfully"
))
{
file.SaveAs(fname);
context.Response.ContentType =
"text/plain"
;
context.Response.Write(
"File Uploaded Successfully!"
);
}
else
{
context.Response.ContentType =
"text/plain"
;
context.Response.Write(
"Something wrong happened . Pleasde try again!"
);
break
;
}
}
HttpContext.Current.Response.Redirect(
"Admin/CropUserProfile.aspx"
);
}
}
catch
(Exception ex)
{
context.Response.ContentType =
"text/plain"
;
context.Response.Write(
"Something wrong happened . Please try again!"
);
}
}
Reply
Answers (
0
)
Hit Count in website using with image background
Validation failed for one or more entities.