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;
            }
        }
    }

  • 相关阅读:
    我的第一个Python爬虫——谈心得
    python写第一个网页
    科学计算和可视化
    类和正则表达(自动更正,和代数运算)
    图片处理
    jieba
    汉诺塔问题
    Python核心编程(第二版)第十章习题答案
    python官方文档之open()函数的翻译
    python打开文件时提示“File was loaded in the wrong encoding:’UTF-8”根因调查
  • 原文地址:https://www.cnblogs.com/perock/p/2394052.html
Copyright © 2011-2022 走看看