CAD绘制二维码(网页版)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

//新建一个COM组件对象 参数为COM组件类名

var getPt = mxOcx.NewComObject("IMxDrawUiPrPoint");

getPt.message = "点取插入点";

if (getPt.go() != 1) {

    return;

}

var pos = getPt.value();

if (pos == null)

    return;

//新建一个COM组件对象 参数为COM组件类名

var qrCode = mxOcx.NewEntity("IMxDrawQrCode");

//返回二维码文本

qrCode.Text = txt;

//中心点

qrCode.Center = pos;

//二维码缩放比例

qrCode.Scale = 20;

//二维码旋转角度

qrCode.Rotation = 30 * 3.1415925 / 180.0;

//绘实体 参数为实体对象

mxOcx.DrawEntity(qrCode);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在CAD绘制二维码,您可以使用以下步骤: 1. 在CAD中创建一个新的图层,用于绘制二维码。 2. 使用CAD .NET API中的Line对象绘制二维码的线条。 3. 通过调用Graphics.DrawLines方法将线条绘制CAD中。 4. 通过二维码生成库将文本转换为二维码,然后将其分解为线条并将其绘制CAD中。 以下是一个示例代码,用于在CAD绘制二维码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using ZXing; using ZXing.Common; namespace CadQRCode { public class QRCode { [CommandMethod("DrawQRCode")] public void DrawQRCode() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; // Prompt the user to enter the text to encode PromptStringOptions pso = new PromptStringOptions("\nEnter the text to encode: "); PromptResult pr = doc.Editor.GetString(pso); if (pr.Status != PromptStatus.OK) { return; } // Generate the QR code from the entered text BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new EncodingOptions { Height = 200, Width = 200, Margin = 0 } }; BitMatrix bitMatrix = writer.Encode(pr.StringResult); // Create a new layer for the QR code using (Transaction trans = db.TransactionManager.StartTransaction()) { LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead); ObjectId layerId; if (!lt.Has("QRCode")) { LayerTableRecord ltr = new LayerTableRecord { Name = "QRCode", Color = Color.FromColorIndex(ColorMethod.ByAci, 1) }; layerId = lt.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); } else { layerId = lt["QRCode"]; } // Create a new Polyline object to hold the lines of the QR code Polyline qrCode = new Polyline(); qrCode.Layer = layerId; // Loop through the rows and columns of the bit matrix to create the lines of the QR code for (int y = 0; y < bitMatrix.Height; y++) { for (int x = 0; x < bitMatrix.Width; x++) { if (bitMatrix[x, y]) { qrCode.AddVertexAt(qrCode.NumberOfVertices, new Point2d(x, y), 0, 0, 0); } } } // Add the polyline to the drawing BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); btr.AppendEntity(qrCode); trans.AddNewlyCreatedDBObject(qrCode, true); trans.Commit(); } } } } 此代码使用ZXing库生成二维码,并使用Polyline对象将其绘制CAD中。请注意,此代码使用了一个名为“QRCode”的新图层来存储绘制的线条。如果您希望绘制到不同的图层,请更改代码中的图层名称。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值