C#.ASP代码如下1、我用的是 ASP.NET 2.0 
2、FLASH用的是CS3
3、FLASH发送给ASP.NET的是一个二进制数据,.NET读取后,把数据保存成一个图片。问题
1、测试情况下,一点问题都没有,可一发布就不好用。
2、图片保存的路径也不能改变,我想换个目录都不行。
3、ASP.NET代码我是根据JSP代码修改过来的,JSP我不懂;自我错误分析:
1、JSP代码翻译成 C#代码有问题
2、C#代码部分也有问题但我找不到错误地方
C#代码如下:
public partial class createImg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            try
            {
                Stream reader = Request.InputStream;
                FileStream fs = new FileStream("C:\\logo.gif", FileMode.OpenOrCreate, FileAccess.Write);
                byte[] buff = new byte[1024];
                int c = 0; //实际读取的字节数
                while ((c = reader.Read(buff, 0, buff.Length)) > 0)
                {
                    fs.Write(buff, 0, c);
                }
                fs.Close();
            }
            catch
            {
                //
            }        }
    }
}
JSP代码如下:<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%
int v;
String filePath = request.getRealPath(System.currentTimeMillis()+".jpg");
BufferedInputStream inputStream = new BufferedInputStream(request.getInputStream());
FileOutputStream outputStream = new FileOutputStream(new File(filePath));
byte [] bytes = new byte[1024];
while((v=inputStream.read(bytes))>0){
outputStream.write(bytes,0,v);
}
outputStream.close();
inputStream.close();
%>

解决方案 »

  1.   

    我抓的是AS2.0,不过C#带代应该一样    
    protected void Page_Load(object sender, EventArgs e)
        {
            //flash post出来的数据,有width,height
            string account = User.Identity.Name;
            if (account == string.Empty)
            {
                return;
            }
            int width = 0;
            int height = 100;        if (!int.TryParse(Request.Form["width"], out width) &&
             !int.TryParse(Request.Form["height"], out  height))
            { 
                throw new ApplicationException("照片格式不正确!");
            }
            //测试post来的数据
            //Response.Write(Request.Form);
            //Response.End();
            //定义bitmap ,宽,高,和格式
             Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
             Rectangle rect = new Rectangle(0, 0, width, height);
             //本来用的方案 copy bit数组
           //  System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
           //  IntPtr iPtr = bmpData.Scan0;
           //    int iStride = bmpData.Stride;         int iBytes = width * height * 3;//宽*长 *3是因为每一点都需要rgb三种色值填充
             byte[] PixelValues = new byte[iBytes];         int iPoint = 0;         bmp.MakeTransparent(Color.White);
             for (int i = 0; i < height; i++)//填充每一行的色值
             {
                 string[] ss=Request.Form["px"+i].Split(','); //解析行数据分组
                 for (int j = 0; j < width; j++)
                 {
                     string values = ss[j];
                     while (values.Length < 6)
                     {
                         values = "0" + values; //位不足填充
                     }
                     string s1, s2, s3;//获取RGB
                     s1 = values.Substring(0, 2);
                     s2 = values.Substring(2, 2);
                     s3 = values.Substring(4, 2);
                    // int iGray = Gray[i, j];
                    // int gr = Convert.ToInt32(ss[j],16);
                   //  PixelValues[iPoint] = PixelValues[iPoint + 1] = PixelValues[iPoint + 2] = Convert.ToByte(gr);
                     PixelValues[iPoint] = Convert.ToByte(Convert.ToInt32(s1,16));
                     PixelValues[iPoint+1] = Convert.ToByte(Convert.ToInt32(s2, 16));
                     PixelValues[iPoint+2] = Convert.ToByte(Convert.ToInt32(s3, 16));
                     //设置点陈color
                      bmp.SetPixel(j, i, Color.FromArgb(PixelValues[iPoint], PixelValues[iPoint + 1], PixelValues[iPoint + 2]));
                     
                     iPoint += 3;
                   //  Response.Write(gr+"<br/>");
                 }
             }
            // System.Runtime.InteropServices.Marshal.Copy(PixelValues, 0, iPtr, iBytes);        // bmp.UnlockBits(bmpData);
             //注意,目录一下要有权限,至少要有User和户修改权限
             string root = Server.MapPath(".");
             string path = root+@"\pics\" + DateTime.Now.ToFileTime() + ".jpg";
             bmp.Save(path, ImageFormat.Jpeg);
           
        }
      

  2.   

    关注此类问题大家看看我开发的网站。请给点指导。http://www.xubintailcn/tianyi/  对了,那位朋友用Flash,怎样访问DataGrid的行,(ROW这个概念在这儿好像是不存在的)