Print Page | Close Window

GDI, Drawing an Image

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=12199
Printed Date: 28 March 2026 at 11:06pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: GDI, Drawing an Image
Posted By: vshriniwasan
Subject: GDI, Drawing an Image
Date Posted: 16 October 2004 at 9:32am

Hey guys, I am working on a simple GDI Script in SharePoint. This is only Code Behind. I am trying to write the stream. I have two errors. It is saying Response is not declared. Is there any other way to declare this... Can I import something that might fix the problem.

Response.ContentType = "image/gif"
fullSizeImg.Save(Response.OutputStream, ImageFormat.Gif) 

Please Advise, Thank you...

Shrini




Replies:
Posted By: michael
Date Posted: 16 October 2004 at 10:57am
Imports HTTPCOntext.Current
at the top of the Code behind page.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: vshriniwasan
Date Posted: 16 October 2004 at 11:57am

Michael you are a genius...

It worked perfect with a little hitch..

As per your advise, I imporeted System.web.httpcontext and changed my response to current.response.

Now for what's happening and the little bit code:

myImage = New Image
Controls.Add(myImage)
myImage.ImageURL = WriteGDI(passing Values)

function WriteGDI()
...............................
...............................
    myBitMap.Save(memStream, ImageFormat.Png)
    memStream.WriteTo(Current.Response.OutputStream)
End Function

What this is doing is replacing my page with the image itself. What can I do to just have the image change in the middle of the page.

Thanks a lot for take time to assist me.
Shrini



Posted By: michael
Date Posted: 16 October 2004 at 1:50pm
Not sure what you mean with just replacing the middle of the page. If you want to display a gdi image within another page you either need to add a placeholder or image control to the page and then dynamically add the .aspx as gdi to it. Generating a gdi image will result in the aspx page to be an image so you need to add it to another page.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: vshriniwasan
Date Posted: 16 October 2004 at 7:00pm

Michael,

I already have a place holder for the image in the middle of the page.

I have a function I am passing the information to the Funciton which which generates a simple image. There are no other ASPX pages where I can move the Script and pass the values through QueryString to the page.

It looks like I am screwed in a manner.

Hope there is a solution.

Shrini



Posted By: vshriniwasan
Date Posted: 16 October 2004 at 7:57pm

Michael,

Here is an interesting option. May Be!

I can serialize the image. Can I deserialize it and assign it as the imageURL.

Don't know how I can do that yet and is it going to drop me in the same position.

Shrini



Posted By: michael
Date Posted: 16 October 2004 at 8:20pm
If you do not want to generate the image in a 2nd page so you can set the URL you will need to use a HTTP Handler. This is once you understand HTTP Handlers fairly easy to do, here is a c# example how the asp.net forums generate an avatar which is passes as a binary from database

using System;
using System.Web;
using System.Web.Caching;
using AspNetForums;

namespace AspNetForums.Components.HttpHandler {

    public class AvatarHttpHandler : IHttpHandler {

        public void ProcessRequest (HttpContext context) {

             try {
                Avatar userAvatar = Resources.GetAvatar( int.Parse(context.Request.QueryString["UserID"]) );

                context.Response.ContentType = userAvatar.ContentType;
                context.Response.OutputStream.Write(userAvatar.Content, 0, userAvatar.Length);

                context.Response.Cache.SetCacheability(HttpCacheability.Publ ic);
                                     context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(30));
                context.Response.Cache.SetAllowResponseInBrowserHistory(true );
                context.Response.Cache.SetValidUntilExpires(true);
                context.Response.Cache.VaryByParams["UserID"] = true;
             } catch {}

        }

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


-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net