本帖最后由 laodan 于 2023-5-24 17:44 编辑
有VB.NET的代码,使用base64编码,然后自定义图像大小。你可以看看
使用控件:PictureBox1
[Visual Basic .NET] 纯文本查看 复制代码 Dim base64String As String = qrcode (base64编码的图像)
Dim imageBytes As Byte() = Convert.FromBase64String(base64String)
Dim ms As New MemoryStream(imageBytes, 0, imageBytes.Length)
ms.Write(imageBytes, 0, imageBytes.Length)
Dim img As Image = Image.FromStream(ms, True)
Dim resizedImg As New Bitmap(250, 250)
Dim g As Graphics = Graphics.FromImage(resizedImg)
g.DrawImage(img, New Rectangle(0, 0, 250, 250))
PictureBox1.Image = resizedImg
我尝试给你转为了C#,你看看能不能用
[Visual Basic .NET] 纯文本查看 复制代码 string base64String = qrcode; //假设qrcode为字符串类型的base64编码的图像
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Write(imageBytes, 0, imageBytes.Length);
Image img = Image.FromStream(ms, true);
Bitmap resizedImg = new Bitmap(250, 250);
Graphics g = Graphics.FromImage(resizedImg);
g.DrawImage(img, new Rectangle(0, 0, 250, 250));
PictureBox1.Image = resizedImg;
|