zoukankan      html  css  js  c++  java
  • image2string

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Diagnostics;
    
    namespace WindowsFormsApplication3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            public Bitmap GetImageFromBase64(string base64string)
            {
                byte[] b = Convert.FromBase64String(base64string);
                MemoryStream ms = new MemoryStream(b);
                Bitmap bitmap = new Bitmap(ms);
                return bitmap;
            }
            public string GetBase64FromImage(string imagefile)
            {
                string strbaser64 = "";
                try
                {
                    Bitmap bmp = new Bitmap(imagefile);
                    MemoryStream ms = new MemoryStream();
                    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte[] arr = new byte[ms.Length];
                    ms.Position = 0;
                    ms.Read(arr, 0, (int)ms.Length);
                    ms.Close();
                    strbaser64 = Convert.ToBase64String(arr);
                }
                catch (Exception)
                {
                    throw new Exception("Something wrong during convert!");
                }
                return strbaser64;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string fileaddress = "C:\Users\cici\Desktop\新建文件夹\20090112125352837.jpg";
                string str =GetBase64FromImage(fileaddress);
                label1.Width = 10;
                label1.Text = str;
                Debug.WriteLine("string");
                Debug.WriteLine(label1.Text);
                Bitmap bm = GetImageFromBase64(label1.Text);
                this.pictureBox1.Image = bm;
            }
        }
    }
  • 相关阅读:
    查看数据库错误日志的位置
    快速过滤出完整的SQL语句
    使用apidocJs快速生成在线文档
    vs开发nodejs系列之 修改新建js文件的模板
    Node.js 入门资料
    ECMAScript 6 学习资料
    NodeJS学习目录
    MongoDB学习笔记系列~目录
    sails ORM组件 Waterline v0.10 英文文档
    node.js---sails项目开发
  • 原文地址:https://www.cnblogs.com/rosizel/p/3891283.html
Copyright © 2011-2022 走看看