I need to write a custom handler when the handler is accessed, it returns
the photo in jpg with 2 lines on the bottom of the image.
lower left "Taken by"
lower right "January 2 2008"
This is what I have so far...
public class certificate : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Respons e.ContentType = "image/jpeg";
context.Respons e.Cache.SetCach eability(HttpCa cheability.NoCa che);
context.Respons e.BufferOutput = false;
context.Respons e.WriteFile("/photos/1.jpg");
}
public bool IsReusable {
get {
return false;
}
}
}
Your help is greatly appreciated,
Tem 5 1681 http://www.c-sharpcorner.com/UploadF...termarkCS.aspx http://geekswithblogs.net/aguest/articles/58795.aspx
I think if you merge those 2 articles together, you can get what you want.
"Tem" <te*****@yahoo. comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>I need to write a custom handler when the handler is accessed, it returns the photo in jpg with 2 lines on the bottom of the image.
lower left "Taken by"
lower right "January 2 2008"
This is what I have so far...
public class certificate : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Respons e.ContentType = "image/jpeg";
context.Respons e.Cache.SetCach eability(HttpCa cheability.NoCa che);
context.Respons e.BufferOutput = false;
context.Respons e.WriteFile("/photos/1.jpg");
}
public bool IsReusable {
get {
return false;
}
}
}
Your help is greatly appreciated,
Tem
This is what I came up with.
It only outputs a black image.. something's not right
But I can't seem to figure out what is wrong with it.
Please have a look
Thanks
<%@ WebHandler Language="C#" Class="LabelPho to" %>
using System;
using System.Web;
using System.Drawing;
using System.Drawing. Drawing2D;
using System.Drawing. Imaging;
public class certificate : IHttpHandler
{
public void ProcessRequest( HttpContext context)
{
context.Respons e.ContentType = "image/jpeg";
context.Respons e.Cache.SetCach eability(HttpCa cheability.NoCa che);
context.Respons e.BufferOutput = false;
GenerateText(@" C:\photo1.jpg") .Save(context.R esponse.OutputS tream,
ImageFormat.Jpe g);
}
public bool IsReusable
{
get
{
return false;
}
}
private Bitmap GenerateText(st ring filePath)
{
int opac = 250;
string text = "hello";
Image i = Image.FromFile( filePath);
int width = i.Width;
int height = i.Height;
Graphics g = Graphics.FromIm age(i);
Brush myBrush = new SolidBrush(Colo r.FromArgb(opac , Color.Red));
SizeF sz = g.MeasureString (text, new
Font(FontFamily .GenericSansSer if, 2));
int x;
int y;
x = width / 2;
y = height / 2;
// draw the water mark text
g.DrawString(te xt, new Font(FontFamily .GenericSansSer if, 7),
myBrush, new Point(x, y));
return new Bitmap(width, height, g);
}
}
Important: refer to the warning about System.Drawing; basically, it
isn't supported for this type of use (I've quoted below). http://msdn2.microsoft.com/en-us/lib...m.drawing.aspx
However, the problem is that you are manipulating "i", then returning
a blank (new) Bitmap; just return i (perhaps cast it if you need). And
perhaps add a few "using" blocks (on the Graphics, etc - ideally the
image would be disposed too, but this would need to be done by the
calling method). The constructor you have used only uses the Graphics
object to get the resolution - not the contents: http://msdn2.microsoft.com/en-us/library/byca5y1f.aspx
Marc
<quote>
Caution:
Classes within the System.Drawing namespace are not supported for use
within a Windows or ASP.NET service. Attempting to use these classes
from within one of these application types may produce unexpected
problems, such as diminished service performance and run-time
exceptions.
</quote>
So you're saying this is the wrong way to do it.?
Is there another way to do what I'm trying to do in asp.net?
BTW I got it to work by doing what you suggested here.
However, the problem is that you are manipulating "i", then returning
a blank (new) Bitmap; just return i (perhaps cast it if you need). And
perhaps add a few "using" blocks (on the Graphics, etc - ideally the
image would be disposed too, but this would need to be done by the
calling method). The constructor you have used only uses the Graphics
object to get the resolution - not the contents: http://msdn2.microsoft.com/en-us/library/byca5y1f.aspx
I thought .NET was supposed to dispose unused object automatically?
I thought .NET was supposed to dispose unused object automatically?
No; it performs garbage collection, but that isn't the same as
disposal... in short, if your code is responsable for something that
implements IDisposable, then your code should also ideally ensure that
Dispose() is called, commonly via "using".
Marc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David McDivitt |
last post by:
We have a massive java application to be made ADA compliant. We want onfocus
and onblur events for each text field. The best way seems to be javascript,
by cycling through all the nodes recursively after page load, and attaching
the events. We already cycle through everything to set tabs. If nodename is
LABEL, we should be able to use the FOR attribute, get the object
referenced, and attach events on that object.
When cycling through...
|
by: Tabi |
last post by:
Hi,
I want to create a custom section in my web.config that can hold my custom
values. I created a section in web.config as written below.
<configSections>
<section name="myCustomSection"
type="ComIT.Applications.Common.ConfigurationSections.MyHandler"
allowLocation="true" allowDefinition="Everywhere" />
</configSections>
|
by: jcrouse |
last post by:
I am rotating some text is some label controls. In the one place I use it it
works fine. In the other place I use it I can't figure out the syntax. I
don't really understand the event. Where it works fine, it seems to fire
when the form changes visibility. Here is the code.
Private Sub lblP1JoyUp_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles lblP1JoyUp.Paint
If lblP1JoyUp.Visible = True Then
Dim...
|
by: bryan |
last post by:
I've got a custom HttpHandler to process all requests for a given
extension. It gets invoked OK, but if I try to do a Server.Transfer I
get an HttpException. A Response.Redirect works, but I really need to
avoid the extra round-trip to the client.
I've tried Passing the page name, the full URL, and the instance of
the handler class to the Transfer method, but everything gets me the
same error 500.
Any help would be appreciated.
|
by: vbnewbie |
last post by:
I am having problems accessing properties of dynamically generated
objects in VB2005. Can someone please help?
In a nutshell:
My app creates an equal number of checkboxes and labels that share the
same Tag number. (I thought it might help)
The checkboxes name is a concatenation of "chkCancel" and a number that
represents the order in which they were created:
chkCancel0 (Tag = 0)
chkCancel1 (Tag = 1)
| |
by: Chuck Anderson |
last post by:
Is it possible to overlay a transparent watermark on an image -
dynamically?
I'd like the result to look like this example:
<http://www.cycletourist.com/temp/photo.php>
That is a bit of overkill, but you can see what I mean. The watermark
image (a png image) is included separately below the photo.
I tried using a class from phpclasses.org
<http://www.phpclasses.org/browse/package/1580.html...
|
by: Tem |
last post by:
I need to write a custom handler when the handler is accessed, it returns
the photo in jpg with 2 lines on the bottom of the image.
lower left "Taken by"
lower right "January 2 2008"
This is what I have so far...
public class certificate : IHttpHandler {
public void ProcessRequest (HttpContext context) {
|
by: Jordan S. |
last post by:
Using .NET 3.5... in a "plain old" .aspx page I have the following code in
the Init event:
this.Context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
this.Context.Response.Cache.SetCacheability(HttpCacheability.Public);
this.Context.Response.Cache.SetValidUntilExpires(false);
It works great. Testing shows that the page is cached for 60 seconds as
expected. Specifically, I insert the current date/time into the Response...
|
by: rfr |
last post by:
Apparently the Transitional Doctype kills this script because the script
does not make proper use of units like "px".
It works well without a doctype statement. But once someone adds a
transitional doctype, the js script no longer works.
Can someone familiar with javascript bring it up-to-date so that it works
with current doctypes and post it here for others to make use of?
The whole HTML document including the js scrip follows (...
|
by: hyperpau |
last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding.
I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com).
Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge.
I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |