asp.netc#中二维码图片无法大小调整
创始人
2024-09-17 07:00:39
0

问题可能是由于生成二维码的代码没有设置图片的大小导致的。解决方法是通过设置二维码图片的大小属性来调整图片大小。

以下代码示例演示如何生成指定大小的二维码图片:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Web;
using ZXing;
using ZXing.Common;

namespace WebApplication1
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string text = "hello world!";//生成二维码的文本内容
            int width = 300;//图片宽度
            int height = 300;//图片高度
            var barcodeWriter = new BarcodeWriterPixelData
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = height,
                    Width = width,
                    Margin = 1,
                    CharacterSet = "UTF-8"
                }
            };

            var pixelData = barcodeWriter.Write(text);
            using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, PixelFormat.Format32bppRgb))
            using (var ms = new MemoryStream())
            {
                var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
                try
                {
                    // Copy the source pixels into the destination bitmap
                    System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
                }
                finally
                {
                    bitmap.UnlockBits(bitmapData);
                }

                Response.ContentType = "image/png";
                bitmap.Save(Response.OutputStream, ImageFormat.Png);
            }
        }
    }
}

在上述代码示例中,通过设置heightwidth属性来指定二维码图片的大小,从而生成指定大小的二维码图片。

相关内容

热门资讯

盘点一款!德普之星透视辅助软件... 盘点一款!德普之星透视辅助软件,德扑之心免费透视,总是是有挂(有挂工具)暗藏猫腻,小编详细说明破解器...
我来教大家!如何下载wepok... 我来教大家!如何下载wepoker安装包,wepoker怎么获得好牌,真是真的是有挂(的确有挂);1...
重大消息!hhpoker是正规... 重大消息!hhpoker是正规的吗,wepoker破解器激活码,总是真的有挂(有挂教程)1、玩家可以...
记者发布!hhpoker德州透... 记者发布!hhpoker德州透视,pokermaster辅助器,一贯是有挂(新版有挂)1、游戏颠覆性...
分享实测!wepoker有没有... 分享实测!wepoker有没有插件,hhpoker德州挂真的有吗,本来真的是有挂(确实有挂)1、让任...
新手必备!pokemmo脚本辅... 新手必备!pokemmo脚本辅助器下载,智星菠萝辅助,真是是真的有挂(有挂教程)1、每一步都需要思考...
关于!wepoker可以透视码... 关于!wepoker可以透视码,wepoker数据分析工具,切实存在有挂(有挂辅助)1、首先打开辅助...
一分钟了解!微扑克辅助,wep... 一分钟了解!微扑克辅助,wepoker辅助器最新版本更新内容,好像真的是有挂(有挂解惑)一、wepo...
普及知识!wpk控制牌是真的吗... 普及知识!wpk控制牌是真的吗,aapoker脚本怎么用,都是真的有挂(确实有挂)亲,关键说明,透视...
玩家实测!epoker有透视吗... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...