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
Rajesh Kumar
NA
222
38.9k
Parameter is Not Valid Error
Dec 10 2020 8:53 PM
We are working on Integration project which will get information from SOAP and output getting in byte. now i am trying to write it into memory stream to convert to PDF, but i am getting error message as below
"Parameter is Not Valid"
public
string
getimage(
string
s)
{
// var bytes = s;
byte
[] bytes = Convert.FromBase64String(s);
Image image1;
try
{
using
(var ms =
new
MemoryStream(bytes, 0, bytes.Length))
{
ms.Seek(0, SeekOrigin.Begin);
ms.Position = 0;
using
(image1 = Image.FromStream(ms,
true
))
{
using
(Image imageFile = image1)
{
FrameDimension frameDimensions =
new
FrameDimension(
imageFile.FrameDimensionsList[0]);
int
frameNum = imageFile.GetFrameCount(frameDimensions);
string
[] jpegPaths =
new
string
[frameNum];
PdfDocument doc =
new
PdfDocument();
for
(
int
frame = 0; frame < frameNum; frame++)
{
imageFile.SelectActiveFrame(frameDimensions, frame);
doc.Pages.Add(
new
PdfPage());
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[frame]);
using
(Bitmap bmp =
new
Bitmap(imageFile))
{
using
(var ms11 =
new
MemoryStream())
{
bmp.Save(ms11, System.Drawing.Imaging.ImageFormat.Png);
XImage img = XImage.FromStream(ms11);
PdfPage page =
new
PdfPage();
xgr.DrawImage(img, 0, 0, 595, 842);
}
}
}
byte
[] fileContents =
null
;
using
(MemoryStream stream =
new
MemoryStream())
{
doc.Save(stream,
true
);
fileContents = stream.ToArray();
}
TempData[
"file"
] = Convert.ToBase64String(fileContents);
doc.Close();
return
Convert.ToBase64String(fileContents);
}
}
}
}
catch
(Exception ex)
{
throw
ex;
}
}
Can someone suggest me what is wrong here here is my code as well. Getting error in row number 10.
Reply
Answers (
4
)
need explanation C# below code
What happens internally when delegate calls attached method