• 读取图片的DLL


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SqlTypes;
    using System.Drawing;
    using System.IO;
    namespace NJ_MF_ClassLib
    {
        public class tif
        {
            //private System.Windows.Forms.PictureBox pictureBox1;
            public static byte[] tiftojpg(byte[] _bin)
            {
                // System.Windows.Forms.PictureBox picbox = new System.Windows.Forms.PictureBox();
                // System.IO.BinaryReader binReader = new System.IO.BinaryReader();
                // binReader.Read();
                // Stream s = new MemoryStream();
                // SqlBytes bytes = new SqlBytes(_bin);
                // System.IO.File.WriteAllBytes(@"C:\a.bin", newBin);
                // StreamWriter sw = new StreamWriter(@"C:\1.txt", true);
                // sw.WriteLine("111111111111");
                // sw.WriteLine(_bin.Length.ToString());
                // memorystream.Read(byteFileflag,0,2);
                // byteFileflag.Equals(0x4949);
                // picbox.Image = System.Drawing.Image.FromStream(s);
                // System.IO.File.WriteAllBytes(@"C:\a.bin", newBin);
                // bmp2.Save(@"C:\test.jpg");
                //----------------------------------------------
                if (_bin == null)
                    return _bin;
                byte[] newBin  = new byte[_bin.Length-7];
                Array.Copy(_bin,7, newBin, 0,newBin.Length);                                       
                byte[] byteFileflag = new byte[2];           
                Array.Copy(newBin, 0, byteFileflag, 0, 2);           
                byte byteFlag = byteFileflag[0];
                if (byteFlag == 0x49)
                {
                    MemoryStream memorystream = new MemoryStream(newBin);
                    memorystream.Position = 0;

                    MemoryStream retMemoryStream = new MemoryStream();
                    Bitmap bmp = new Bitmap(memorystream);

                    bmp.Save(retMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);              
                    byte[] retBinary = new byte[retMemoryStream.Length];
                    retMemoryStream.Position = 0;
                    retMemoryStream.Read(retBinary, 0, (int)retMemoryStream.Length);

                    retMemoryStream.Close();
                    retMemoryStream.Dispose();

                    memorystream.Close();
                    memorystream.Dispose();
                    return retBinary;
                }
                else
                {
                    return newBin;
                }

            }

            static int IndexOf(byte[] s, byte[] pattern)
            {
                int slen = s.Length;
                int plen = pattern.Length;
                for (int i = 0; i <= slen - plen; i++)
                {
                    for (int j = 0; j < plen; j++)
                    {
                        if (s[i + j] != pattern[j]) goto next;
                    }
                    return i;
                next: ;
                }
                return -1;
            }
        }
    }

  • 相关阅读:
    春季学期第十二周作业
    2019春第三次课程设计实验报告
    春季学期第十一周作业
    春季学期第十周作业
    春季学期第九周作业
    第五周总结 & 实验报告(三)
    第四周总结 & 实验报告(二)
    实验报告(一)&第三周总结
    第二周小结
    2019春总结
  • 原文地址:https://www.cnblogs.com/perock/p/2394052.html
Copyright © 2020-2023  润新知