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                    }
  • 相关阅读:
    jvm gc 日志详细信息的输出(一)
    带宽与数据传输速率
    功率半导体器件
    超链接标签a样式生效,取消下划线,文字垂直(上下)居中
    防范诈骗
    去掉table中的空隙
    html中使用js实现内容过长时部分
    背景色透明度设置
    jQuery给标签写入内容
    多个div居中显示
  • 原文地址:https://www.cnblogs.com/angleSJW/p/1687457.html
Copyright © 2011-2022 走看看