首页 > 代码库 > image2string
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; } }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。