国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

超實用Image類

2019-11-17 02:34:14
字體:
來源:轉載
供稿:網友

超實用Image類

using System;    using System.Drawing;    using System.Drawing.Imaging;    using System.IO;    using System.Runtime.InteropServices;        public static class ImageHelper    {        PRivate static float[][] ColorMatrix = null;                static ImageHelper()        {            float[][] numArray = new float[5][];            numArray[0] = new float[] { 0.299f, 0.299f, 0.299f, 0f, 0f };            numArray[1] = new float[] { 0.587f, 0.587f, 0.587f, 0f, 0f };            numArray[2] = new float[] { 0.114f, 0.114f, 0.114f, 0f, 0f };            float[] numArray2 = new float[5];            numArray2[3] = 1f;            numArray[3] = numArray2;            numArray2 = new float[5];            numArray2[4] = 1f;            numArray[4] = numArray2;            ColorMatrix = numArray;        }                public static Bitmap ConstructRGB24Bitmap(byte[] coreData, int width, int height)        {            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);            BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);            Marshal.Copy(coreData, 0, bitmapdata.Scan0, coreData.Length);            bitmap.UnlockBits(bitmapdata);            return bitmap;        }                public static Image Convert(byte[] buff)        {            MemoryStream stream = new MemoryStream(buff);            Image image = Image.FromStream(stream);            stream.Close();            return image;        }                public static byte[] Convert(Image img)        {            Image image = CopyImageDeeply(img);            MemoryStream stream = new MemoryStream();            image.Save(stream, ImageFormat.Jpeg);            byte[] buffer = stream.ToArray();            stream.Close();            image.Dispose();            return buffer;        }                public static Bitmap ConvertToGrey(Image origin)        {            Bitmap image = new Bitmap(origin);            Graphics graphics = Graphics.FromImage(image);            ImageAttributes imageAttr = new ImageAttributes();            System.Drawing.Imaging.ColorMatrix newColorMatrix = new System.Drawing.Imaging.ColorMatrix(ColorMatrix);            imageAttr.SetColorMatrix(newColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);            graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);            graphics.Dispose();            return image;        }                public static Icon ConvertToIcon(Image img, int iconLength)        {            using (Bitmap bitmap = new Bitmap(img, new Size(iconLength, iconLength)))            {                return Icon.FromHandle(bitmap.GetHicon());            }        }                public static Image ConvertToJPG(Image img)        {            MemoryStream stream = new MemoryStream();            img.Save(stream, ImageFormat.Jpeg);            Image image = Image.FromStream(stream);            stream.Close();            return image;        }                public static Image CopyImageDeeply(Image img)        {            Bitmap image = new Bitmap(img.Width, img.Height, img.PixelFormat);            Graphics graphics = Graphics.FromImage(image);            graphics.DrawImage(img, 0, 0, img.Width, img.Height);            graphics.Dispose();            return image;        }                public static byte[] GetRGB24CoreData(Bitmap bm)        {            byte[] destination = new byte[(bm.Width * bm.Height) * 3];            BitmapData bitmapdata = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);            Marshal.Copy(bitmapdata.Scan0, destination, 0, destination.Length);            bm.UnlockBits(bitmapdata);            return destination;        }                public static bool IsGif(Image img)        {            FrameDimension dimension = new FrameDimension(img.FrameDimensionsList[0]);            return (img.GetFrameCount(dimension) > 1);        }                public static byte[] ReviseRGB24Data(byte[] origin, Size originSize, Size newSize)        {            Bitmap image = ConstructRGB24Bitmap(origin, originSize.Width, originSize.Height);            Bitmap bitmap2 = new Bitmap(newSize.Width, newSize.Height);            Graphics graphics = Graphics.FromImage(bitmap2);            graphics.DrawImage(image, 0f, 0f, new RectangleF(0f, 0f, (float) newSize.Width, (float) newSize.Height), GraphicsUnit.Pixel);            graphics.Dispose();            return GetRGB24CoreData(bitmap2);        }                public static void Save(Image img, string path, ImageFormat format)        {            if ((img != null) && (path != null))            {                CopyImageDeeply(img).Save(path, format);            }        }    }

 

從db里取出image類型字段:

HeadImageData =  dr["HeadImageData"] as byte[] ?? null

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宿松县| 上高县| 北碚区| 托克托县| 崇义县| 澄迈县| 洛阳市| 弋阳县| 墨江| 古丈县| 吉林市| 淅川县| 柏乡县| 遂宁市| 慈溪市| 延安市| 巴塘县| 平和县| 湘阴县| 潜山县| 神农架林区| 临夏县| 玉田县| 雷州市| 长治县| 格尔木市| 凤山市| 封丘县| 永兴县| 佛教| 澎湖县| 锡林郭勒盟| 滨州市| 宝清县| 南召县| 南京市| 察隅县| 阜新| 赣州市| 陵川县| 尉犁县|