<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to jig a bitmap in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13421838#M388</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7859429"&gt;@reithinger&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use the QRCoder nugetpackage.&lt;/P&gt;
&lt;P&gt;That means that i have a bitmap (this is actual not save)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can use QRCoder to create a hatch figuring the QRCode or a block containg this hatch which is easier to scale and jig.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

using QRCoder;

using System.Collections;
using System.Collections.Generic;

namespace Gile.AutoCAD.QRCoder
{
    /// &amp;lt;summary&amp;gt;
    /// Provides methods to create AutoCAD entities (Hatch or Block) representing a QRCode.
    /// Uses QRCOder library (https://github.com/codebude/QRCoder/wiki/How-to-use-QRCoder).
    /// &amp;lt;/summary&amp;gt;
    public class BlockQRCoder
    {
        readonly List&amp;lt;BitArray&amp;gt; matrix;
        readonly string plainText;
        readonly int size;

        /// &amp;lt;summary&amp;gt;
        /// Gets or sets the background color.
        /// &amp;lt;/summary&amp;gt;
        public Color BackgroundColor { get; set; } = Color.FromRgb(255, 255, 255);

        /// &amp;lt;summary&amp;gt;
        /// Gets or sets the foreground color.
        /// &amp;lt;/summary&amp;gt;
        public Color ForegroundColor { get; set; } = Color.FromRgb(0, 0, 0);

        /// &amp;lt;summary&amp;gt;
        /// Creates a new intance of BlockQRCoder.
        /// Requires the same parameters as QRCodeGenerator.CreateQrCode method.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="plainText"&amp;gt;Text which shall be encoded in the QR Code.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="eccLevel"&amp;gt;Error correction level. Either L (7%), M (15%), Q (25%) or H (30%).&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="forceUtf8"&amp;gt;Enables to force text encoding in UTF-8.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="utf8BOM"&amp;gt;Enables to set ByteOrderMark (BOM) when QRCoder uses UTF-8 for text-encoding&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="eciMode"&amp;gt;Allows to specify a fixed EciMode.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="requestedVersion"&amp;gt;If set other than default (= -1), it will set a fixed QR code version.&amp;lt;/param&amp;gt;
        public BlockQRCoder(
            string plainText,
            QRCodeGenerator.ECCLevel eccLevel = QRCodeGenerator.ECCLevel.Q,
            bool forceUtf8 = false,
            bool utf8BOM = false,
            QRCodeGenerator.EciMode eciMode = QRCodeGenerator.EciMode.Default,
            int requestedVersion = -1)
        {
            this.plainText = plainText;
            using (var qrGenerator = new QRCodeGenerator())
            using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
            {
                matrix = qrCodeData.ModuleMatrix;
                size = matrix.Count;
            }
        }

        /// &amp;lt;summary&amp;gt;
        /// Creates a new block definition.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="db"&amp;gt;Database which owns the block.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="blockName"&amp;gt;Name of the block (creates an anonymous block if null).&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The objectId of the block definition.&amp;lt;/returns&amp;gt;
        public ObjectId CreateBlock(Database db, string blockName = null, bool plainTextAsAttribute = false)
        {
            ObjectId blockId;
            using (var tr = new OpenCloseTransaction())
            {
                if (string.IsNullOrEmpty(blockName))
                    blockName = "*U";
                var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                if (blockTable.Has(blockName))
                    throw new Exception(ErrorStatus.AlreadyInDB);

                var btr = new BlockTableRecord
                {
                    Name = blockName
                };
                tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
                blockId = blockTable.Add(btr);
                tr.AddNewlyCreatedDBObject(btr, true);

                var solid = GetBackgroundSolid();
                btr.AppendEntity(solid);
                tr.AddNewlyCreatedDBObject(solid, true);

                var hatch = GetHatch();
                btr.AppendEntity(hatch);
                tr.AddNewlyCreatedDBObject(hatch, true);

                if (plainTextAsAttribute)
                {
                    var attDef = new AttributeDefinition(Point3d.Origin, plainText, "TEXT", "", db.Textstyle)
                    {
                        Constant = true,
                        Height = 2.5,
                        Justify = AttachmentPoint.BaseCenter,
                        AlignmentPoint = new Point3d(size / 2.0, -5.0, 0.0)
                    };
                    btr.AppendEntity(attDef);
                    tr.AddNewlyCreatedDBObject(attDef, true);
                }

                tr.Commit();
            }
            return blockId;
        }

        /// &amp;lt;summary&amp;gt;
        /// Gets a Solid figuring the QR Code background.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;returns&amp;gt;the newly created Solid.&amp;lt;/returns&amp;gt;
        public Solid GetBackgroundSolid() =&amp;gt;
            new Solid(
                    new Point3d(0.0, 0.0, 0.0),
                    new Point3d(size, 0.0, 0.0),
                    new Point3d(0.0, size, 0.0),
                    new Point3d(size, size, 0.0))
            { Color = BackgroundColor };

        /// &amp;lt;summary&amp;gt;
        /// Gets a Hatch figuring the QR Code.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;returns&amp;gt;The newly created Hatch.&amp;lt;/returns&amp;gt;
        public Hatch GetHatch()
        {
            var hatch = new Hatch();
            for (int i = 0; i &amp;lt; size; i++)
            {
                for (int j = 0; j &amp;lt; size; j++)
                {
                    if (matrix[i][j])
                    {
                        HatchLoop loop = new HatchLoop(HatchLoopTypes.Polyline);

                        double x = i;
                        double y = size - j;

                        loop.Polyline.Add(new BulgeVertex(new Point2d(x, y), 0.0));
                        loop.Polyline.Add(new BulgeVertex(new Point2d(x + 1.0, y), 0.0));
                        loop.Polyline.Add(new BulgeVertex(new Point2d(x + 1.0, y - 1.0), 0.0));
                        loop.Polyline.Add(new BulgeVertex(new Point2d(x, y - 1.0), 0.0));
                        loop.Polyline.Add(new BulgeVertex(new Point2d(x, y), 0.0));

                        hatch.AppendLoop(loop);
                    }
                }
            }
            hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
            hatch.Color = ForegroundColor;
            hatch.EvaluateHatch(true);
            return hatch;
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 12 Apr 2025 13:56:22 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2025-04-12T13:56:22Z</dc:date>
    <item>
      <title>how to jig a bitmap</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13416361#M385</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the QRCoder nugetpackage.&lt;/P&gt;&lt;P&gt;That means that i have a bitmap (this is actual not save)&lt;/P&gt;&lt;P&gt;How can I jig this bitmap in my drawing (the bitmap is attached to the mouse), the user must select the point where he wants to have the image.&lt;/P&gt;&lt;P&gt;By next click is the Image in the drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should i save the bitmap as a rasterimage, can i use it dynamics ?&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;&lt;P&gt;Fabrice&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 08:29:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13416361#M385</guid>
      <dc:creator>reithinger</dc:creator>
      <dc:date>2025-04-09T08:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to jig a bitmap</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13417342#M386</link>
      <description>&lt;P&gt;Unless there is a pressing need to see the actual QRCode while dragging, why not just drag the outline/boundary (as a polyline)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Otherwise, you can use the&amp;nbsp;&lt;A href="https://help.autodesk.com/view/OARX/2024/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_GraphicsInterface_Geometry_Image_ImageBGRA32_Point3d_Vector3d_Vector3d_Autodesk_AutoCAD_GraphicsInterface_TransparencyMode" target="_blank" rel="noopener"&gt;Geometry.Image()&lt;/A&gt; method for drawing bitmaps using a &lt;A href="https://help.autodesk.com/view/OARX/2024/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_EditorInput_DrawJig" target="_blank" rel="noopener"&gt;DrawJig&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can find an example of doing this &lt;A href="https://claude.site/artifacts/40c56007-1201-489c-81de-db4e677cc7ae" target="_blank" rel="noopener"&gt;here&lt;/A&gt; (generated by Claude, and not tested).&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 17:35:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13417342#M386</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2025-04-09T17:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to jig a bitmap</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13418262#M387</link>
      <description>&lt;P&gt;Hi ActivistInvestor,&lt;/P&gt;&lt;P&gt;I do it with your first Idea. I drag the outline/boundary and i think it's a good solution. So the user can be define himself the heigth anf width he want.&lt;/P&gt;&lt;P&gt;I would test the other link from Claude. It's interesting me.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 05:39:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13418262#M387</guid>
      <dc:creator>reithinger</dc:creator>
      <dc:date>2025-04-10T05:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to jig a bitmap</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13421838#M388</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7859429"&gt;@reithinger&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use the QRCoder nugetpackage.&lt;/P&gt;
&lt;P&gt;That means that i have a bitmap (this is actual not save)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can use QRCoder to create a hatch figuring the QRCode or a block containg this hatch which is easier to scale and jig.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

using QRCoder;

using System.Collections;
using System.Collections.Generic;

namespace Gile.AutoCAD.QRCoder
{
    /// &amp;lt;summary&amp;gt;
    /// Provides methods to create AutoCAD entities (Hatch or Block) representing a QRCode.
    /// Uses QRCOder library (https://github.com/codebude/QRCoder/wiki/How-to-use-QRCoder).
    /// &amp;lt;/summary&amp;gt;
    public class BlockQRCoder
    {
        readonly List&amp;lt;BitArray&amp;gt; matrix;
        readonly string plainText;
        readonly int size;

        /// &amp;lt;summary&amp;gt;
        /// Gets or sets the background color.
        /// &amp;lt;/summary&amp;gt;
        public Color BackgroundColor { get; set; } = Color.FromRgb(255, 255, 255);

        /// &amp;lt;summary&amp;gt;
        /// Gets or sets the foreground color.
        /// &amp;lt;/summary&amp;gt;
        public Color ForegroundColor { get; set; } = Color.FromRgb(0, 0, 0);

        /// &amp;lt;summary&amp;gt;
        /// Creates a new intance of BlockQRCoder.
        /// Requires the same parameters as QRCodeGenerator.CreateQrCode method.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="plainText"&amp;gt;Text which shall be encoded in the QR Code.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="eccLevel"&amp;gt;Error correction level. Either L (7%), M (15%), Q (25%) or H (30%).&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="forceUtf8"&amp;gt;Enables to force text encoding in UTF-8.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="utf8BOM"&amp;gt;Enables to set ByteOrderMark (BOM) when QRCoder uses UTF-8 for text-encoding&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="eciMode"&amp;gt;Allows to specify a fixed EciMode.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="requestedVersion"&amp;gt;If set other than default (= -1), it will set a fixed QR code version.&amp;lt;/param&amp;gt;
        public BlockQRCoder(
            string plainText,
            QRCodeGenerator.ECCLevel eccLevel = QRCodeGenerator.ECCLevel.Q,
            bool forceUtf8 = false,
            bool utf8BOM = false,
            QRCodeGenerator.EciMode eciMode = QRCodeGenerator.EciMode.Default,
            int requestedVersion = -1)
        {
            this.plainText = plainText;
            using (var qrGenerator = new QRCodeGenerator())
            using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(plainText, eccLevel, forceUtf8, utf8BOM, eciMode, requestedVersion))
            {
                matrix = qrCodeData.ModuleMatrix;
                size = matrix.Count;
            }
        }

        /// &amp;lt;summary&amp;gt;
        /// Creates a new block definition.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="db"&amp;gt;Database which owns the block.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="blockName"&amp;gt;Name of the block (creates an anonymous block if null).&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The objectId of the block definition.&amp;lt;/returns&amp;gt;
        public ObjectId CreateBlock(Database db, string blockName = null, bool plainTextAsAttribute = false)
        {
            ObjectId blockId;
            using (var tr = new OpenCloseTransaction())
            {
                if (string.IsNullOrEmpty(blockName))
                    blockName = "*U";
                var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                if (blockTable.Has(blockName))
                    throw new Exception(ErrorStatus.AlreadyInDB);

                var btr = new BlockTableRecord
                {
                    Name = blockName
                };
                tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
                blockId = blockTable.Add(btr);
                tr.AddNewlyCreatedDBObject(btr, true);

                var solid = GetBackgroundSolid();
                btr.AppendEntity(solid);
                tr.AddNewlyCreatedDBObject(solid, true);

                var hatch = GetHatch();
                btr.AppendEntity(hatch);
                tr.AddNewlyCreatedDBObject(hatch, true);

                if (plainTextAsAttribute)
                {
                    var attDef = new AttributeDefinition(Point3d.Origin, plainText, "TEXT", "", db.Textstyle)
                    {
                        Constant = true,
                        Height = 2.5,
                        Justify = AttachmentPoint.BaseCenter,
                        AlignmentPoint = new Point3d(size / 2.0, -5.0, 0.0)
                    };
                    btr.AppendEntity(attDef);
                    tr.AddNewlyCreatedDBObject(attDef, true);
                }

                tr.Commit();
            }
            return blockId;
        }

        /// &amp;lt;summary&amp;gt;
        /// Gets a Solid figuring the QR Code background.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;returns&amp;gt;the newly created Solid.&amp;lt;/returns&amp;gt;
        public Solid GetBackgroundSolid() =&amp;gt;
            new Solid(
                    new Point3d(0.0, 0.0, 0.0),
                    new Point3d(size, 0.0, 0.0),
                    new Point3d(0.0, size, 0.0),
                    new Point3d(size, size, 0.0))
            { Color = BackgroundColor };

        /// &amp;lt;summary&amp;gt;
        /// Gets a Hatch figuring the QR Code.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;returns&amp;gt;The newly created Hatch.&amp;lt;/returns&amp;gt;
        public Hatch GetHatch()
        {
            var hatch = new Hatch();
            for (int i = 0; i &amp;lt; size; i++)
            {
                for (int j = 0; j &amp;lt; size; j++)
                {
                    if (matrix[i][j])
                    {
                        HatchLoop loop = new HatchLoop(HatchLoopTypes.Polyline);

                        double x = i;
                        double y = size - j;

                        loop.Polyline.Add(new BulgeVertex(new Point2d(x, y), 0.0));
                        loop.Polyline.Add(new BulgeVertex(new Point2d(x + 1.0, y), 0.0));
                        loop.Polyline.Add(new BulgeVertex(new Point2d(x + 1.0, y - 1.0), 0.0));
                        loop.Polyline.Add(new BulgeVertex(new Point2d(x, y - 1.0), 0.0));
                        loop.Polyline.Add(new BulgeVertex(new Point2d(x, y), 0.0));

                        hatch.AppendLoop(loop);
                    }
                }
            }
            hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
            hatch.Color = ForegroundColor;
            hatch.EvaluateHatch(true);
            return hatch;
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Apr 2025 13:56:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13421838#M388</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-04-12T13:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to jig a bitmap</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13423169#M389</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7859429"&gt;@reithinger&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi ActivistInvestor,&lt;/P&gt;&lt;P&gt;I do it with your first Idea. I drag the outline/boundary and i think it's a good solution. So the user can be define himself the heigth anf width he want.&lt;/P&gt;&lt;P&gt;I would test the other link from Claude. It's interesting me.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Here's one way to enable dragging of an image's contents, where the dragging is done using a Jig:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// using Autodesk,AutoCAD.Internal;

var vsWireframe = Utils.visualStyleId("Wireframe");
var cvpvsId = Utils.GetCurrentViewportVisualStyleId();
Utils.SetCurrentViewportVisualStyle(vsWireframe);
try
{
   var result = editor.Drag(myJig);  // Call drag and pass in your jig;
}
finally
{
   Utils.SetCurrentViewportVisualStyle(cvpvsId);
}&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 13 Apr 2025 11:38:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-jig-a-bitmap/m-p/13423169#M389</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2025-04-13T11:38:35Z</dc:date>
    </item>
  </channel>
</rss>

