473,714 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with Image.FromStrea m()

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 ASP.NET, the image
control does not display tiffs,pngs,.. still it does
display gif-streams. Memory stream writing into a gif-
stream of the tiff and other streams likewise fails,
although the streams seem to be filled correctly.
On top of that, when I save the streams to a file and
open them by Image.FromFile, the images are displayed!

So, what's on? - Is there a more convenient work around?

Thanks for response,
Detlef
Nov 18 '05 #1
4 11740
ASP.Net is a technology which creates HTML documents for the most part. An
image control displays an image using HTML, which means that the image is
not IN the page, but a URL to the image appears in an image tag in the page.
All the files used to display the page are requested separately by the
browser and assembled by the browser in the browser window. Therefore, in
order to display an image from a stream in a page you have to include a URL
in that page that points to another ASP.Net page that sets the
Response.Conten tType property to "image/jpg" (or whatever image format
you're using), and saves the image stream to the Response.Output Stream of
the page. In other words, the second page acts just like an image.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Detlef Huettenbach" <d.***********@ netcologne.de> wrote in message
news:03******** *************** *****@phx.gbl.. .
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 ASP.NET, the image
control does not display tiffs,pngs,.. still it does
display gif-streams. Memory stream writing into a gif-
stream of the tiff and other streams likewise fails,
although the streams seem to be filled correctly.
On top of that, when I save the streams to a file and
open them by Image.FromFile, the images are displayed!

So, what's on? - Is there a more convenient work around?

Thanks for response,
Detlef

Nov 18 '05 #2
Thank you very much for your answer, and yes, I set the images URL,
namely to an HttpHandler, and in that handler the content type is set to
image/tiff, /png etc.

Unfortunately, right now at home, I can't look into the code at work.
I'll do it tomorrow, will see whether it will work if I using yet
another aspx page with an image control as an intermeditate, and will
post the result.

Thanks for your answer
Detlef

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
Hi Kevin,

Thank you for your kind answer.
Yes, URL is set on image control, pointing to
an HTTP handler, where the images are retrieved
and the Response Content Type is set to the
appropriate image/tiff ... value.

Unfortunately, here, at home, I can't look
into the app at work. So, tomorrow, I'll
give it another try with yet another aspx
image page as intermediary and will post
the result + some code.

Thanks again for your respone
Detlef

"Kevin Spencer" <ke***@takempis .com> schrieb im Newsbeitrag
news:e6******** ******@TK2MSFTN GP10.phx.gbl... > --
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Detlef Huettenbach" <d.***********@ netcologne.de> wrote in message
news:03******** *************** *****@phx.gbl.. .
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 ASP.NET, the image
control does not display tiffs,pngs,.. still it does
display gif-streams. Memory stream writing into a gif-
stream of the tiff and other streams likewise fails,
although the streams seem to be filled correctly.
On top of that, when I save the streams to a file and
open them by Image.FromFile, the images are displayed!

So, what's on? - Is there a more convenient work around?

Thanks for response,
Detlef

ASP.Net is a technology which creates HTML documents for the most part. An
image control displays an image using HTML, which means that the image is
not IN the page, but a URL to the image appears in an image tag in the

page. All the files used to display the page are requested separately by the
browser and assembled by the browser in the browser window. Therefore, in
order to display an image from a stream in a page you have to include a URL in that page that points to another ASP.Net page that sets the
Response.Conten tType property to "image/jpg" (or whatever image format
you're using), and saves the image stream to the Response.Output Stream of
the page. In other words, the second page acts just like an image.

Nov 18 '05 #4
Hi all, and Kevin in particular,

here's a source for the HTTP handler that picks
the image files from a database (this case *.png) and
handles it over to an image on a Webform with
Image.ImageURL= "...ashx" (although you could rightaway
also set the src-attribute of an <img/>-element.
Figure around: the pics wont show up on the WebForm.
What's the cause? - The ViewState?

Thanks for response
Detlef
--
<%@ WebHandler Language="C#" Class="PicViewe r" %>

using System;
using System.Web;
using System.Drawing;
using System.Drawing. Imaging;
using System.Data;
using System.Data.Sql Client;
using System.IO;
using System.Componen tModel;

public class PicViewer : IHttpHandler
{

public void ProcessRequest( HttpContext context)
{
System.Data.Sql Client.SqlConne ction
sqlConnInvoice;
Graphics g;
Bitmap bmp;
MemoryStream bmpStream;
Image _img;
MemoryStream memStream;
byte[] _picBytes;

//Get PicBytes, in this case Png Data,
where PngPic is a
//SQL-DataField of SQL format Image
conn = new
System.Data.Sql Client.SqlConne ction();
conn.Connection String = "...yerkyerk... ";
sqlConnInvoice. Open();
System.Data.Sql Client.SqlComma nd
_cmdLoadPicture =
new
System.Data.Sql Client.SqlComma nd("select PngPic from
PngPictures where PicID=52531;",c onn);
SqlDataReader drReader =
_cmdLoadPicture .ExecuteReader( );
drReader.Read() ;
_picBytes=(byte[])drReader.GetSq lBinary(0);
//Push data to Memory Stream
memStream = new MemoryStream();
memStream.Write
(_picBytes,0,_p icBytes.Length) ;

//Commented to follow a more general route:
//Make a Bitmap, print image into it and
save
//it into another standard format, here
*.gif,
//but could be any other
/*
//Construct image to push into response
stream
_img=Image.From Stream(memStrea m,true);
*/

//Read image size
float _height = Image.FromStrea m
(memStream).Phy sicalDimension. Height;
float _width = Image.FromStrea m
(memStream).Phy sicalDimension. Width;

//new Bitmap - adapt size if necessary:
bmp = new Bitmap(Image.Fr omStream
(memStream), new Size((int)_widt h, (int)_height));
g = Graphics.FromIm age (bmp);

//Draw on Bitmap
g.DrawImage(_im g,0,0);
memStream.Close ();
conn.Close();

/*
context.Respons e.ContentType = "image/gif";
//Save _img into Reponse stream - try
other format
_img.Save
(context.Respon se.OutputStream ,ImageFormat.Gi f);
*/

//Save bmp into Reponse stream
context.Respons e.ContentType=" image/gif";
bmp.Save(contex t.Response.Outp utStream,
System.Drawing. Imaging.ImageFo rmat.Gif);
bmp.Dispose();
g.Dispose();
}

public bool IsReusable
{
get { return true; }
}
}
//----------
Nov 18 '05 #5

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

Similar topics

3
4667
by: CanyonJ | last post by:
I've been running into a frustrating problem for a while now. I use image.FromStream to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per pixel format, so there is some compression going on when we save the file. Quite a few files are opened and closed. Everything seems to work fine for a couple hours. The only draw back is the cpu is generally at 100%. Then the code starts...
3
1691
by: Adam Stirk | last post by:
Hi, I am trying to download a image that is generated by PHP using HttpWebRequest, I believe the server uses cookies to generate the image, but I keep getting the error image from the server. Can anyone help? The code I am using is :-
6
8566
by: Saya | last post by:
Hello, This is a repost 'cause I haven't solve the problem: I can't use the System.Drawing class 'Image.FromStream' in the CompactFramework environment. What I've done with respect to Brendan's suggestion is as follows: Brendan, thanks for the reply! I'm a little bit further now, but not yet finished. I've come this far, see code below: Stream s =
6
3998
by: hb | last post by:
Hi, Would you please give me some idea to convert/decode a Base 64 encoded GIF image string to a *.gif file in ASP.Net? Thank you hb
12
9271
by: Lance | last post by:
hey all, first time vb.net 2005 user, after sticking vb6 out for a long time... anyway, using this code ====================== Dim FS As FileStream = File.OpenRead(Filename) Dim theImage As Image Try theImage = Image.FromStream(FS, False, False)
7
4820
by: bookon | last post by:
I was running into the System.Drawing.Image.FromStream "parameter is not valid" on some of the images I was retrieving from a blob column in Sql Server. I thought there were corrupt images as almost all worked (all are gifs), and only a few broke when this line ran: Image img = Image.FromStream(ms); here is the original code: b = (byte)dt.Rows.ItemArray; //b.ToString() ms = new MemoryStream(); ms.Write(b, 0, b.Length);
9
9634
by: kombu67 | last post by:
I'm reading a series of images from a MS SQL table and saving them to directory. These are staff ID pictures from our security card app. Once I've extracted the ID photo from the security app to disk, I need to reference the disk file in our HR app. As part of the process, I'm resizing the image and changing its resolution from 96 to 72 dpi. If they are not at a 72 dpi resolution, the HR app freezes. The resizing works without a hitch, but...
0
8801
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
9314
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9074
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
7953
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...
1
6634
isladogs
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...
0
5947
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
4464
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
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2110
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.