HighTechTalks DotNet Forums  

Watermark/label custom http handler

ASP.net ASP.net discussions (microsoft.public.dotnet.framework.aspnet)


Discuss Watermark/label custom http handler in the ASP.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Tem
 
Posts: n/a

Default Watermark/label custom http handler - 01-02-2008 , 07:24 PM






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.Response.ContentType = "image/jpeg";
context.Response.Cache.SetCacheability(HttpCacheab ility.NoCache);
context.Response.BufferOutput = false;

context.Response.WriteFile("/photos/1.jpg");

}

public bool IsReusable {
get {
return false;
}
}
}

Your help is greatly appreciated,
Tem


Reply With Quote
  #2  
Old   
sloan
 
Posts: n/a

Default Re: Watermark/label custom http handler - 01-03-2008 , 01:08 AM







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" <tem1232 (AT) yahoo (DOT) com> wrote

Quote:
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.Response.ContentType = "image/jpeg";
context.Response.Cache.SetCacheability(HttpCacheab ility.NoCache);
context.Response.BufferOutput = false;

context.Response.WriteFile("/photos/1.jpg");

}

public bool IsReusable {
get {
return false;
}
}
}

Your help is greatly appreciated,
Tem



Reply With Quote
  #3  
Old   
Tem
 
Posts: n/a

Default Re: Watermark/label custom http handler - 01-04-2008 , 02:27 AM



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="LabelPhoto" %>

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.Response.ContentType = "image/jpeg";
context.Response.Cache.SetCacheability(HttpCacheab ility.NoCache);
context.Response.BufferOutput = false;

GenerateText(@"C:\photo1.jpg").Save(context.Respon se.OutputStream,
ImageFormat.Jpeg);
}

public bool IsReusable
{
get
{
return false;
}
}


private Bitmap GenerateText(string filePath)
{
int opac = 250;
string text = "hello";

Image i = Image.FromFile(filePath);

int width = i.Width;
int height = i.Height;

Graphics g = Graphics.FromImage(i);

Brush myBrush = new SolidBrush(Color.FromArgb(opac, Color.Red));

SizeF sz = g.MeasureString(text, new
Font(FontFamily.GenericSansSerif, 2));

int x;
int y;

x = width / 2;
y = height / 2;

// draw the water mark text
g.DrawString(text, new Font(FontFamily.GenericSansSerif, 7),
myBrush, new Point(x, y));

return new Bitmap(width, height, g);
}
}


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.