Ask a Question related to ASP.NET General, Design and Development.
-
David J. Berman #1
Re: HttpHandler for images and browser behavior
No no I don't know why that doesn't work because it really should but I'll
give you a snippet that DOES work. Oddly enough, it works by NOT specifying
the content type. Bizzare eh? Also, it works fine as URL in address bar or
as img src=.
Here ya go free of charge. Sorry if it looks like html to you - you get
what you pay for :) Insert it using paste as html or something and it
should look fine. This code shows a thumbnail picture from a sql database
using a simple select thumbnail from pictures query. If there is no data,
it draws a black box instead. Notice that I had to comment out the mime
type in order to get it to work:
OleDbConnection myConn = new
OleDbConnection(ConfigurationSettings.AppSettings["OLEDBDSN"].ToString());
OleDbCommand myCmd = new OleDbCommand(sqlText, myConn);
OleDbDataReader dr = null;
//open the database and get a datareader
try
{
myConn.Open();
dr = myCmd.ExecuteReader();
if ( dr.Read() ) // Check to make sure we loaded a user record
{
// Response.ContentType = "image/jpeg";
Response.BinaryWrite( (byte[]) dr["Thumbnail"] );
}
else
{
// Draw the .JPG
//------------------------------------------------------
// Create a bitmap that measures 130 pixels square
Bitmap bitmap = new Bitmap (130, 130,
PixelFormat.Format32bppArgb);
// Create a Graphics object for drawing to the bitmap
Graphics g = Graphics.FromImage (bitmap);
// TODO: Use Graphics methods to draw the image
// Set the response's content type to image/jpeg
// Response.ContentType = "image/jpeg";
// Write the image to the HTTP response
bitmap.Save (Response.OutputStream, ImageFormat.Jpeg);
// Clean up before returning
bitmap.Dispose ();
g.Dispose ();
//------------------------------------------------------
} // Draw the image
} // try
catch(Exception myException)
{
Trace.Write("Oops. The error: " + myException.Message);
} // catch
finally
{ // Do this no matter what
// Close the database connenction
myConn.Close();
}
} // Done trying to load image from database
"Kevin Spencer" <kevin@SPAMMERSSUCKtakempis.com> wrote in message
news:#vYfYUZODHA.2096@TK2MSFTNGP12.phx.gbl...I> Thanks again, George. Adding a "Content-Disposition" header had no effect.header> have to agree that it must be a bug in IE. As I mentioned before, if I put
> the address with QueryString into an image tag in an HTML page, it renders
> fine. But if I type the address in the browser window, it doesn't. Hope
> Microsoft is listening to this thread!
>
> Thanks again,
>
> Kevin Spencer
> Microsoft FrontPage MVP
> Internet Developer
> [url]http://www.takempis.com[/url]
> Big things are made up of
> lots of Little things.
>
> "George Ter-Saakov" <we@hotmail.com> wrote in message
> news:%238KfD9YODHA.1364@TK2MSFTNGP10.phx.gbl...> URL.> > Then it's a bug in the browser.
> > First it must check Mime type. and only then to check extension of the> could,> >
> > George.
> >
> > "Kevin Spencer" <kevin@SPAMMERSSUCKtakempis.com> wrote in message
> > news:OBXss0XODHA.2476@TK2MSFTNGP10.phx.gbl...> > > Thanks George. Believe me, I checked the ContentType in every way I> know.> > > and it is correct. I will try using Content-Disposition and let you> That> > >
> > > As for your question as to how the browser knows to hand it off to
> > > Photoshop, that's no mystery. The original file had a .psd extension.> > that> > > file extension is mapped to Photoshop in the OS.
> > >
> > > Thanks again,
> > >
> > > Kevin Spencer
> > > Microsoft FrontPage MVP
> > > Internet Developer
> > > [url]http://www.takempis.com[/url]
> > > Big things are made up of
> > > lots of Little things.
> > >
> > > "George Ter-Saakov" <we@hotmail.com> wrote in message
> > > news:uwE9h02NDHA.2480@TK2MSFTNGP10.phx.gbl...
> > > > The only question I have how does it know to pop up Adobe Photoshop?
> > > > It seems to me it because of the file extension in the ULF.
> > > > Are you sure that proper MIME type is set? It does not mean anything> > > it
> > > > works in <img src=..> because it's determines image type by the"inline;filename=image.jpg")> > of> > Content-Disposition.> > > > the image.
> > > >
> > > > Anyway you probably can change the behavior by using> > > > Response.AddHeader("Content-Disposition",original> mime> > > > But i would double check that correct mime type is set. Show us the> with> > return> > > > type you are setting. It must be "img/jpeg" for jpeg file.
> > > >
> > > > George.
> > > >
> > > > "Kevin Spencer" <kevin@SPAMMERSSUCKtakempis.com> wrote in message
> > > > news:%23GsNHG1NDHA.3204@TK2MSFTNGP10.phx.gbl...
> > > > > I'm writing an HttpHandler for images that can modify images and> > > > the
> > > > > odified version of the image. One requirement is that it can work> file> > > > .psd
> > > > > files, which are Adobe Photoshop images, and can't, of course, be
> > > rendered
> > > > > by a browser. However, one of the modifications is to change the> > > > format
> > > > > of the image requested. So, the browser might request
> > > > > "foo.psd?cmd=fmt&ext=jpg" to get a JPG back instead of therequest> and> > PSD> > > > > file. For testing, I created an HTML page with an image tag in it,> > > set
> > > > > it as my Start Page, so that I can debug in the IDE. When aimage> > for> > > a
> > > > > different format is received by the Handler, it sets the
> > > > > Response.ContentType property to the proper MIME type for thethe> > file> > > > > type it returns. In the HTML page, the browser correctly renderssame> > JPG> > > > in
> > > > > the page. However, if I put the URL to the image file, with theget> the> > > > > QueryString, in the browser's Address window and run it that way,> > > > > browser doesn't seem to recognize the ContentType header, and Iit> an> > .psd> > > > > "Open/Save" dialog. Of course, if I choose "Open," Adobe Photoshop
> > > opens,
> > > > > and gives me an error (since the file is NOT a psd, but only has a> > > > > extension). If I choose to Save the image, and name it with a .jpg
> > > > > extension, it opens fine in whatever image program I want to openbehavior.> > > with,
> > > > > as it IS a JPG.
> > > > >
> > > > > What I don't understand is whay the difference in browsercorrectly> In> and> > > > both
> > > > > cases, the browser is sending an identical Request for the image,> > > > > getting back the identical Response. However, it displays> in> directly?> > > the
> > > > > context of an HTML page, but not as just a file. Is there any HTTP
> > > header
> > > > I
> > > > > can append that will enable the browser to display the image>> >> > > > >
> > > > > TIA,
> > > > >
> > > > > Kevin Spencer
> > > > > Microsoft FrontPage MVP
> > > > > Internet Developer
> > > > > [url]http://www.takempis.com[/url]
> > > > > Big things are made up of
> > > > > lots of Little things.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
David J. Berman Guest
-
Open Browser Window behavior
Hi Using DW4 - I have links on a page that I have opening in a new window using the Open Browser Window behavior. I have set attributes such as... -
Tool Tip behavior for images
In Director I often use the built-in behavior that allows me to show a line of text (like a tool tip) when I roll my cursor over a sprite. What I... -
Check Browser behavior in MX
Hi there, I put the behavior which comes with MX into an index page for a site I am working on only to discover that it only recognizes IE5.xx and... -
Modifying "Open Browser Window" behavior to launch a maximized browser
I want to launch a web application in a fullscreen browser window with nothing but the title bar and the accompanying window borders (I do not want... -
Duplicate Browser Window Behavior - Why?
> Change this - Actually, change it to this: <a href="kitchens/kitchen_one/kitchen_portfolio_1.htm"...



Reply With Quote

