我是用Winfrom开发,希望能帮到你
先建一个类,Copy可用..........
using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Runtime.Serialization.Formatters.Binary; //引入供序列化Image对象使用
保存图片到数据库后台代码
namespace Drugger.WebUI.Modules
{
using System;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Drugger.BusinessFacade;
using Drugger.Model;
using Drugger.SystemFramework;
using Drugger.WebUI.Modules;
using Drugger.WebCtrlLib;
/// <summary>
/// 图片编辑控件
/// </summary>
public class PhotoEditModule: UserControl
{
protected RequiredFieldValidator valFilePhoto;
protected RegularExpressionValidator valExpFilePhoto;
protected HtmlInputFile filePhoto;
Stream imgStream = filePhoto.PostedFile.InputStream;
int imgLength = filePhoto.PostedFile.ContentLength;
byte[]imgData = new byte[imgLength];
int n = imgStream.Read(imgData, 0, imgLength);
#endregion
if (Page.IsValid)
{
#region 保存数据到数据库
int retVal = - 1;
PhotoModel photoModel = new PhotoModel();
PhotoSystem photoSystem = new PhotoSystem();
PhotoModel.PhotoRow row = photoModel.Photo.NewPhotoRow();
后台代码
namespace Drugger.WebUI.Modules
{
using System;
using System.Text;
using System.IO;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using Drugger.BusinessFacade;
using Drugger.SystemFramework;
/// <summary>
/// 图片显示Web页
/// </summary>
public class Picture: Page
{
private void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int photoId = 0;
string photoIdText = Request.QueryString.Get("photoId");
photoId = (int)photoIdText;
byte[]photo = (new PhotoSystem()).GetPhotoByPhotoID(photoId);