日期:2014-05-17  浏览次数:20477 次

ms.GetBuffer() 是把内存里边的东西,保存为2进制格式吗?
ms.GetBuffer() 是把内存里边的东西,保存为2进制格式吗?



ms = new MemoryStream();
final_image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Thumbnail thumb = new Thumbnail(thumbnail_id, ms.GetBuffer()  );


完整

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.Collections.Generic;

public partial class upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        System.Drawing.Image thumbnail_image = null;
        System.Drawing.Image original_image = null;
        System.Drawing.Bitmap final_image = null;
        System.Drawing.Graphics graphic = null;
        MemoryStream ms = null;

        try
        {
            // Get the data  得到上传的文件
            HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];

            // Retrieve the uploaded image  把上传文件转化为 Image
            original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream);




            // Calculate the new width and height 下边一整段,都是计算长宽的,具体算法没有深究
            int width = original_image.Width;     //原始宽度
            int height = original_image.Height;   //原始长度
            int target_width = 200;
            int target_height = 200;
            int new_width, new_height;

            float target_ratio = (float)target_width / (float)target_height;  //目标 宽长比
            float image_ratio = (float)width / (float)height;   //原始  宽长比

            if (target_ratio > image_ratio)   //计算出新的长宽。 
            {
          &n