473,765 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Watermark/label custom http handler

Tem
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

Jan 3 '08 #1
5 1508

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

Jan 3 '08 #2
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);
}
}

Jan 4 '08 #3
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>
Jan 4 '08 #4
Tem
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?
Jan 4 '08 #5
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
Jan 4 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
13274
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)
9
5872
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...
5
1681
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) {
1
1716
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 (...
0
9568
marktang
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...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
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...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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
3
2805
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.