Actually I wish to round corner the Image and then display it in updatePanel...
Without roundcorner functions it's working fine...But when I run the functions for round corner image, its giving File Not Found Error()
My Codes
protected void Timer1_Tick(object sender, EventArgs e)
{
NameValueCollection MyImgList = new NameValueCollection();
MyImgList.Add("Img1", "~/MyImages/Picture1.jpg");
MyImgList.Add("Img2", "~/MyImages/Picture2.jpg");
MyImgList.Add("img3", "~/MyImages/Picture3.jpg");
Random Rnd = new Random();
int Indx = Rnd.Next(0, 4);
path = MyImgList[Indx].ToString();
//LtrImg.Text = "<img src='" + Page.ResolveUrl(path) + "' alt=''/>";
using (System.Drawing.Image imgin = System.Drawing.Image.FromFile(path))
{
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imgin.Width, imgin.Height);
Graphics g = Graphics.FromImage(bitmap);
g.Clear(Color.White);
Brush brush = new System.Drawing.TextureBrush(imgin);
FillRoundedRectangle(g, new Rectangle(0, 0, imgin.Width, imgin.Height), roundedDia, brush);
// done with drawing dispose graphics object.
g.Dispose();
// Stream Image to client.
Response.Clear();
Response.ContentType = "image/pjpeg";
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.End();
// dispose bitmap object.
bitmap.Dispose(); /* May be Here */
}
LtrImg.Text = "<img src='" + Page.ResolveUrl(path) + "' alt=''/>";
}
Thanks for the guidances..
Anyhow I succeeded by the following way..
protected void Timer1_Tick(object sender, EventArgs e)
{ NameValueCollection MyImgList = new NameValueCollection();
MyImgList.Add("MyImage1", "~/MyImages/Picture1.jpg");
MyImgList.Add("MyImage2", "~/MyImages/Picture2.jpg");
MyImgList.Add("MyImage3", "~/MyImages/Picture3.jpg");
Random Rnd = new Random();
int Indx = Rnd.Next(0, 4);
Session["ImgId"] = Indx.ToString();
Image1.ImageUrl = "ImgWebForm.aspx?ImgId="+Indx.ToString().Trim();
}
and then
ImgWebForm.aspx Page_Load()
{
string ImgFileId = Session["ImgId"].ToString();
switch (ImgFileId)
{
case "1":
path = Server.MapPath("~/MyImages/Picture1.jpg");
break;
case "2":
path = Server.MapPath("~/MyImages/Picture2.jpg");
break;
case "3":
path = Server.MapPath("~/MyImages/Picture3.jpg");
break;
}
int roundedDia = 50;
using (System.Drawing.Image imgin = System.Drawing.Image.FromFile(path))
{
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imgin.Width, imgin.Height);
Graphics g = Graphics.FromImage(bitmap);
g.Clear(Color.White);
Brush brush = new System.Drawing.TextureBrush(imgin);
FillRoundedRectangle(g, new Rectangle(0, 0, imgin.Width, imgin.Height), roundedDia, brush);
// done with drawing dispose graphics object.
g.Dispose();
// Stream Image to client.
Response.Clear();
Response.ContentType = "image/pjpeg";
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.End();
// dispose bitmap object.
bitmap.Dispose();
}
public static void FillRoundedRectangle(Graphics g, Rectangle r, int d, Brush b)
{
// anti alias distorts fill so remove it.
System.Drawing.Drawing2D.SmoothingMode mode = g.SmoothingMode;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
g.FillPie(b, r.X, r.Y, d, d, 180, 90);
g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90);
g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90);
g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
g.FillRectangle(b, r.X + d / 2, r.Y, r.Width - d, d / 2);
g.FillRectangle(b, r.X, r.Y + d / 2, r.Width, r.Height - d);
g.FillRectangle(b, r.X + d / 2, r.Y + r.Height - d / 2, r.Width - d, d / 2);
g.SmoothingMode = mode;
}
Let it be useful to someoneelse like me..
Thankyou ...
Related
Trying to create dynamically a series of circles with Javafx. After typing the number of circles i got this:
But actually i want that my circles be in that position:
Here is my code and thanks for any hints!!
int k = 5;
for (int i = 0; i < nbNoeuds; i++) {
Noeudfx circle = new Noeudfx(k * 2, k * 2, 1, String.valueOf(i));
Label id = new Label(String.valueOf(i));
noeuds.getChildren().add(id);
id.setLayoutX(k * 2 - 20);
id.setLayoutY(k * 2 - 20);
id.setBlendMode(BlendMode.DIFFERENCE);
k += 10;
FillTransition ft1 = new FillTransition(Duration.millis(300), circle, Color.RED, Color.BLACK);
ft1.play();
noeuds.getChildren().add(circle);
ScaleTransition tr = new ScaleTransition(Duration.millis(100), circle);
tr.setByX(10f);
tr.setByY(10f);
tr.setInterpolator(Interpolator.EASE_OUT);
tr.play();
}
}
public class Noeudfx extends Circle {
Noeud noeud;
Point point;
Label distance = new Label("distance : infinite");
boolean isSelected = false;
List<Noeudfx> circles = new ArrayList<>();
public Noeudfx(double a, double b, double c, String nom) {
super(a, b, c);
noeud = new Noeud(nom, this);
point = new Point((int) a, (int) b);
circles.add(this);
}
}
Here is my solution:
int nbNoeuds = Integer.parseInt(nodeID.getText());
System.out.println("nnnnn"
+ nbNoeuds);
final Timeline animation = new Timeline(
new KeyFrame(Duration.seconds(.5), (ActionEvent actionEvent) -> {
while (noeuds.getChildren().size() <= nbNoeuds) {
// noeuds.getChildren().remove(0);
int radius =10 ;
noeuds.getChildren().add(
new Circle(
rnd.nextInt(SCENE_SIZE - radius * 2) + radius, rnd.nextInt(SCENE_SIZE - radius * 2) + radius,
radius,
Color.GRAY
)
);
}
})
);
animation.setCycleCount(Animation.INDEFINITE);
animation.play();
animation.setOnFinished((ActionEvent actionevent) -> {
animation.stop();
});
Update: i tried to add label to each circle, the problem was that the number of circles in the screen is not correct i don't know why!
Label id = new Label(String.valueOf(i));
id.setTextFill(Color.CADETBLUE);
id.setAlignment(Pos.CENTER);
Circle circle = new Circle(
rnd.nextInt(SCENE_SIZE - radius * 2) + radius, rnd.nextInt(SCENE_SIZE - radius * 2) + radius,
radius,
Color.GRAY
);
Double a = circle.getCenterX();
Double b = circle.getCenterY();
id.setLayoutX(a - 20);
id.setLayoutY(b - 20);
id.setBlendMode(BlendMode.DIFFERENCE);
noeuds.getChildren().add(id);
noeuds.getChildren().add(circle);
i made one desktop application using asp.net which convert html to PDF.
basically this application used for generate users PDF from database.
process: first of all i am converting all data to html and then convert to PDF using itextsharp but after generating some PDFs it shows blank pages
any idea or anyone face this type of issue
public static void converttopdf(string HtmlStream, List<Tuple<string, string>> tifffiles, List<Tuple<string, string>> pdffilestomerge, string filename, string patientfirstpagestr, string TableofContent, string patientheader, SqlConnection con, string sectiondetails)
{
MemoryStream msOutput = new MemoryStream();
TextReader reader = new StringReader(HtmlStream);
Document document = new Document(PageSize.A4, 30, 30, 42, 44);
string filetogenerate = string.Empty;
if (pdffilestomerge != null && pdffilestomerge.Count > 1)
{
filetogenerate = temppath + filename + "_Temp1.pdf";
}
else
{
filetogenerate = temppath + filename + "_Temp.pdf";
}
PdfWriter writer = PdfWriter.GetInstance(document, new System.IO.FileStream(filetogenerate, System.IO.FileMode.Create));
HTMLWorker worker = new HTMLWorker(document);
document.Open();
worker.StartDocument();
string[] separator = new string[] { #"<br clear='all' style='page-break-before:always'>" };
string[] pages = HtmlStream.Split(separator, StringSplitOptions.None);
foreach (string page in pages)
{
document.NewPage();
System.Collections.ArrayList htmlarraylist = HTMLWorker.ParseToList(new StringReader(page), null);
for (int k = 0; k < htmlarraylist.Count; k++)
{
document.Add((IElement)htmlarraylist[k]);
}
}
using (var ms = new MemoryStream())
{
if (tifffiles != null)
{
int docid = 0;
foreach (var obj in tifffiles)
{
string filepath = obj.Item2.ToString();
WriteLogEntry("bitmap file path : " + filepath);
if (filepath != string.Empty)
{
try
{
Bitmap myBitmap = new Bitmap(filepath);
System.Drawing.Color pixelColor = myBitmap.GetPixel(50, 50);
if (pixelColor.Name == "ff808080")
{
WriteLogEntry("convert image by irfanview :" + filepath);
LaunchCommandLineApp(filepath, temppath + "Test.jpg");
document.NewPage();
var imgStream = GetImageStream(temppath + "Test.jpg");
var image = iTextSharp.text.Image.GetInstance(imgStream);
image.SetAbsolutePosition(10, 80);
image.ScaleToFit(document.PageSize.Width - 60, document.PageSize.Height - 80);
//image.ScaleToFit(document.PageSize.Width - 30, document.PageSize.Height);
if (docid != Convert.ToInt32(obj.Item1))
{
Chunk c1 = new Chunk("#~#DID" + obj.Item1.ToString() + "#~#");
c1.Font.SetColor(0, 0, 0); //#00FFFFFF
c1.Font.Size = 0;
document.Add(c1);
}
document.Add(image);
File.Delete(temppath + "Test.jpg");
}
else
{
document.NewPage();
var imgStream = GetImageStream(filepath);
var image = iTextSharp.text.Image.GetInstance(imgStream);
image.SetAbsolutePosition(10, 80);
image.ScaleToFit(document.PageSize.Width - 60, document.PageSize.Height - 80);
//image.ScaleToFit(document.PageSize.Width - 30, document.PageSize.Height);
if (docid != Convert.ToInt32(obj.Item1))
{
Chunk c1 = new Chunk("#~#DID" + obj.Item1.ToString() + "#~#");
c1.Font.SetColor(0, 0, 0); //#00FFFFFF
c1.Font.Size = 0;
document.Add(c1);
}
document.Add(image);
WriteLogEntry("Image added successfully" + filepath);
}
}
catch
{
document.NewPage();
if (docid != Convert.ToInt32(obj.Item1))
{
Chunk c1 = new Chunk("#~#DID" + obj.Item1.ToString() + "#~#");
c1.Font.SetColor(0, 0, 0); //#00FFFFFF
c1.Font.Size = 0;
document.Add(c1);
}
WriteLogEntry("Image not valid" + filepath);
}
docid = Convert.ToInt32(obj.Item1);
}
}
}
}
worker.EndDocument();
worker.Close();
document.Close();
if (pdffilestomerge != null && pdffilestomerge.Count > 1)
{
string file = temppath + filename + "_Temp.pdf";
mergepdf(file, pdffilestomerge, filetogenerate);
}
PdfReader pdfreader = new PdfReader(temppath + filename + "_Temp.pdf");
Document document1 = new Document(PageSize.A4, 30, 30, 42, 44);
PdfWriter writer1 = PdfWriter.GetInstance(document1, new FileStream(FinalOutputPath + filename + ".pdf", FileMode.Create));
//HeaderFooter footer = new HeaderFooter(new Phrase("Page "), true);
//footer.Alignment = Element.ALIGN_RIGHT;
//footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
//document1.Footer = footer;
//HeaderFooter header = new HeaderFooter(new Phrase(""), true);
//header.Alignment = Element.ALIGN_LEFT;
//header.Border = iTextSharp.text.Rectangle.NO_BORDER;
//document1.Add(header);
document1.Open();
PdfContentByte cb1 = writer1.DirectContent;
PdfImportedPage page1;
string test1 = TableofContent; int TableofContentPageCount = 0; int SectionPageStartNumber = 0;
string lastdocnamestr = "";
for (int t = 1; t <= pdfreader.NumberOfPages; t++)
{
document1.NewPage();
HeaderFooter header = new HeaderFooter(new Phrase(""), true);
header.Alignment = Element.ALIGN_LEFT;
header.Border = iTextSharp.text.Rectangle.NO_BORDER;
HeaderFooter header1 = new HeaderFooter(new Phrase(" "), true);
header1.Alignment = Element.ALIGN_LEFT;
header1.Border = iTextSharp.text.Rectangle.NO_BORDER;
HeaderFooter header2 = new HeaderFooter(new Phrase(" "), true);
header2.Alignment = Element.ALIGN_LEFT;
header2.Border = iTextSharp.text.Rectangle.NO_BORDER;
document1.Add(header);
document1.Add(header1);
document1.Add(header2);
page1 = writer1.GetImportedPage(pdfreader, t);
var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
byte[] pdfcontent = pdfreader.GetPageContent(t);
//PdfDictionary dict = pdfreader.GetPageN(t);
string contentStream = System.Text.Encoding.Default.GetString(pdfcontent);
var contentByte = writer1.DirectContent;
contentByte.BeginText();
contentByte.SetFontAndSize(baseFont, 8);
var multiLineString = "";
var multiLineString1 = "";
string test = getBetween(contentStream, "#~#", "#~#");
if (test.Length > 0)
{
test1 = test1.Replace(test + ".", t.ToString());
DataTable dt = getdocdetailforheader(Convert.ToInt32(test.Replace("DID", "")), con);
if (dt.Rows.Count > 0)
{
multiLineString = dt.Rows[0]["DocumentName"].ToString() + " - " + Convert.ToDateTime(dt.Rows[0]["EncounterDTTM"].ToString()).ToString("MM/dd/yyyy") + " | Owner : " + dt.Rows[0]["Ownername"].ToString();
lastdocnamestr = multiLineString;
WriteLogEntry(multiLineString);
}
if (TableofContentPageCount == 0)
{
TableofContentPageCount = t;
}
}
//if (contentStream.Contains("sectionstart") && SectionPageStartNumber == 0) SectionPageStartNumber = t;
if (lastdocnamestr != string.Empty)
{
multiLineString = lastdocnamestr;
}
//else
//{
// if (TableofContentPageCount == 0)
// {
// multiLineString = "Table of Content";
// }
//}
multiLineString1 = patientheader;
contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, multiLineString, 15, 820, 0);
contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, multiLineString1, 15, 810, 0);
contentByte.EndText();
string relLogo = Directory.GetCurrentDirectory().ToString().Replace("bin", "").Replace("Debug", "").Replace("\\\\", "") + "\\Image\\MFA_LOGO.png";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(relLogo);
jpg.ScaleAbsolute(38f, 38f);
jpg.SetAbsolutePosition(document1.PageSize.Width - 70, 806);
jpg.Alignment = Element.ALIGN_RIGHT;
document1.Add(jpg);
cb1.MoveTo(0, 805);
cb1.LineTo(document1.PageSize.Width, 805);
cb1.Stroke();
cb1.AddTemplate(page1, 0, 0);
}
SectionPageStartNumber = pdfreader.NumberOfPages + 1;
System.Collections.ArrayList htmlarraylist1 = HTMLWorker.ParseToList(new StringReader(sectiondetails), null);
document1.NewPage();
for (int k = 0; k < htmlarraylist1.Count; k++)
{
document1.Add((IElement)htmlarraylist1[k]);
}
document1.Close();
FinalPDF(FinalOutputPath + filename + ".pdf", FinalOutputPath + filename + "_1.pdf", patientfirstpagestr, test1, TableofContentPageCount, patientheader, SectionPageStartNumber);
File.Delete(temppath + filename + "_Temp.pdf");
I have a requirement to create a round corner buttons but I am new to dev express.Do we have any buttons in Dev express 8.2 which supports round corner.With normal button i tried following code but it didnt work.
public class RoundButton : Button
{
protected override void OnResize(EventArgs e)
{
using (var path = new System.Drawing.Drawing2D.GraphicsPath())
{
path.AddEllipse(new Rectangle(0, 0, 80, 30));
this.Region = new Region(path);
}
base.OnResize(e);
}
}
public class RoundButton : Button
{
bool isMouseEnter = false;
GraphicsPath GetRoundPath(RectangleF Rect, int radius)
{
float r2 = radius / 2f;
GraphicsPath GraphPath = new GraphicsPath();
GraphPath.AddArc(Rect.X-1, Rect.Y, radius, radius, 180, 90);
GraphPath.AddLine(Rect.X + r2, Rect.Y, Rect.Width - r2, Rect.Y);
GraphPath.AddArc(Rect.X + Rect.Width - radius, Rect.Y, radius, radius, 271, 90);
GraphPath.AddLine(Rect.Width, Rect.Y + r2, Rect.Width, Rect.Height - r2);
GraphPath.AddArc(Rect.X + Rect.Width - radius - 1,
Rect.Y + Rect.Height - radius, radius, radius, 1, 90);
GraphPath.AddLine(Rect.Width - r2, Rect.Height, Rect.X + r2, Rect.Height);
GraphPath.AddArc(Rect.X, Rect.Y + Rect.Height - radius, radius, radius, 90, 90);
GraphPath.AddLine(Rect.X, Rect.Height - r2, Rect.X, Rect.Y + r2);
// GraphPath.CloseFigure();
return GraphPath;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
RectangleF Rect = new RectangleF(0, 0, this.Width, this.Height);
GraphicsPath GraphPath = GetRoundPath(Rect, 10);
this.Region = new Region(GraphPath);
using (Pen pen = new Pen(System.Drawing.Color.FromArgb(74, 174, 74), 8.25F))
{
if (isMouseEnter)
pen.Color = System.Drawing.Color.FromArgb(88, 208, 88);
pen.Alignment = PenAlignment.Inset;
e.Graphics.DrawPath(pen, GraphPath);
}
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
isMouseEnter = true;
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
isMouseEnter = false;
}
}
I have the below method that I am using to create webcontrols (for now just literal and Panel)
private T CreateControl<T>(string s1, string s2, string m1)
where T: WebControl , new()
{
T ctrl = default(T);
if (ctrl is Literal )
{
Literal l = new Literal();
l.ID = s1 + "ltl" + s2;
l.Text = s1 + " " + s2;
ctrl = (Literal)l;
}
else if (ctrl is Panel)
{
Panel p = new Panel();
p.ID = s1+ "pnl" + s2;
p.CssClass = s1 + "graphs";
p.Attributes.Add("responsefield", s2);
p.Attributes.Add("metricid", m1);
ctrl = (Panel)l;
}
else if (ctrl is CheckBox)
return ctrl;
}
I am invoking this as:
Literal lg = CreateControl<Literal>("emails", name.Name, name.MetricId.ToString() );
But the conversion is failing at:
ctrl = (Literal)l;
ctrl = (Panel)p;
Error:
Cannot implicitly convert type 'System.Web.UI.WebControls.Panel' to 'T'
Can somebody advise how to handle this conversion?
Thanks in advance...
I can suggest you something like this.
private T CreateControl<T>(string s1, string s2, string m1)
where T : System.Web.UI.Control,new()
{
if (typeof(T) == typeof(Literal))
{
Literal l = new Literal();
l.ID = s1 + "ltl" + s2;
l.Text = s1 + " " + s2;
return l as T;
}
else if (typeof(T) == typeof(Panel))
{
Panel p = new Panel();
p.ID = s1 + "pnl" + s2;
p.CssClass = s1 + "graphs";
p.Attributes.Add("responsefield", s2);
p.Attributes.Add("metricid", m1);
return p as T;
}
else if (typeof(T) == typeof(CheckBox))
{
return new CheckBox() as T;
}
else
{
return new T();
}
}
Edit: Modified the method you don't need to cast it afterwars like #jbl suggested.
Literal l = CreateControl<Literal>("something", "something", "something");
in page cap.aspx
==========================================================================
string code = GetRandomText();
Bitmap bitmap = new Bitmap(160,50,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bitmap);
Pen pen = new Pen(Color.LavenderBlush);
Rectangle rect = new Rectangle(0,0,160,50);
SolidBrush b = new SolidBrush(Color.LightPink);
SolidBrush blue = new SolidBrush(Color.White);
int counter = 0;
g.DrawRectangle(pen, rect);
g.FillRectangle(b, rect);
for (int i = 0; i < code.Length; i++)
{
g.DrawString(code[i].ToString(), new Font("Tahoma", 10 + rand.Next(14, 18)), blue, new PointF(10 + counter, 10));
counter += 20;
}
DrawRandomLines(g);
bitmap.Save(Response.OutputStream,ImageFormat.Gif);
g.Dispose();
b.Dispose();
blue.Dispose();
bitmap.Dispose();
===================================================================================
<div id="DIVdialog" style="display:none">
<img src="cap.aspx"/>
</div>
===================================================================================
$("#DIVdialog").dialog();
==================================================================================
show dialog but does not show image? address cap.aspx is correct!
how get cap.aspx by $.ajax and datatype:image?
I think that the key here is to add the ContentType and the BufferOutput
context.Response.ContentType = "image/gif";
context.Response.BufferOutput = false;
Eg:
public void RenderIt(HttpContext context)
{
context.Response.ContentType = "image/gif";
context.Response.BufferOutput = false;
string code = GetRandomText();
using(Bitmap bitmap = new Bitmap(160,50,System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using(Graphics g = Graphics.FromImage(bitmap))
{
using(Pen pen = new Pen(Color.LavenderBlush)
{
using(SolidBrush b = new SolidBrush(Color.LightPink))
{
using(SolidBrush blue = new SolidBrush(Color.White))
{
Rectangle rect = new Rectangle(0,0,160,50);
int counter = 0;
g.DrawRectangle(pen, rect);
g.FillRectangle(b, rect);
for (int i = 0; i < code.Length; i++)
{
g.DrawString(code[i].ToString(), new Font("Tahoma", 10 + rand.Next(14, 18)), blue, new PointF(10 + counter, 10));
counter += 20;
}
DrawRandomLines(g);
g.Dispose();
b.Dispose();
blue.Dispose();
// Return
bitmap.Save(context.Response.OutputStream, ImageFormat.Gif);
// Dispose
bitmap.Dispose();
}
}
}
}
}
context.Response.End();
}