将图像流式传输到手机 [英] Stream an image to a mobile phone

查看:104
本文介绍了将图像流式传输到手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了将图像流式传输到手机的逻辑,您可以在其中保存图像.该代码可在Web浏览器上使用.但是当我在电话上尝试时,它将保存图像,但是我无法查看图像.我认为该图片在手机上太大了.

当我将图像保存在Web浏览器上时,我注意到图像大小为2KB.手机上的图像大小为40KB.我将网络浏览器生成的图像复制到了手机上,并且可以查看.

我是否错过了电话的东西?电话上的逻辑原理是否相同?

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();

推荐答案

可能的答案是,并非所有的jpeg都是相同的:有些应用了更激进的压缩.
而不是将图像作为位图加载,然后向下发送,请尝试使用File.ReadAllBytes读取文件,然后使用Response.BinaryWrite直接将其发送到电话-看看是否可以改善大小差异.然后再试一次,更改您的单个像素,然后在前后将其写入新的文件服务器端.
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.


谢谢您的建议,我今天将尝试一下.我能够查看已下载到手机的文件.该文件包含当前的html页面而不是图像.您为什么要下载当前的html页面而不是图像?
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?


我尝试了您的建议使用file.ReadAllBytes,并使用Response.BinaryWrite直接发送它.结果是一样的.它下载了当前的HTML页面而不是图像.图像文件很小.
谢谢
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


这篇关于将图像流式传输到手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆