Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Mobile
I wrote a logic to stream an image to a phone where you can save it. The code works on the web browser. But when I tried it on the phone, it will save the image, but I cannot view the image. I think the image is too big on the phone.

When I save the image on the web browser, I noticed the image size is 2KB. The image size on the phone is 40KB. I copied the image that was generated from the web browser to the phone, and I was able to view it.

Am I missing something for the phone? Does the logic work the same on the phone?
   string mappath = Server.MapPath("~/TestData/test.jpg");
                   //Server.MapPath("~/images/CommImages") + "\\";
                  Bitmap bitmap = new Bitmap(mappath);
             
 
                using (MemoryStream ms = new MemoryStream())
                {
                   
 
                    // Send the encoded image to the browser

                    Response.BufferOutput = false;   // to prevent buffering 
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.ClearHeaders();
                    HttpContext.Current.Response.AddHeader("Content-Disposition",
                             "attachment; filename=USPSTest.jpg");
                    HttpContext.Current.Response.ContentType = "image/jpeg";
                    bitmap.SetPixel(10, 10, Color.Red);
                
                    bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
 
                 
 
                }
                bitmap.Dispose();
Posted 26-Aug-11 7:22am
Edited 26-Aug-11 7:23am
RaisKazi33.5K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The probable answer is that not all jpegs are the same: some have more aggressive compression applied.

Rather than loading the image as a bitmap, then sending that down, try reading the file using File.ReadAllBytes and send it directly to the phone using Response.BinaryWrite instead - see if that improves the size difference. Then try again, changing your single pixel and writing it to a new file server side both before and after.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thank you for your suggestion I will try it out today. I was able to view the file that was downloaded to the phone. The file contains the current html page instead of the image. Do you why it download the current html page instead of the image?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I tried your suggestion to use file.ReadAllBytes, and send it directly using Response.BinaryWrite.   The result was the same.   It downloaded the current HTML page instead of the image.   The image file is very small.  
Thanks
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,434
1 OriginalGriff 6,178
2 Peter Leow 2,534
3 Abhinav S 2,274
4 Maciej Los 2,268


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 30 Aug 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100