zoukankan      html  css  js  c++  java
  • 读取图片的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;
            }
        }
    }

  • 相关阅读:
    二级JAVA考证笔记
    JAVA异常处理机制
    notepad++安装nppFTP
    nginx conf_ctx ****
    ngx_string()错误分析
    nginx
    char *p[] 和char**的思考
    LeetCode.接雨水
    LeetCode.atoi
    LeetCode.数字转罗马数字
  • 原文地址:https://www.cnblogs.com/perock/p/2394052.html
Copyright © 2011-2022 走看看