Posted:
Thursday, June 30, 2022 11:08:02 AM(UTC)
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:
Code:
void AnimatedQR(string gif[h]File[/h], string QrText, string outputGif[h]File[/h])
{
RasterCodecs codecs = new RasterCodecs();
RasterImage QRimage = RasterImage.Create(800, 800, 24, 200, RasterColor.White);
RasterImage GIFimage = codecs.Load(gif[h]File[/h], 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.[h]Save[/h](animatedQR, outputGif[h]File[/h], RasterImageFormat.Gif, 8);
_viewerBefore.Image = GIFimage;
_viewerAfter.Image = animatedQR;
}
Posted:
Tuesday, April 27, 2021 9:24:49 PM(UTC)
The sample application worked, but now I get an error when I try and load a TIFF image instead of the CMP file.
When I change:
private string srcImageFileName = Application.StartupPath + @"\IMAGE1.CMP"
To
private string targetFileName = Application.StartupPath + @"\testAnnBurn.tif"
I get an exception saying "Image is not GDI+ Compatible" on the following line:
System.Drawing.Graphics gdiPlusGraphics = Leadtools.Drawing.RasterImagePainter.CreateGraphics(srcImage).Graphics;
Keep in mind, all I am trying to do is:
1) Load a TIFF image
2) Add a text annotation to the header
3) Burn the annotation to the image
4) Save the TIFF image to disk
Posted:
Thursday, August 20, 2020 4:27:26 PM(UTC)
Posted:
Wednesday, July 22, 2020 4:36:14 PM(UTC)
Hello Abdul,
Thank you for providing the
sample files and code. After reviewing everything it looks like the exception is being thrown because the SvgDocument is null so the DocumentWriterSvgPage's SvgDocument, Width, and Height properties are all null. For your use-case since you are rendering annotations on a RasterImage and then saving out as a PDF with the DocumentWriter, you will need to use DocumentWriterRasterPage.
https://www.leadtools.co...entwriterrasterpage.htmlYour code should look more like the code below:
Code:
for (int i = 1; i <= totalPages; i++)
{
var page = new DocumentWriterRasterPage();
RasterImage image = codecs.Load(input[h]File[/h]Name, info.BitsPerPixel, CodecsLoadByteOrder.BgrOrGrayOrRomm, i, i);
docannContainer = docannCodecs.Load(ann[h]File[/h], i);
RasterImage tempImage = docrenderingEngine.RenderOnImage(docannContainer, image);
page.Image = tempImage;
docWriter.AddPage(page);
page.Image.Dispose();
}
}
docWriter.EndDocument();
// [h]save[/h] the document writer stream
using var [h]file[/h]Stream = [h]File[/h].Create(@"C:\Temp\docwriterresize.pdf");
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.CopyTo([h]file[/h]Stream);
If you have any questions about the above process please feel free to reach back out to me.
Thanks
Posted:
Wednesday, November 20, 2019 9:04:54 AM(UTC)
This message was posted before the current version of LEADTOOLS was released and may no longer be applicable.
Hi Team,
Thanks for LeadTools. You guys are doing a great works with your SDK's. I'm planning to purchase LeadTools v20. Right now I'm experimenting with Evaluation Package. I stuck with achieving my functionality. I couldn't find any proper examples. After a long google search. I'm writing here. Please assist me.
My Use Case:
To put in simple words, I need to open any document or any print via my Virtual Printer in LeadTools HTML/JavaScript Document Viewer.
Here are the steps that I have tried.
I have installed Lead Tools V20 Virtual Printer in my Windows 10 PC. Now If I open a word document (or any document) and select
File -> Print -> Selecting My Virtual Printer -> Now Click on Print Button.
Now my Virtual Printer's will capture the Print Job and Convert it to PDF and
save it in a Path. Here is the Code for that.
Code:
[EmfEventMethodAttribute]
public static void [h]Save[/h]StreamAsPdf(object sender, Leadtools.Printer.EmfEventArgs e)
{
try
{
ConsoleMethods.Info("EMF Event: [h]Save[/h]StreamAsPdf");
// Write the EMF as [h]file[/h] to disk.
const string format = "pdf";
var [h]file[/h]Name = GetRandom[h]File[/h]Name(format);
string path = Path.Combine(
GetOutputRootPath(),
format + @"\",
[h]file[/h]Name);
Directory.CreateDirectory(Path.GetDirectoryName(path));
// Create an instance of the LEADTOOLS DocumentWriter
var docWriter = new DocumentWriter();
docWriter.BeginDocument(path, DocumentFormat.Pdf);
var page = new DocumentWriterEmfPage()
{
EmfHandle = new Meta[h]file[/h](new MemoryStream(e.Stream.ToArray()))
.GetHenhmeta[h]file[/h]()
};
docWriter.AddPage(page);
docWriter.EndDocument();
ConsoleMethods.Success("[h]Save[/h]StreamAsPdf: Complete");
ConsoleMethods.Verbose(path);
// Now Here I need to open this [h]file[/h] in my HTML5/JavaScript Document Viewer
Process.Start("http://localhost:20020/index.html?[h]file[/h]=" + [h]file[/h]Name);
}
catch (Exception ex)
{
ConsoleMethods.Error(ex.Message, 4000);
}
}
Line No 31 in above code opens my HTML5/JavaScript Document Viewer. From here I need to know how to customize LeadTools HTML5/JavaScript Document Viewer example to customize and pass the
file name. I'm stuck here. LeadTools HTML5/Javascript Viewer always passes default LeadToolsDemo.Pdf url to the Document Service and it loads the default
sample document. Please assist on how to achieve this so that I can demonstrate this to my BOSS and get approval for purchase.
Thanks,
Abdul Rahman