473,587 Members | 2,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BinaryWrite with multiple images

Hello,

I have a multipage tiff file which I am trying to output to a web browser
using Response.Binary Write. I am taking the tiff file, then looping for
each page and saving it off to a jpg in a memory stream. The problem I'm
having is when the page comes up, only the first image is shown. If I save
each page off in a file I can see that each page is unique and it's not a
problem with the stream, it seems to be a problem with outputting to the
browser. And my loop is running through for each page. My code is below,
any tips would be greatly appreciated. Thanks!

for (int i=0; i< tifPageCount; i++)
{

System.IO.Memor yStream JPGStream = new MemoryStream();

JPGStream.SetLe ngth(0);
TifImage.Select ActiveFrame(new
System.Drawing. Imaging.FrameDi mension(TifImag e.FrameDimensio nsList[0]), i);

TifImage.Save(J PGStream, System.Drawing. Imaging.ImageFo rmat.Jpeg);

JPGStream.Posit ion = 0;

byte[] NewBuffer = new byte[JPGStream.Lengt h];

JPGStream.Read( NewBuffer, 0, (int) JPGStream.Lengt h);

JPGStream.Close ();

Response.Conten tType = "image/jpeg";

Response.Output Stream.Write(Ne wBuffer, 0, NewBuffer.Lengt h);

Response.Conten tType = "text/html";

Response.Write( "<BR><BR><BR>") ;

}

Response.End();

TifImage.Dispos e();
Nov 16 '05 #1
6 7832
Richard <ab*******@mind spring.com> wrote:
I have a multipage tiff file which I am trying to output to a web browser
using Response.Binary Write. I am taking the tiff file, then looping for
each page and saving it off to a jpg in a memory stream.


You're trying to write out several responses in one. That just isn't
the way the web works. Instead, you should write out HTML which
requests each JPEG in turn. Then for each of those JPEG requests, you
supply just the single JPEG.

Btw, you should read http://www.pobox.com/~skeet/csharp/readbinary.html

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Thanks for your help, I think I see what you're saying but want to make
sure. Instead of doing a bunch of 'Response.Write ' commands, I should write
everything out to a separate string, then do a Response.Write( MyString)?

One thing I didn't mention, I can't save the pages off to files on the hard
drive, so I don't think I could do a '<img src>' tag, I have to be able to
write it out as binary. Would that be an additional problem? Thanks again!

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Richard <ab*******@mind spring.com> wrote:
I have a multipage tiff file which I am trying to output to a web browser using Response.Binary Write. I am taking the tiff file, then looping for
each page and saving it off to a jpg in a memory stream.


You're trying to write out several responses in one. That just isn't
the way the web works. Instead, you should write out HTML which
requests each JPEG in turn. Then for each of those JPEG requests, you
supply just the single JPEG.

Btw, you should read http://www.pobox.com/~skeet/csharp/readbinary.html

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Richard <ab*******@mind spring.com> wrote:
Thanks for your help, I think I see what you're saying but want to make
sure. Instead of doing a bunch of 'Response.Write ' commands, I should write
everything out to a separate string, then do a Response.Write( MyString)?
No...
One thing I didn't mention, I can't save the pages off to files on the hard
drive, so I don't think I could do a '<img src>' tag, I have to be able to
write it out as binary. Would that be an additional problem? Thanks again!


No, you *must* use <img src=...> tags. You could cache the images in
memory if you need to, but the basic way things will have to work is:

1) Browser requests page
2) You respond with a page full of <img src=...> tags
3) Browser requests an image
4) You response with the image
5) Go back to step 3 for each image you've specified
6) User gets to see pictures

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
How could I use the caching? My problem is, the files that I'm needing to
display are Tiff files. As I understand it, IE can't display tiff images.
So I'm trying to take each tiff file and convert each page to a jpg in
memory( I can't manually save the jpg out to the server to display due to
security reasons because I'd have to give ASPNET user write permission...or
will caching get around that?). Do you have any suggestions, or any links
that might help me out? Sorry I'm a bit new to the Asp.net world. Thanks
again for your help!
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Richard <ab*******@mind spring.com> wrote:
Thanks for your help, I think I see what you're saying but want to make
sure. Instead of doing a bunch of 'Response.Write ' commands, I should write everything out to a separate string, then do a Response.Write( MyString)?
No...
One thing I didn't mention, I can't save the pages off to files on the hard drive, so I don't think I could do a '<img src>' tag, I have to be able to write it out as binary. Would that be an additional problem? Thanks

again!
No, you *must* use <img src=...> tags. You could cache the images in
memory if you need to, but the basic way things will have to work is:

1) Browser requests page
2) You respond with a page full of <img src=...> tags
3) Browser requests an image
4) You response with the image
5) Go back to step 3 for each image you've specified
6) User gets to see pictures

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
Richard <ab*******@mind spring.com> wrote:
How could I use the caching? My problem is, the files that I'm needing to
display are Tiff files. As I understand it, IE can't display tiff images.
So I'm trying to take each tiff file and convert each page to a jpg in
memory( I can't manually save the jpg out to the server to display due to
security reasons because I'd have to give ASPNET user write permission...or
will caching get around that?). Do you have any suggestions, or any links
that might help me out? Sorry I'm a bit new to the Asp.net world. Thanks
again for your help!


Convert all the images into jpegs, then cache the data in the session
(read up on ASP.NET sessions in general for more information). When the
session expires, the memory will be freed, and all will be well. If you
need the images after the session has expired, you have to convert the
images again.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
I'll read up on the sessions, thanks again!
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Richard <ab*******@mind spring.com> wrote:
How could I use the caching? My problem is, the files that I'm needing to display are Tiff files. As I understand it, IE can't display tiff images. So I'm trying to take each tiff file and convert each page to a jpg in
memory( I can't manually save the jpg out to the server to display due to security reasons because I'd have to give ASPNET user write permission...or will caching get around that?). Do you have any suggestions, or any links that might help me out? Sorry I'm a bit new to the Asp.net world. Thanks again for your help!


Convert all the images into jpegs, then cache the data in the session
(read up on ASP.NET sessions in general for more information). When the
session expires, the memory will be freed, and all will be well. If you
need the images after the session has expired, you have to convert the
images again.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7

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

Similar topics

0
2203
by: Patrick Blackman | last post by:
How do you create a TIFF to store multiple images?
2
4488
by: Netian | last post by:
Hello , Please teach me how to create an Icon object with multiple images by GDI++ . I can create an Icon with a image as following , but can't do an Icon with multiple images. private Icon ReturnIcon() { Bitmap Cbitmap = new Bitmap(32, 32, PixelFormat.Format64bppPArgb); Graphics gc = Graphics.FromImage(Cbitmap); //
0
1497
by: Just Jeff | last post by:
Hi, I am a newbie to CSS. My problem at this point has to do with layout. I've inherited a website that uses nested tables for the layout of the page (www.gccnh.com), which I would like to slowly change to use CSS. My biggest problem at this point is figuring out how to deal with the multiple images that were used for the background. Most...
3
1451
by: mmr315 | last post by:
i am able to get single image at once but how to get multiple images at once
11
4152
by: Jankie | last post by:
I need to dispaly a user's multiple images in one entry.Right now,say if a user uploads 3 images,three entries for the same id display to match 3 images. I only want 1 entry to display all of a user's related images like below: Id First Name Last Name Title Image1 Image2 Image3
5
2196
by: swethak | last post by:
Hi,. when i display the image by using below code i got the error as image displayed in the form of garbage value format.plz tell that what's the mistake in my code. <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("rainlist"); $result = mysql_query(sprintf("SELECT * from pix WHERE pid = 1",...
1
2732
by: =?Utf-8?B?UmFqYWdvcGFs?= | last post by:
Question How to Upload multiple images in asp.net? (ex.Like a gmail file field)
2
3249
by: sarayu | last post by:
Hi All, How can i select multiple images by using shift or control key from my hard disk and upload it by using a submit button.For this what we use for selecting different images and for uploading.Any interface is required?Is it possible only with PHP-MYsql and Javascript.Else what technology we use ? Thanks in advance
0
3254
selvasoft
by: selvasoft | last post by:
Hi Please help me any one. I want solution for display multiple images from oracle database.Using JSP. here is my code for display one image from database. Please Any one give me some ideas. <%@ page import ="java.sql.*,java.util.*,java.awt.*,java.io.*" %> <%
3
2794
KeredDrahcir
by: KeredDrahcir | last post by:
I want to be able the upload multiple images at once. I can do a normal upload where the user browses for each image individually and I can also do where you have several browse images on the screen. What I'd like to is allow the user to select several images on one browse, in a similar way to how Facebook does it. Can anyone help me? If it...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
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...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
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...
0
3840
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...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
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...

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.