看了一晚上 没看出来 哪错了...
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public partial class _homework2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String Caption = TextBox1.Text;
bool IsPublic = false;
if (CheckBox1.Checked)
IsPublic = true;
AddAlbum(Caption, IsPublic);
Label3.Text = "相册建立成功! " ;
}
public static void AddAlbum(string Caption, bool IsPublic)
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[ "Personal "].ConnectionString);
string sql;
sql = "INSERT INTO[Albums]([Caption],[IsPublic])VALUES(@Caption,@IsPublic) ";
SqlCommand command = new SqlCommand(sql, connection);
command.Parameters.Add(new SqlParameter( "@Caption ", Caption));
command.Parameters.Add(new SqlParameter( "@IsPublic ", IsPublic));
connection.Open();
command.ExecuteNonQuery();
}
private static Size CalculateDimensions(Size oldSize, int targetSize)
{
Size newSize = new Size();
if (oldSize.Height > oldSize.Width)
{
newSize.Width = (int)(oldSize.Width * ((float)targetSize / (float)oldSize.Height));
newSize.Height = targetSize;
}
else
{
newSize.Width = targetSize;
newSize.Height = (int)(oldSize.Height * ((float)targetSize / (float)oldSize.Width));
}
return newSize;
}
private static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
{
System.Drawing.Image oldImage = System.Drawing.Image.FromStream(new MemoryStram(imageFile));
Size newSize = CalculateDimensions(oldImage.Size, targetSize);
Bitmap newImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb);
Graphics canvas = Graphics.FromImage(newImage);
canvas.SmoothingMode = SmoothingMode.AntiAlias;
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
canvas.DrawImage(oldImage, new Rectangle(new Point(0, 0), newSize));
MemoryStream m = new MemoryStream();
newImage.Save(m, ImageFormat.Jpeg);
return m.GetBuffer();
}
public static void AddPhoto(int AlbumID, string Caption, byte[] BytesOriginal)
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[ "Personal "].ConnectionString);
string sql;
sql = "INSERT INTO [Photos] ( [AlbumID], [BytesOriginal], [Caption], [BytesFull], [BytesPoster], [BytesThumb] ) "
+ "VALUES ( @AlbumID, @BytesOriginal,@Caption,@BytesFull, @BytesPoster, @BytesThumb ) ";
SqlCommand command = new SqlCommand(sql, connection);
command.Parameters.Add(new SqlParameter( "@AlbumID ", AlbumID));
command.Parameters.Add(new SqlParameter( "@Caption ", Caption));
command.Parameters.Add(new SqlParameter( "@BytesOriginal ", BytesOriginal));
command.Parameters.Add(new SqlParameter( "@BytesFull ", ResizeImageFile(BytesOriginal, 600)));
command.Parameters.Add(new SqlParameter( "@BytesPoster ", ResizeImageFile(BytesOriginal, 198)));
command.Parameters.Add(new SqlParameter( "@BytesThumb ", ResizeImageFile(BytesOriginal, 100)));
connection.Open();
command.ExecuteNonQuery();
}
protected void Button2_Click(object sender, EventArgs e)
{
Stream imgDataStream = FileUpload1.PostedFile.InputStream;
int imgDataLen = FileUpload1.PostedFile.ContentLength;
string Caption = TextBox2.Text;
byte[] BytesOriginal = new byte[imgDataLen];
int n = imgDataStream.Read(BytesOriginal, 0, imgDataLen);
AddPhoto(1, Caption, BytesOriginal);
Label3.Text = "图片上传成功 ";
}
}
错误1找不到类型或命名空间名称“MemoryStram”(是否缺少 using 指令或程序集引用?)C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSite8\homework2.aspx.cs6477C:\...\WebSite8\
错误2与“System.Drawing.Image.FromStream(System.IO.Stream)”最匹配的重载方法具有一些无效参数C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSite8\homework2.aspx.cs6441C:\...\WebSite8\
错误3参数“1”: 无法从“MemoryStram”转换为“System.IO.Stream”C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSite8\homework2.aspx.cs6473C:\...\WebSite8\
[解决办法]
MemoryStram==> MemoryStream
[解决办法]
参数“1”: 无法从“MemoryStram”转换为“System.IO.Stream”
仔细看看