代码
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
}
转载于:https://www.cnblogs.com/angleSJW/archive/2010/03/16/1687457.html
相关资源:VB C# 图片 文字 加密 解密 base64