c#图片base64去转义字符_C# 将图片转成Base64字符串,再将字符串转成图片,然后将图片存储到服务器文件夹中,求代码。感激不尽...
展开全部
网上多的是:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
namespace base64_img
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//图片62616964757a686964616fe4b893e5b19e31333335326163 转为 base64编码的文本
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "选择要转换的图片";
dlg.Filter = "Image files (*.jpg;*.bmp;*.gif)|*.jpg*.jpeg;*.gif;*.bmp|AllFiles (*.*)|*.*";
if (DialogResult.OK == dlg.ShowDialog())
{
ImgToBase64String(dlg.FileName);
}
}
//图片 转为 base64编码的文本
private void ImgToBase64String(string Imagefilename)
{
try
{
Bitmap bmp = new Bitmap(Imagefilename);
this.pictureBox1.Image = bmp;
FileStream fs = new FileStream(Imagefilename + ".txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
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();
String strbaser64 = Convert.ToBase64String(arr);
sw.Write(strbaser64);
sw.Close();
fs.Close();
MessageBox.Show("转换成功!");
}
catch (Exception ex)
{
MessageBox.Show("ImgToBase64String 转换失败/nException:" + ex.Message);
}
}
//base64编码的文本 转为 图片
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "选择要转换的base64编码的文本";
dlg.Filter = "txt files|*.txt";
if (DialogResult.OK == dlg.ShowDialog())
{
Base64StringToImage(dlg.FileName);
}
}
//base64编码的文本 转为 图片
private void Base64StringToImage(string txtFileName)
{
try
{
FileStream ifs = new FileStream(txtFileName, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(ifs);
String inputStr = sr.ReadToEnd();
byte[] arr = Convert.FromBase64String(inputStr);
MemoryStream ms = new MemoryStream(arr);
Bitmap bmp = new Bitmap(ms);
bmp.Save(txtFileName + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
//bmp.Save(txtFileName + ".bmp", ImageFormat.Bmp);
//bmp.Save(txtFileName + ".gif", ImageFormat.Gif);
//bmp.Save(txtFileName + ".png", ImageFormat.Png);
ms.Close();
sr.Close();
ifs.Close();
this.pictureBox1.Image = bmp;
MessageBox.Show("转换成功!");
}
catch (Exception ex)
{
MessageBox.Show("Base64StringToImage 转换失败/nException:"+ex.Message);
}
}
}
}
c#图片base64去转义字符_C# 将图片转成Base64字符串,再将字符串转成图片,然后将图片存储到服务器文件夹中,求代码。感激不尽...相关推荐
- c#图片base64去转义字符_C# imgage图片转base64字符/base64字符串转图片另存成
//图片转为base64编码的字符串 protected string ImgToBase64String(string Imagefilename) { try { Bitmap bmp = new ...
- c#图片base64去转义字符_C#实现字符串与图片的Base64编码转换操作示例
本文实例讲述了C#实现字符串与图片的Base64编码转换操作.分享给大家供大家参考,具体如下: using System; using System.Collections.Generic; usin ...
- c#图片base64去转义字符_C#实现字符串与图片的Base64编码转换操作示例|chu
本文实例讲述了C#实现字符串与图片的Base64编码转换操作.分享给大家供大家参考,具体如下: using System; using System.Collections.Generic; usin ...
- c#图片base64去转义字符_c#中图片与base64互相转换
本教程说明如何在C#.NET Windows Forms Application中将图像转换为base64字符串,以及将base64字符串转换为图像. 您可以创建一个新的Windows窗体应用程序项目 ...
- matlab读取一个文件的图片大小,Matlab读取文件夹中子文件夹中的图片并修改尺寸...
今天被师兄问到如何利用matlab批处理图片,觉得很简单嘛 就让他去百度 结果只百度到处理文件夹中图片的程序 好吧 这里放上如何处理文件夹中子文件夹的图片 现状:在一个名为casia的文件夹中,里面有 ...
- C# ASP.NET MVC 图片上传的多种方式(存储至服务器文件夹,阿里云oss)
图片上传时我们进场用到的一个功能今天将他整理了一下写了个demo希望对大家有用 该demo分为如下 1.上传至至服务器文件夹 2.上传至阿里云oss 3.百度webupload上传图片 效果图如下: ...
- python图片保存jpg、show变成bmp_Python 实现判断图片格式并转换,将转换的图像存到生成的文件夹中...
Python 实现判断图片格式并转换,将转换的图像存到生成的文件夹中 我就废话不多说了,直接上代码吧! import Image from datetime import datetime impor ...
- 图片名字存在txt文件中,从另一个装有图片的文件夹中筛选对应的图片。python代码
txt文件的每一行都存一张图片的名字(带尾缀),从另一个存有全部图片的文件中筛选txt中存在的图片. # -*- coding: UTF-8 -*- # !/usr/bin/env python im ...
- MATLAB 保存imshow绘制图片到指定文件夹中的两种方法
MATLAB 保存imshow绘制图片到指定文件夹中的两种方法 imwrite函数 imwrite(image,filename) imwrite(image,filename)是将图像数据image ...
最新文章
- Spring 建立简单的示例
- 最大流增广路(KM算法) HDOJ 1853 Cyclic Tour
- 一个具有20位地址和32位字长的存储器_step7编程之地址概念详解
- 【小白学习C++ 教程】一、Vscode和 Visual stdudio配置C++环境
- oralce group by字符串拼接
- linux基础学习(十)
- MySQL架构设计相关的方式方法和软件介绍
- 用纯fme批量生成界址点成果表(模板格式全部自拟)
- Jetson Nano 系列之:25FPS性能优化之路
- LeCo-198. 打家劫舍
- 大数据剖析:想与北上争雄,深圳到底还差在哪儿?
- Javafx 实现国际象棋游戏
- 集成seata到springboot,cloud项目,找不到事务分组
- outlook邮件存到本地_如何在Microsoft Outlook中将电子邮件(和其他项目)另存为文件
- Socket通信客户端报错Connection reset
- c 语言的三国杀代码大全,三国杀武将语言代码~
- 《花开半夏》--2 消息,魏如风(1)
- 滴滴国际化项目 Android 端演进
- CoreAnimation图层的树状结构和寄宿图
- 什么人适合报考同等学力申硕,避坑指南来了