Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, June 30, 2022 11:08:02 AM(UTC)

Amin  
Amin

Groups: Manager, Tech Support
Posts: 367

Was thanked: 1 time(s) in 1 post(s)

This C# code sample shows how to use the BarcodeEngine, CombineFastCommand and RasterCodecs classes from LEADTOOLS to take an input animated GIF image and embed it inside a QR code to produce an animated GIF QR code image file.

The result looks like the following image:
Animated GIF logo inside QR


Code:

void AnimatedQR(string gifFile, string QrText, string outputGifFile)
{
   RasterCodecs codecs = new RasterCodecs();
   RasterImage QRimage = RasterImage.Create(800, 800, 24, 200, RasterColor.White);
   RasterImage GIFimage = codecs.Load(gifFile, 24, CodecsLoadByteOrder.Bgr, 1, -1);

   QRBarcodeData data = new QRBarcodeData
   {
      SymbolModel = QRBarcodeSymbolModel.Model2AutoSize,
      Symbology = BarcodeSymbology.QR,
      Value = QrText,
      Bounds = new LeadRect(1, 1, QRimage.ImageWidth, QRimage.ImageHeight)
   };

   QRBarcodeWriteOptions options = new QRBarcodeWriteOptions
   {
      GroupNumber = 0,
      GroupTotal = 0,
      XModule = 30,
      ECCLevel = QRBarcodeECCLevel.LevelL,
      HorizontalAlignment = BarcodeAlignment.Near,
      VerticalAlignment = BarcodeAlignment.Near
   };
   BarcodeEngine barcodeEngine = new BarcodeEngine();
   barcodeEngine.Writer.WriteBarcode(QRimage, data, options);
   AutoCropCommand crop = new AutoCropCommand(128);
   crop.Run(QRimage);

   int minW = QRimage.Width;
   int minH = QRimage.Height;
   bool resize = false;
   if (GIFimage.Width > QRimage.Width / 5)
   {
      minW = GIFimage.Width * 5;
      minH = QRimage.Height * minW / QRimage.Width;
      resize = true;
   }
   if(GIFimage.Height> minH / 5)//must resize based on hieght
   {
      minW = minW * GIFimage.Height * 5 / minH;
      minH = GIFimage.Height * 5;
      resize = true;
   }
   if(resize)
   {
      SizeCommand size = new SizeCommand(minW, minH, RasterSizeFlags.None);
      size.Run(QRimage);
   }
   RasterImage animatedQR = null;
   for(int page = 1; page<=GIFimage.PageCount; page++)
   {
      GIFimage.Page = page;
      RasterImage temp = QRimage.Clone();
      temp.AnimationDelay = GIFimage.AnimationDelay;
      var r = new LeadRect((temp.Width - GIFimage.Width) / 2, (temp.Height - GIFimage.Height) / 2, GIFimage.Width, GIFimage.Height);
      CombineFastCommand combine = new CombineFastCommand(temp, r, new LeadPoint(0, 0), CombineFastCommandFlags.Destination0 | CombineFastCommandFlags.OperationAdd);
      combine.Run(GIFimage);
      if (page == 1)
         animatedQR = temp;
      else
         animatedQR.AddPage(temp);
   }

   codecs.Save(animatedQR, outputGifFile, RasterImageFormat.Gif, 8);
   _viewerBefore.Image = GIFimage;
   _viewerAfter.Image = animatedQR;
}

Amin Dodin

Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.039 seconds.