[Go] picture processing function (adaptive thumbnail add thumbnail image in DataTable)

Source: Internet
Author: User

        /// <summary>        ///to specify a generated thumbnail in a row for a DataTable/// </summary>        /// <param name= "dataTable" >Data Source</param>        /// <param name= "Datatableimagecolumnname" >column name of the data source to generate the thumbnail</param>        /// <param name= "Appendsmallpiccolumnname" >new column names for thumbnail data columns</param>        /// <param name= "ImageFormat" >Source image Format</param>        /// <param name= "MaxWidth" >maximum width of image Adaptive</param>        /// <param name= "MaxHeight" >most like adaptive maximum height</param>         Public Static voidGetsmallpic (DataTable DataTable,stringDatatableimagecolumnname,stringAppendsmallpiccolumnname, ImageFormat ImageFormat,intMaxWidth,intmaxheight) {            varDC =NewDataColumn (Appendsmallpiccolumnname, Type.GetType ("system.byte[]"));            DATATABLE.COLUMNS.ADD (DC);  for(inti =0; i < DataTable.Rows.Count; i++)            {                //Generate thumbnails Getsmallpic (Datatable.rows[i], datatableimagecolumnname, appendsmallpiccolumnname);                varImagebyte = (byte[]) datatable.rows[i][datatableimagecolumnname]; varms =NewMemoryStream (Imagebyte,0, imagebyte.length); varSourceimage =Image.fromstream (MS); intNewwidth, Newheight; Imageselfadaption (Sourceimage, MaxWidth, MaxHeight, outNewwidth, outnewheight); varMybitmap =NewBitmap (sourceimage, Newwidth, newheight); Ms=NewMemoryStream ();                Mybitmap.save (MS, ImageFormat); Datatable.rows[i][appendsmallpiccolumnname]=Ms.                ToArray (); Ms.            Close (); }        }         /// <summary>        ///gets the width of the image after adaptive (set maximum width height)/// </summary>        /// <param name= "image" >Image</param>        /// <param name= "MaxWidth" >Maximum width</param>        /// <param name= "MaxHeight" >Maximum Height</param>        /// <param name= "Newwidth" >Adaptive Image Width</param>        /// <param name= "Newheight" >self-adapting image height</param>        /// <returns></returns>         Public Static voidImageselfadaption (image Image,intMaxWidth,intMaxHeight, out intNewwidth, out intnewheight) {            varOriginalWidth =image.            Width; varOriginalHeight =image.            Height; Double_newwidth = maxWidth, _newheight =MaxHeight; Doublet = originalwidth > MaxWidth?Maxwidth:originalwidth; if(OriginalHeight * t/originalwidth >maxheight) {_newheight=MaxHeight; _newwidth= (Double) Maxheight/originalheight *OriginalWidth; }            Else{_newwidth=T; _newheight= (t/originalwidth) *OriginalHeight; } newwidth= (int) _newwidth; Newheight= (int) _newheight; }         /// <summary>        ///get an image that complements transparent areas/// </summary>        /// <param name= "image" >image to complement transparent areas</param>        /// <param name= "Mincomplementsize" >minimum pixel block size to complement transparent areas (note: must be greater than or equal to 2)</param>        /// <returns></returns>         Public StaticBitmap Getcomplementimage (image Image,intmincomplementsize) {            if(Mincomplementsize <2)            {                return NewBitmap (image. Width, image.            Height); }            Else            {                intNewwidth =image.                Width; intNewheight =image.                Height; //width to seek redundancy                intwidth = image. Width%mincomplementsize; //High Redundancy                intHeight = image. Height%mincomplementsize; //Not enough width                if(Width! =0) {Newwidth+ = Mincomplementsize-width; }                if(Height! =0)//High Enough{newheight+ = Mincomplementsize-height; }                return NewBitmap (image, Newwidth, newheight); }        }         /// <summary>        ///Get Image Object/// </summary>        /// <param name= "Imagebyte" >Binary image binary data</param>        /// <returns></returns>         Public StaticImage GetImage (byte[] imagebyte) {            if(Imagebyte! =NULL)            {                varms =NewMemoryStream (); Ms. Write (Imagebyte,0, imagebyte.length); returnImage.fromstream (MS); }            return NULL; }        /// <summary>        ///get image binary Data/// </summary>        /// <param name= "image" >Image</param>        /// <param name= "ImageFormat" >image Format</param>        /// <returns></returns>         Public Static byte[] Getimagebytearray (image image, ImageFormat imageformat) {varms =NewMemoryStream (); Image.            Save (MS, ImageFormat); varIMG =New byte[Ms.            Length]; Ms. Position=0; Ms. Read (IMG,0, Convert.ToInt32 (Ms.            Length)); Ms.            Close (); returnimg; }

[Go] picture processing function (adaptive thumbnail add thumbnail image in DataTable)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.