|
i want to convert a aspx web form into image file.but an error out of memory is occur when i execute following code.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
public class CaptureWebPage
{
private const string EXTRACTIMAGE_EXE = "IECapt.exe";
private const int TIMEOUT = 60000;
private const string TMP_NAME = "InBetween.png";
public CaptureWebPage()
{
}
private void Shot(string url, string rootDir)
{
Process p = new Process();
p.StartInfo.FileName = rootDir + "\\" + EXTRACTIMAGE_EXE;
p.StartInfo.Arguments = String.Format("\"{0}\" \"{1}\"", url, rootDir + "\\" + TMP_NAME);
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.WaitForExit();
p.Dispose();
}
private System.Drawing.Image Scale(System.Drawing.Image imgPhoto,int Width, int Height)
{
int srcWidth = imgPhoto.Width;
int srcHeight = imgPhoto.Height;
int srcX = 0; int srcY = 0;
int destX = 0; int destY = 0;
float percent = 0; float percentWidth = 0; float percentHeight = 0;
percentWidth = ((float)Width / (float)srcWidth);
percentHeight = ((float)Height / (float)srcHeight);
if (percentHeight < percentWidth)
{
percent = percentWidth;
destY = 0;
}
else
{
percent = percentHeight;
destX = 0;
}
int destWidth = (int)(srcWidth * percent);
int destHeight = (int)(srcHeight * percent);
System.Drawing.Bitmap pnghoto = new System.Drawing.Bitmap(Width,
Height, PixelFormat.Format24bppRgb);
pnghoto.SetResolution(imgPhoto.HorizontalResolution,
imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(pnghoto);
grPhoto.InterpolationMode =
InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(srcX, srcY, srcWidth, srcHeight),
GraphicsUnit.Pixel);
grPhoto.Dispose();
return pnghoto;
}
public string GetImage(string url, string name, string rootDir, int width, int height)
{
string fileName = rootDir + "\\" + TMP_NAME;
Shot(url, rootDir);
System.Drawing.Image thumbImage = System.Drawing.Image.FromFile(fileName);
Scale(thumbImage, width, height);
System.Drawing.Image scaledImg = Scale(thumbImage, width, height);
fileName = rootDir + "\\" + name + ".png";
if (File.Exists(fileName))
File.Delete(fileName);
scaledImg.Save(fileName, ImageFormat.Png);
return name + ".png";
}
}
protected void btnsave_Click(object sender,EventArgs e)
{
int Width, Height;
Width = Convert.ToInt32("1000");
Height = Convert.ToInt32("1000");
CaptureWebPage cwp = new CaptureWebPage();
string str="http://localhost:1108/bijliboardwap/showdetail.aspx?meterid="+meterid;
string imagePath = cwp.GetImage(str, " ", Server.MapPath("~"), Width, Height);
Response.Redirect("~/Default2.aspx?Path=" + imagePath);
}
|
|
|
|
|
Hi,
welcome to CodeProject.
Your question is very hard to read, with a lot of unformatted code. We recommend you use PRE tags (or the "code block" widget) to get code formatted properly, with indentation, and syntax coloring. You could still edit and improve your existing message! It is also good practice to be as specific as possible about compilation or run-time problems; e.g. an Exception tends to include a line number, telling us which line bombs is a big step forward.
I haven't looked at all the code, I want to signal GDI+ or .NET uses some strange exceptions when things go wrong. As an example (possibly spot on), Image.FromFile gives an OutOfMemoryException when the data in the file isn't using an image format the method understands.
So I suggest you:
1. look at the exact filepath you are using
2. consider whether you want a file on the client side or the server side
3. try and open said file, e.g. by double-clicking it in Windows Explorer; if explorer fails, so will FromFile.
|
|
|
|
|
If you go to google and search for microsoft you will see microsoft corporation the result and below that you will see some featured links from microsoft such as windows, support, etc and then you can see (more from microsoft.com)
What does this google technology called and how can I do it for my website?
|
|
|
|
|
jrahma wrote: What does this google technology called and how can I do it for my website?
That technology is called Crawling.Google searches for any content on all the pages available on Web.It even looks the tags, even seraches the entire pages for the searched keywords.
How many times a page is searched it makes your page get ranked higher and displayed in searched results on first few results. There are also many factors associated to it.
For details, Have a look
You dont need to do anything specific. Upload your site on web. Have really good contents that people are looking for. Also check above link for details.
|
|
|
|
|
When you create a web site on a new domain name, it will not automatically show up in Google results. Google is NOT reading the entire internet, it is not fetching random URLs. "All" it does is crawl from one page to the next, starting at some root point, and following (almost) all links it encounters. So putting up a new site as an island isn't going to work.
AFAIK in order for your web site to appear in Google results at all, you need to do at least one of these:
1. get your web site linked to on one or more pages that are already known to Google; communities such as Facebook, LinkedIn, CodeProject, ... may be a good starting point; a friend's site may be too.
2. report your home page to Google, see http://www.google.com/addurl/[^]; not sure if that really works though.
3. pay Google for a sponsored link; does not make sense to me, unless you're a big corporation.
And whatever you try, it takes a couple of weeks to get initial results!
Once your site is showing up in Google results, there are techniques to improve your ranking.
Search for Search Engine Optimization.
|
|
|
|
|
|
Hi there,
I'm writing a web service that's supposed to monitor client out there, using web clients.
I'd like to allow a user to read a status report using a web browser.
The naive solution i had thought of was having an <index.html> file, and updating it when needed.
The problem is, updates may need to be made very often.
Another problem may be that the web service might not have privileges to change the file, since it will be held by the iis, while serving it to the user.
Any good ideas or tips?
Thanks in advance,
Summer Bulb
|
|
|
|
|
A webservice does not have a file to change. It should provide access to services, such as, setting or retrieving data. I'm not very clear on what you are attempting to do or what you want to accomplish.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
The idea is as follows:
Multiple clients will be pinging the web service to indicate activity.
The web service will store the ping information.
I would like to be able to display that information to a user useing his web browser (with a html file or something like that).
Am i clear now?
|
|
|
|
|
Ok, create an aspx page that reads the data and displays it, you know, basic ASP.NET.
If you are thinking you can use the web service to display the page then you don't understand what a webservice is or how to use it.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Assuming your web service consists of one or more asmx files, all it would take IMO is one or more aspx pages that present the required information. Mind you, I haven't tried this, however I don't expect there to be any problem. You could use a database (or a static class) to hold the shared information.
|
|
|
|
|
Hi,
i've a GridView with 1000 rows,
one column of the grid is "Edit".
My problem is - when i'm press on some row (for ex. row mumber 600)
the page is set to the top,
and then i need to scroll and find the row that become editable.
How i can set the focus on the row that i selected (after i pressed on "Edit").
Can someone please help me?
|
|
|
|
|
|
I've set it at Page_Init and it works great
10x
|
|
|
|
|
you can just set this on the aspx page at the top in the declaration this might be a little easier.
Three types of people in this world, those that can count and those that can't
www.casserlyprogramming.com
|
|
|
|
|
I have a contact.aspx page
I created asp:table with rows which has txtMessage, txtEmail and btnSend controls
I placed the table within asp:updatepanel and above it I have asp:updateprogress
Now ajax seems to be working properly and updateprogress is showing
I only have one problem here
In the btnSend_Click evet, I am setting ther button enable to false which is not happening!
I also tried setting the entire table visibility to false but its not happening as well
I am not getting any error and submission is going through but without doing what I want with the button enable property
What can I do plz?
|
|
|
|
|
It should not happen. I tried and its working fine as expected.Can you post code.. Then it'll be better to answer.
|
|
|
|
|
This is the code. I just need to disable the btnSend or any of the textbox
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="panelContact" runat="server">
<ContentTemplate>
<div>
<asp:Table ID="Table11" runat="server" CellPadding="10">
<asp:TableRow ID="rowComment"><asp:TableCell VerticalAlign="Top" ColumnSpan="3"><asp:Label runat="server" ID="lblStatus" Text="Thank you." ForeColor="Red" Font-Bold="true" Visible="false" /><asp:Label runat="server" ID="lblMessage" Text="Please write your message and I will get back to you as soon as possible." /></asp:TableCell></asp:TableRow>
<asp:TableRow ID="rowHomePage" Visible="false"><asp:TableCell VerticalAlign="Top" ColumnSpan="3"><br /><asp:HyperLink ID="lblHomePage" runat="server" Text="Click Here to return to home page." NavigateUrl="Default.aspx" /></asp:TableCell></asp:TableRow>
<asp:TableRow ID="rowMessage">
<asp:TableCell VerticalAlign="Top">Your Message</asp:TableCell>
<asp:TableCell Width="10" HorizontalAlign="Center" VerticalAlign="Top">:</asp:TableCell>
<asp:TableCell VerticalAlign="Top"><asp:TextBox runat="server" ID="txtMessage" TextMode="MultiLine" TabIndex="0" Width="300px" Height="150px"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="rowEmail">
<asp:TableCell VerticalAlign="Top">Your Email</asp:TableCell>
<asp:TableCell Width="10" HorizontalAlign="Center" VerticalAlign="Top">:</asp:TableCell>
<asp:TableCell VerticalAlign="Top" HorizontalAlign="Right"><asp:TextBox runat="server" ID="txtEmail" Width="300px"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="rowbutton">
<asp:TableCell VerticalAlign="Top"></asp:TableCell>
<asp:TableCell Width="10" HorizontalAlign="Center" VerticalAlign="Top"></asp:TableCell>
<asp:TableCell VerticalAlign="Top">
<asp:UpdateProgress runat="server" ID="updateProgress" DisplayAfter="1">
<ProgressTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/loading_progress.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Button runat="server" ID="btnSend" Text="Send" Width="100%" OnClick="btnSend_Click" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
|
|
|
|
|
Perhaps the snippet was not posted or formatted correctly but you appear to have the both the progress control and the button inside the update panel
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yes true
Why? Is it wrong?
So how can I do it?
|
|
|
|
|
The progress control should not be inside the update panel. See the example here[^] and while your at it read the rest of the documentation about UpdatePanels and how to use them.
Move the button outside the update panel and use a Trigger. Once again, reading the documentation will help.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thx for your replies
I noted your comments and changed my code accordingly but the button is not not allowing disable
Anyhow I have another question here please
How can I hide the UpdatePanel and all everything inside it when UpdateProgress is started?
And how can I show it back from the code if my try...returned error?
This my latest code
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="panelContact" runat="server">
<ContentTemplate>
<asp:Table ID="Table11" runat="server" CellPadding="10">
<asp:TableRow ID="rowComment"><asp:TableCell VerticalAlign="Top" ColumnSpan="3"><asp:Label runat="server" ID="lblStatus" Text="Thank you." ForeColor="Red" Font-Bold="true" Visible="false" /><asp:Label runat="server" ID="lblMessage" Text="Please write your message and I will get back to you as soon as possible." /></asp:TableCell></asp:TableRow>
<asp:TableRow ID="rowHomePage" Visible="false"><asp:TableCell VerticalAlign="Top" ColumnSpan="3"><br /><asp:HyperLink ID="lblHomePage" runat="server" Text="Click Here to return to home page." NavigateUrl="Default.aspx" /></asp:TableCell></asp:TableRow>
<asp:TableRow ID="rowMessage">
<asp:TableCell VerticalAlign="Top">Your Message</asp:TableCell>
<asp:TableCell Width="10" HorizontalAlign="Center" VerticalAlign="Top">:</asp:TableCell>
<asp:TableCell VerticalAlign="Top"><asp:TextBox runat="server" ID="txtMessage" TextMode="MultiLine" TabIndex="0" Width="300px" Height="150px"></asp:TextBox></asp:TableCell>
<asp:TableCell Width="10" HorizontalAlign="Center" VerticalAlign="Top"><asp:RequiredFieldValidator runat="server" ID="rgMessages" ControlToValidate="txtMessage" ToolTip="Please write your message!" Text='<img src="images/error.gif">' Display="Dynamic" SetFocusOnError="true" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="rowEmail">
<asp:TableCell VerticalAlign="Top">Your Email</asp:TableCell>
<asp:TableCell Width="10" HorizontalAlign="Center" VerticalAlign="Top">:</asp:TableCell>
<asp:TableCell VerticalAlign="Top" HorizontalAlign="Right"><asp:TextBox runat="server" ID="txtEmail" Width="300px"></asp:TextBox></asp:TableCell>
<asp:TableCell Width="10" HorizontalAlign="Center" VerticalAlign="Top"><asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="txtEmail" ToolTip="Please enter a valid email address!" Text='<img src="images/error.gif">' Display="Dynamic" SetFocusOnError="true" /><asp:RegularExpressionValidator runat="server" ID="rgEmail" ControlToValidate="txtEmail" ToolTip="Please enter a valid email address!" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage='<img src="../images/error.gif">' Display="Dynamic" SetFocusOnError="true" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="rowbutton">
<asp:TableCell VerticalAlign="Top"></asp:TableCell>
<asp:TableCell Width="10" HorizontalAlign="Center" VerticalAlign="Top"></asp:TableCell>
<asp:TableCell VerticalAlign="Top">
<asp:Button runat="server" ID="btnSend" Text="Send" Width="100%" OnClick="btnSend_Click" />
</asp:TableCell>
<asp:TableCell Width="10" HorizontalAlign="Center" VerticalAlign="Top"></asp:TableCell>
</asp:TableRow>
</asp:Table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSend" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress runat="server" ID="updateProgress" DisplayAfter="1" AssociatedUpdatePanelID="panelContact">
<ProgressTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/loading_progress.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
Thanks
|
|
|
|
|
hi,
I've to play a mp3 file on my web page
how can i implement it
|
|
|
|
|
|
<audio controls autobuffer>
<source src="myfile.ogg" />
<source src="myfile.mp3" />
<!-- flash fall back if you care about ie -->
</audio>
http://html5doctor.com/native-audio-in-the-browser/
|
|
|
|