zoukankan      html  css  js  c++  java
  • C# Base64加解密图片

    代码
     1  // 读取图片信息并用pictureBox显示
     2                 byte[] imageBytes=Convert.FromBase64String(str_picture);
     3                 MemoryStream memoryStream = new MemoryStream(imageBytes, 0, imageBytes.Length);
     4                 memoryStream.Write(imageBytes, 0, imageBytes.Length);
     5                 Image image = Image.FromStream(memoryStream);
     6                 memoryStream.Close();
     7 
     8                 // 将图片放置在 PictureBox 中
     9                 this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
    10                 this.pictureBox1.Image = image;
    11 
    12 //将选中图片进行Base64加密
    13                 OpenFileDialog openfile = new OpenFileDialog();
    14                 openfile.Title = "请为商品选择相应的图片";
    15                 openfile.Filter = "商品图片                      (*.jpg;*.bmp;*png)|*.jpeg;*.jpg;*.bmp;*.png|AllFiles(*.*)|*.*";
    16                 if (DialogResult.OK == openfile.ShowDialog())
    17                 {
    18                    try
    19                   {
    20                     Bitmap bmp = new Bitmap(openfile.FileName);
    21                     pictureBox1.Image = bmp;
    22                     pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
    23                     MemoryStream ms = new MemoryStream();
    24                     bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    25                     byte[] arr = new byte[ms.Length];
    26                     ms.Position = 0;
    27                     ms.Read(arr, 0, (int)ms.Length);
    28                     ms.Close();
    29                     str_picture = Convert.ToBase64String(arr);
    30                    }
    31                   catch { }
    32                    }
  • 相关阅读:
    0909我眼中的编译原理
    你要的所有数据源都在这里了!
    JAVA多线程和并发基础
    写的代码小有成就+今日总结--购买产品---20200508
    mysql数据库时区问题
    【Spring】——声明式事务配置详解
    SpringBoot整合阿里云OSS文件上传、下载、查看、删除
    一文看懂:网址,URL,域名,IP地址,DNS,域名解析
    git快速入门
    批处理框架spring batch基础知识介绍
  • 原文地址:https://www.cnblogs.com/angleSJW/p/1687457.html
Copyright © 2011-2022 走看看