How to convert bytes into image - asp.net

I am generating a report using Telerik and displaying it as PDF in UI. Can anyone tell me, how to display that report as an image in UI using jquery and asp.net mvc3

You can try somethig like this:-
public Image byteArrayToImage(byte[] byteArray1)
{
MemoryStream m1= new MemoryStream(byteArray1);
Image i1= Image.FromStream(m1);
return i1;
}
Check out this link:- ByteToImage

Related

CefSharp WpfControl and rendering to image

We want to show a webpage in a chromium based browser within a wpf application.
The website that is displayed within the browser should also be shown on another screen but without interaction.
I want to combine the cefsharp wpf browser control and the cefsharp offscreen rendering.
Can I use one chromium instance for displaying the page with interactions in wpf and export the current visible website as an image?
Thank you and best regards,
Simon
Thank you amatiland, it indeed works with the OnPaint Method or Event.
public MainWindow()
{
InitializeComponent();
Browser.Paint += Browser_Paint;
}
void Browser_Paint(object sender, CefSharp.Wpf.PaintEventArgs e)
{
Bitmap newBitmap = new Bitmap(e.Width, e.Height, 4 * e.Width, System.Drawing.Imaging.PixelFormat.Format32bppRgb, e.Buffer);
var aPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "TestImageCefSharpQuant.png");
newBitmap.Save(aPath);
}
XAML
<wpf:ChromiumWebBrowser x:Name="Browser" Address="www.google.com"></wpf:ChromiumWebBrowser>

Iframe shows ActionMethod name while loading PDF file in ASP MVC

i am using iframe tag in order to call ActionMethod that returns FileResult to display PDF file. The issue is after it loads PDF document instead of showing pdf file name, it shows ActionMethod name on the top of the PDF file name in Chrome.
Razor Code:
<iframe src="#Url.Action("GetAgreementToReview", "Employee")" style="zoom: 0.60; -ms-zoom: 1; width: 100%;" width="99.6%" height="420" frameborder="0" id="agreementPdf"></iframe>
CS Code:
public ActionResult GetAgreementToReview()
{
Response.AddHeader("Content-Disposition", "inline; filename=Master-Agreement.pdf");
return File("~/Content/Master-Agreement.pdf", "application/pdf");
}
Image: As you can see in the screenshot, it shows 'GetAgreementToReview' i.e. ActionMethod name instead of 'Master-Agreement.pdf'.
Does anyone know how to fix this issue?
Thanks.
Sanjeev
I had a similar problem and found a solution after exploring almost everything the web has to offer.
You must use a custom route for your action and you must send the filename from UI into the URL itself. (Other parameters won't be affected)
//add a route property
[Route("ControllerName/GetAgreementToReview/{fileName?}")]
public ActionResult GetAgreementToReview(string fileName, int exampleParameter)
{
byte[] fileData = null; //whatever data you have or a file loaded from disk
int a = exampleParameter; // should not be affected
string resultFileName = string.format("{0}.pdf", fileName); // you can modify this to your desire
Response.AppendHeader("Content-Disposition", "inline; filename=" + resultFileName);
return File(fileData, "application/pdf"); //or use another mime type
}
And on client-side, you can use whatever system to reach the URL.
It's a bit hacky, but it works.
If you have an Iframe on HTML to display the PDF (the issue I had), it could look like this:
<iframe src='/ControllerName/GetAgreementToReview/my file?exampleParameter=5' />
And this way you have a dynamic way of manipulate the filename shown by the IFRAME that only uses the last part of an URL for its name shown on the web page (quite annoying). The downloaded filename will have its name given from server-side Content-disposition.
Hope it helps !
please try this code :
return File("~/Content/Master-Agreement.pdf", "application/pdf", "filename.pdf");
Other Helper Link : Stream file using ASP.NET MVC FileContentResult in a browser with a name?

embedding images in asp.net Custom Control

I am creating a custom Gridview control, according to requirement i have to place two image buttons in the Top Pager. where i am able to display imagebuttons in top pager but only one image imagebutton shows the image another imagebutton does not.
Here is code:
protected override void InitializePager(GridViewRow row,int columnSpan,PagedDataSource pagedDataSource)
{
//adding refresh button in TopPager
ImageButton Refresh = new ImageButton();
Refresh.ToolTip = "Refresh GridView";
Refresh.ImageAlign = ImageAlign.Right;
Refresh.AlternateText = "Refresh GridView";
ClientScriptManager cs1 = this.Page.ClientScript;
Refresh.ImageUrl = cs1.GetWebResourceUrl(typeof(myCustomGrid.CustomGrid), "myCustomGrid.Refresh.gif");
// adding button in TopPager to add new record..
ImageButton ExportToPDF = new ImageButton();
ExportToPDF.ToolTip = "Export To PDF";
ExportToPDF.AlternateText = "PDF Export";
ClientScriptManager cs2 = this.Page.ClientScript;
ExportToPDF.ImageUrl = cs2.GetWebResourceUrl(typeof(myCustomGrid.CustomGrid), "myCustomGrid.PDF.gif");
}
I have set both images properties build action to embedded resource
in assembly.info
[assembly: WebResource("myCustomGrid.Refresh.gif", "image/gif")]
[assembly: WebResource("myCustomGird.PDF.gif", "image/gif")]
where i am going wrong! any help is much appreciated.
Does this images placed in root of the project? Because, if not you have to add relative path. And I don't see path from asssembly.
You have to make like this:
[assembly: WebResource("{Your assembly full name}.{Path to image inside assembly and with replacement '/' to '.'}.{Image name}", "image/gif")]
For example:
[assembly: WebResource("MyBestProject.Controls.resources.images.myCustomGird.PDF.gif", "image/gif")]
Could be a typo.
Did you mean :-
[assembly: WebResource("myCustomGrid.PDF.gif", "image/gif")]
and not...
[assembly: WebResource("myCustomGird.PDF.gif", "image/gif")]
Update:
when the imagebuttons renders the HTML generated by Refresh.gif and PDF.gif imagebuttons respectively.The PDF.gif does not load instead i get the alternate text specified which is in this code line ExportToPDF.AlternateText = "PDF Export";
<input align="right" type="image" style="height:20px;width:20px;" alt="Refresh GridView" src="/WebResource.axd?d=CIOcfTt92OMP_aqepr-cGa2E4E8-uaiywsae5-4NcYocrJ-NE-cIL4Qb2JfX3tY0cIa8EwDzWnyeBqNiST34SNpBNuGjVC113XqMTprBN-XU9J7ilPsI6bsaXwHa-Qt30&t=634589418951556073" title="Refresh GridView" name="ctl00$MainContent$customGrid0$ctl01$ctl02">
<input type="image" style="height:20px;width:20px;margin-left:480px;" alt="PDF Export" src="/WebResource.axd?d=su3rsVMzKa7BNi4A-JZVUHPhHh3sS-oWW9bmAeK4I0h1A11NHqBD2setFyA3yundDC34YO0gbBoz5G0PHS0uxeQYI66QON_syQhIdlIKs4JzJW6H_oLErMjOZE6Q_slB0&t=634589418951556073" title="Export To PDF" name="ctl00$MainContent$customGrid0$ctl01$ctl01">
"only" 2 years later, I had a similar issue. I just resolved mine with a simple idea that came by looking at the similarities between this post and my issue. Perhaps someone else will find this solution useful in the future.
The problem appears to be with the ALLCAPS section of the name. For some reason, UpperLower names work fine, as do all lower. But I am guessing ALLCAPS segments get converted to something else internally and don't work. In my case, renaming my icon from "ARROWLEFT.GIF" to "ArrowLeft.gif" (file name, registration, and any references to the resource) fixed the issue.
Additional Note: I had another image in the same project, named "icon_Calendar.GIF" which also wasn't working until I renamed it to "icon_Calendar.gif".

Object Tags and Asp

I have a master page that gets all its images from a table on a database, and I am trying to incorporate flash, for banners, but I can't quite seem to figure it out.
Right now there is a:
<asp:image id="headerimg" runat="server">
and that generates the appropriate img tag needed to show an image in html. Now I would like to know if there is any way where I can generate an object tag if a .swf file is present and populate the tag with width height and data and also not show the img tag.
Update__
I now have made a usercontrol that will create the object tag, but can someone please tell me if it is looking like I am doing it right..
IDataReader dr = DB.GetRS("SELECT HeaderGraphic,HeaderAlign, fWidth, fHeight, Flash FROM Store where CustomerID='" + Session["Customer"].ToString() + "'");
if(dr["Flash"] == 1)
{
HtmlGenericControl obj = new HtmlGenericControl("object");
obj.Attributes["width"] = dr["fWidth"];
obj.Attributes["height"] = dr["fHeight"];
obj.Attributes["data"] = dr["HeaderGraphic"];
this.Controls.Add(obj);
}
else
{
HtmlGenericControl image = new HtmlGenericControl("img");
img.Attributes["src"] = dr["HeaderGraphic"];
img.Attributes["align"] = dr["HeaderAlign"];
this.Controls.Add(image);
}
is this continuing to look right? and is there anything I am missing?
Thanks.
Why not create a user control that generates the required <OBJECT /> html to display the swf file and then you can dynamically load these if there are swf file present?
is this looking right? and how do I get this into the html?
Yes it looks right. You can add it into your page this way:
this.Controls.Add(obj);
Hope it helps!
Hanlet
EDIT: I could recommend you to look into Generic Handlers and see if you can somehow use it. Good luck!

Load images dynamically in ASP.Net page using C# and change another image on click of previous image on client side

i want to add dynamically images in asp.net using C#. after this i want to change image as selected on client side click event. i do not know for this what i will use. please anybody solve my problem. for problem reference: huitsuit dashboard lending page.
Create new Page which should create image runtime as follows:
string s = Server.MapPath("original.jpg");
string s2 = Server.MapPath("ikon.gif");
System.Drawing.Image original= Bitmap.FromFile(s);
Graphics gra = Graphics.FromImage(original);
Bitmap logo = new Bitmap(s2);
gra.DrawImage(logo, new Point(70, 70));
Response.ContentType = "image/JPEG";
big.Save(Response.OutputStream, ImageFormat.Jpeg);
Now in your existing page Implement ICallBack interface
( http://msdn.microsoft.com/en-us/library/ms178208.aspx )
in response of ICallback interface you can set image source to you image aspx page.
e.g
<image src='Image.aspx'>

Resources