|
The JSON you're trying to deserialize doesn't match the structure of the class you're trying to deserialize it to.
You can deserialize it to the following class:
private class Signature
{
public List<List<List<double>>> lines { get; set; }
}
var signature = serializer.Deserialize<Signature>(json);
This will give you a single object with a single property called lines . This property is a list containing a single element. That element is a list containing a sequence of lists, each of which contains a pair of numbers.
{
lines: [
[
[156.44, 96.44],
[156.44, 95.33],
[155.33, 94.22],
[154.22, 93.11],
[154.22, 90.89],
[153.11, 89.78],
...
]
]
}
How you map that data to your expected list of SignatureLine objects is unclear, since you haven't provided an example of how you expect to get four integers from two floating point numbers.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you very much for replying. How you said like that i got one object with a single property called lines. Now i need to implement by taking into forloop but i am not able to. below is the code.
foreach (var line in signature)
{
signatureGraphic.DrawLine(pen, line.lx, line.ly, line.mx, line.my);
}
to get into for loop we have to add below code or not please specify
private class SignatureLine
{
public int lx { get; set; }
public int ly { get; set; }
public int mx { get; set; }
public int my { get; set; }
}
after this it will return
return signatureImage;
again it will come to default page as shown in below code as a bitmap
var signatureImage = sigToImg.SigJsonToImage(json);
then this signatureImage is system.drawing.bitmap and i need to save as image as follows
Bitmap bmp = new Bitmap(signatureImage);
bmp.Save(Server.MapPath("images\\s1.jpg"), ImageFormat.Jpeg);
bmp.Dispose();
but i am not able to get into for loop.
How to achieve this. Please reply me.
Thanks in advance
|
|
|
|
|
Nope, that still doesn't make any sense to me. Your list contains pairs of floating point numbers; how do you intend to get four integer values from that?
For example, the first value in your list is: [156.44, 96.44]
Given those two numbers, what values are you expecting in the lx , ly , mx and my properties of the SignatureLine class?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I dont know i got code while searching, i think we are at end stage and can we change so that it has to work by changing signatureGraphic.DrawLine parameter
signatureGraphic.SmoothingMode = SmoothingMode.AntiAlias;
foreach (var lines in signature)
{
signatureGraphic.DrawLine(pen, lines.lx, line.ly, line.mx, line.my);
}
so that signatureGraphic can draw line.
Please reply.
thanks in advance
|
|
|
|
|
You still haven't explained how you are expecting to get four integers out of each pair of floating-point numbers. Without that information, it is impossible to convert your source data to a series of calls to the DrawLine method.
If you don't know what the data means, then you can't do anything with it!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
actually that is (lx, ly) is the start point of the line, and (mx, my) is the end point of the line.
i think that it is clear. but i dont know how to achieve this. Reply me thanks in advance
modified 5-Feb-14 13:31pm.
|
|
|
|
|
OK, that makes more sense. There's still the slight issue that the JSON is using floating-point numbers but the DrawLine method expects integers, but you can probably ignore that for now.
You'll still need to deserialize to the class I posted previously, but you can use an iterator method to construct the sequence of SignatureLine objects from the data:
private sealed class SignatureLine
{
public int lx { get; set; }
public int ly { get; set; }
public int mx { get; set; }
public int my { get; set; }
}
private class Signature
{
public List<List<List<double>>> lines { get; set; }
public IEnumerable<SignatureLine> SignatureLines
{
get
{
foreach (List<List<double>> stroke in lines)
{
if (stroke.Count == 1) continue;
List<double> lastPoint = stroke[0];
Debug.Assert(lastPoint.Count == 2);
foreach (List<double> point in stroke.Skip(1))
{
Debug.Assert(point.Count == 2);
yield return new SignatureLine
{
lx = (int)Math.Round(lastPoint[0]),
ly = (int)Math.Round(lastPoint[1]),
mx = (int)Math.Round(point[0]),
my = (int)Math.Round(point[1])
};
lastPoint = point;
}
}
}
}
}
...
var serializer = new JavaScriptSerializer();
var signature = serializer.Deserialize<Signature>(json);
foreach (SignatureLine line in signature.SignatureLines)
{
signatureGraphic.DrawLine(pen, line.lx, line.ly, line.mx, line.my);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Now it is looping inside and also values are getting
public Bitmap SigJsonToImage(string json)
{
var signatureImage = GetBlankCanvas();
if (!string.IsNullOrEmpty(json))
{
using (var signatureGraphic = Graphics.FromImage(signatureImage))
{
signatureGraphic.SmoothingMode = SmoothingMode.AntiAlias;
var pen = new Pen(PenColor, PenWidth);
var serializer = new JavaScriptSerializer();
var signature = serializer.Deserialize<signature>(json);
foreach (SignatureLine line in signature.SignatureLines)
{
signatureGraphic.DrawLine(pen, line.lx, line.ly, line.mx, line.my);
}
}
}
return signatureImage;
}
private Bitmap GetBlankCanvas()
{
var blankImage = new Bitmap(CanvasWidth, CanvasHeight);
blankImage.MakeTransparent();
using (var signatureGraphic = Graphics.FromImage(blankImage))
{
signatureGraphic.Clear(BackgroundColor);
}
return blankImage;
}
private sealed class SignatureLine
{
public int lx { get; set; }
public int ly { get; set; }
public int mx { get; set; }
public int my { get; set; }
}
private class Signature
{
public List<list<list<double>>> lines { get; set; }
public IEnumerable<signatureline> SignatureLines
{
get
{
foreach (List<list<double>> stroke in lines)
{
if (stroke.Count == 1) continue;
List<double> lastPoint = stroke[0];
Debug.Assert(lastPoint.Count == 2);
foreach (List<double> point in stroke.Skip(1))
{
Debug.Assert(point.Count == 2);
// For now, just round the floating point values to the nearest integer:
yield return new SignatureLine
{
lx = (int)Math.Round(lastPoint[0]),
ly = (int)Math.Round(lastPoint[1]),
mx = (int)Math.Round(point[0]),
my = (int)Math.Round(point[1])
};
lastPoint = point;
}
}
}
}
}
now after returning return signatureImage; to default page, am i doing correctly to save as image because i am getting blank image the code used is as follows
var signatureImage = sigToImg.SigJsonToImage(json);
Bitmap bmp = new Bitmap(signatureImage);
bmp.Save(Server.MapPath("images\\s1.jpg"), ImageFormat.Jpeg);
bmp.Dispose();
i am getting blank image. how to achieve this. Reply me thanks in advance
modified 6-Feb-14 1:50am.
|
|
|
|
|
Since the signatureImage is already a Bitmap , I'm not sure why you're creating a new Bitmap to save it; you should be able to use:
signatureImage.Save(Server.MapPath("~/images/s1.jpg"), ImageFormat.Jpeg);
Other than that, there's no obvious problem with the code that's saving the image. You'll need to step through your code to check that you're getting the values out of the JSON, that the pen you're using has a suitable colour and width, and that the lines you're drawing are within the bounds of the picture.
The last point is particularly important; if all the lines you're drawing are outside the bounds of the picture, then you won't be able to see them.
I've just run your code to a 200 x 200 pixel canvas, using a 1 pixel black pen on a white background, and I get an image with a hand-drawn "S" on it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 6-Feb-14 7:48am.
|
|
|
|
|
thank you very much, like you have said, i changed picel to width 400 and height 200 and pen size 4 and now am able to get the image. I really liked your response.
can i have ur email id if u dont mind so that next time if i get any other work doubt i can send a amail.
thanks once again.
|
|
|
|
|
Glad to hear you got it sorted.
If you have any future questions, please post them to the forums. That way, more people can see and potentially answer the questions.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ok. Thank you very much once again.
|
|
|
|
|
Hi now i am trying to pass that image url from default page to html page as follows
public string path = "images/s1.jpg";
and in html
while loading only image has to display
but i am not getting, blank image i am getting.
even if i add source directly in html like below
if i see in design view image will show and if i send that html file mail as shown below
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From = new MailAddress("emailid");
mail.To.Add("emailid");
mail.IsBodyHtml = true;
mail.Subject = "Policy Acceptance";
string FilePath = Server.MapPath("~/sendmail.htm");
FileStream f1 = new FileStream(FilePath, FileMode.Open);
StreamReader sr = new StreamReader(f1);
string str = sr.ReadToEnd();
str = str.Replace("[[[user]]]", "name");
f1.Close();
mail.Body = str;
SmtpClient smtp = new SmtpClient("server ip", portnumber);
smtp.Send(mail);
after sending mail, mail will recieve but image will like blank.
I need to pass the image url from default page to html page, whlile html file loading only it has to show image and after sending that html mail image has to display in that mail.
how to achieve this. reply me, thanks in advance.
modified 7-Feb-14 5:17am.
|
|
|
|
|
hi now i aded LinkedResource myimage = new LinkedResource(serpath);
// Create HTML view
AlternateView htmlMail = AlternateView.CreateAlternateViewFromString(str, null, "text/html");
// Set ContentId property. Value of ContentId property must be the same as
// the src attribute of image tag in email body.
myimage.ContentId = "companylogo";
htmlMail.LinkedResources.Add(myimage);
mail.AlternateViews.Add(htmlMail);
so it sorted out and image is embedding to HTML and is working from default page only by accessing html page.
but one problem is again if i redraw or overwrite the image after mail sending i am trying to delete that file by using folowing code
if (System.IO.File.Exists(serpath))
{
System.IO.File.Delete(serpath);
}
but it is giving The process cannot access the file serpath because it is being used by another process.
How to resolve this. Reply me , thanks in advance.
if i create new image with different name means it creating and saving but once again if try for same image name am getting following error
An exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll but was not handled in user code
Additional information: A generic error occurred in GDI+.
i need to overwrite same image also.
how to resolve this Reply me , thanks in advance.
modified 7-Feb-14 13:17pm.
|
|
|
|
|
Make sure you're calling Dispose on the MailMessage instance after you've sent it. The simplest approach is to wrap it in a using block:
using (MailMessage mail = new MailMessage())
{
...
SmtpClient smtp = new SmtpClient();
smtp.Send(mail);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello there !!
I'm currently working in a .NET project in wich I have to use 3 layers and MVC .I was wondering if you guys have any good example that illustrates how to create such a project . I'm not searching for the meaning or wath these architecture can do , I know that .
Just an example !!
thanks
|
|
|
|
|
Bottom answer on SO[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
hey ,
Thanks for your reponse , but as I mentionned earlier I was looking for a concrete example , not an explanation of a 3 layer architecture
|
|
|
|
|
You're right - my apologies. Made even two mistakes in a single post
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
A pretty decent demonstration application showing ASP MVC along with an n-tier architecture is available at ProDinner[^]
|
|
|
|
|
|
We have a web service developed based on .net framework 4.0 and runs on Windows 2008 x64. The purpose of the web service is to emulate data abstraction layer communicating to the backend/downstream applications such as databases, external soap services, FTP, etc. Upstream .net apps will consume the services from this web service.
Though the application is compiled for x64 code, we are hitting the memory wall @ 2GB and it becomes sluggish with falling response times for upstream apps (resulting in timeouts at peak loads). We also see '% time in GC' is more than 50%. We have 8 GB RAM and 4 CPUs. I am feeling that 2GB limit is holding it for better performance. What am I missing?
What are the configuration parameters that are to be tuned for better throughputs?
Thanks for any advise.
Pingala
|
|
|
|
|
There are no configuration parameters to tune. The Garbage Collector is self tuning.
What is more probable is that your code is leaking resources somewhere. Rule of thumb is that if you create an instance of some class that implements IDisposable, make sure you call it when you don't need the object any more.
modified 31-Jan-14 19:46pm.
|
|
|
|
|
This sounds like a performance issue due to memory leak and that means the possibilities are many. I would suggest start by taking a memory dump and analyze it.
Frankly, one can write 100s of possible things to check. Such as
Parse IIS Logs and see which screens and hence which services are most used at peak time load. [Use log parser for this]
Parse IIS Logs and see which screens and hence which services have high response times at peak time load.
Any increase in specific errors logged in event viewer on the service layer that are unusually high in number at peak times?
Any 3rd party interfaces causing slowness causing requests piling up at your end causing high memory usage?
I am assuming you have ruled out any hardware issue already -
such as high CPU usage causing gradual memory spike
network congestion causing memory spike as requests pile up
DB connectivity and/or performance is good enough not to cause resources waiting on your end to cause memory spike
Hope it helps.
Braj
http://coderpanda.blogspot.in
http://pandaxp.wordpress.com
[If you find the articles or solutions useful then please up-vote or recommend them to encourage participation]
|
|
|
|
|
Friends i am designing a editor in that editor i tried adding a menu that can only send email,with from,to,subject and the mail message.I am unable to send mail from yahoo id to gmail id in my application.I dont know why it is not sending.
provide me some help
|
|
|
|