473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Setting image src with outputstream?

Hello

I was wondering if you guys could help me......

I have one textbox, image and one button on a page...... and when I click it
im trying to generate a pic and display it....

but I cant get the right datatype or anything for it to work..... im trying
to stream it.....

private void GeneratePic(string txt)

{

Font font = new Font("Impact", 144);

Image img = Image.FromFile(@"c:\inetpub\wwwroot\dbtest\goldwav e.jpg");

TextureBrush texture = new TextureBrush(img);

Bitmap tb = new Bitmap(500,250);

Graphics bmpGraphics = Graphics.FromImage(tb);

bmpGraphics.SmoothingMode = SmoothingMode.AntiAlias;

bmpGraphics.Clear(Color.White);
bmpGraphics.DrawString(txt, font, texture, 14, 10);

Response.ContentType = "image/jpeg";

tb.Save(Response.OutputStream, ImageFormat.Jpeg);

}

private void Button1_Click(object sender, System.EventArgs e)

{

if(Page.IsValid)

{

Image1.Visible = true;

Image1.ImageUrl = GeneratePic(TextBox1.Text);

}

}
Nov 16 '05 #1
1 3072
First, since GeneratePic returns Void you cannot do:
Image1.ImageUrl = GeneratePic(TextBox1.Text);

You need to save the image to disk first, and then set Image1.ImageUrl
to the path of the file.
You could modify the GeneratePic method to save the file to disk
and return the path to the file.
In order to successfully stream the image data to the browser,
you need to make sure there are no other content that damages the file.
You can do that like:
base.Response.ClearContent();
base.Response.ContentType = "image/jpeg";
[SAVE IMAGE TO OUTPUT STREAM HERE]
// Important to cancel page HTML rendering:
base.Response.End();
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Lasse Edsvik" <la***@nospam.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
Hello

I was wondering if you guys could help me......

I have one textbox, image and one button on a page...... and when I click
it
im trying to generate a pic and display it....

but I cant get the right datatype or anything for it to work..... im
trying
to stream it.....

private void GeneratePic(string txt)

{

Font font = new Font("Impact", 144);

Image img = Image.FromFile(@"c:\inetpub\wwwroot\dbtest\goldwav e.jpg");

TextureBrush texture = new TextureBrush(img);

Bitmap tb = new Bitmap(500,250);

Graphics bmpGraphics = Graphics.FromImage(tb);

bmpGraphics.SmoothingMode = SmoothingMode.AntiAlias;

bmpGraphics.Clear(Color.White);
bmpGraphics.DrawString(txt, font, texture, 14, 10);

Response.ContentType = "image/jpeg";

tb.Save(Response.OutputStream, ImageFormat.Jpeg);

}

private void Button1_Click(object sender, System.EventArgs e)

{

if(Page.IsValid)

{

Image1.Visible = true;

Image1.ImageUrl = GeneratePic(TextBox1.Text);

}

}

Nov 16 '05 #2

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

Similar topics

1
by: Neil Woodvine | last post by:
***Scenario ... I have a DataList with a hyperlink WebControl in the Item Template. I want to display a 64x64 image in the Hyperlink and set the NavigateURL to the full size image. ***Source...
6
by: Chris D | last post by:
Hi, I have an application where a user uploads an image and I create two thumbnails. One a small image and the second is a larger image but still smaller then the original. I store these in SQL...
1
by: Joseff | last post by:
I have this Bitmap object declared and outputted to the browswer this way: invoiceBMP.Save(Response.OutputStream, ImageFormat.Gif); However, the result is that the existing static controls of...
4
by: Detlef Huettenbach | last post by:
I was trying to convert a Windows Forms prototype application to an ASP.NET solution that makes use of loading data streams into the Image Web/Windows control. For WinForms no problem. However in...
10
by: David W. Simmonds | last post by:
I have a DataList control that has an Image control in the ItemTemplate. I would like to resize the image that goes into that control. I have a series of jpg files that are full size, full...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
2
by: Jeronimo Bertran | last post by:
Hello, I am using a rendering aspx page to display a database image on an Image control. When the database record is retrieved, I am saving the bitmap to a session variable for the rendering...
0
by: benfly08 | last post by:
Hi, guys. I have a program to draw bar/pie chart based on the data i hard coded in it. However, my image comes with "BLACK" background color. I don't know how to fix this. The code snippet is...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
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,...

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.