LEADTOOLS加入QRBar code到现有的图像 [英] LEADTOOLS adding QRBarcode to an existing image

查看:241
本文介绍了LEADTOOLS加入QRBar code到现有的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的code写了一个QR code,但过来只用QR code写我的文件。我不知道如何调整QR code的大小,放置在文件的一个角落,而不是占用了整个页面。也不能肯定是否 RasterImage.Create 意味着它会创建一个新的文件,只是QR和丢弃我的原始文件?

code: - PDF转换为BMP添加QR然后保存回PDF

 公共无效PDFFileExample()
    {
        光栅codeCS codeCS1 =新Raster codeCS();        codecs1.Options.Pdf.InitialPath = @C:\\ LEADTOOLS 18 \\ BIN \\ Dotnet4 \\ Win32的;
        codecs1.Dispose();
        光栅codeCS codeCS2 =新Raster codeCS();
        codecs2.ThrowExceptionsOnInvalidImages = TRUE;
        System.Diagnostics.Debug.Assert(codecs2.Options.Pdf.InitialPath == @C:\\ LEADTOOLS 18 \\ BIN \\ Dotnet4 \\ Win32的);        字符串pdfFile = @C:\\ QR codeTesting \\ bottomRight.pdf
        字符串destFileName1 = @C:\\ QR codeTesting \\ bottomRightOutputTemp.pdf
        字符串destFileName2 = @C:\\ QR codeTesting \\ bottomRightOutput.bmp        光栅codeCS codeCS =新Raster codeCS();        如果(codecs.Options.Pdf.IsEngineInstalled)
        {
            //生成的图像的像素深度。
            codecs.Options.Pdf.Load.DisplayDepth = 24;
            codecs.Options.Pdf.Load.GraphicsAlpha = 4;
            codecs.Options.Pdf.Load.Password =;            字体反锯齿//类型使用。
            codecs.Options.Pdf.Load.TextAlpha = 1;
            codecs.Options.Pdf.Load.UseLibFonts = TRUE;            //以每英寸点数水平,垂直显示分辨率。
            codecs.Options.RasterizeDocument.Load.XResolution = 150;
            codecs.Options.RasterizeDocument.Load.YResolution = 150;            使用(RasterImage图像= codecs.Load(pdfFile,0,codecsLoadByteOrder.BgrOrGray,1,1))
            {                //设置PDF版本是V1.4
                codecs.Options.Pdf.Save.Version = codecsRasterPdfVersion.V14;                尝试
                {
                    //保存图像返回为PDF
                    codecs.Save(图像,destFileName1,RasterImageFormat.RasPdf,24);
                }
                赶上(RasterException前)
                {
                    如果(例如,code == RasterException code.FileFormat)
                        MessageBox.Show(的String.Format(图像文件{0}装,destFileName1));
                    其他
                    {
                        MessageBox.Show(的String.Format(无法​​加载文件{0} {1} {2},destFileName1,Environment.NewLine,ex.Message));
                    }
                }
            }            保存为BMP之前//并加载它回来
            使用(RasterImage图像= codecs.Load(destFileName1))
            {
                codecs.Save(图像,destFileName2,RasterImageFormat.Bmp,image.BitsPerPixel);
                writeQRTag(destFileName2);
            }
        }
        其他
        {
            的MessageBox.show(PDF引擎没有找到!);
        }        // 清理
        codecs.Dispose();    }

QR code编写方法

 私人无效writeQRTag(字符串映像文件名称)
    {
        酒吧codeEngine发动机=新的酒吧codeEngine();        //创建写的吧codeS到图像
        INT分辨率= 300;
        使用(RasterImage图像= RasterImage.Create((INT)(8.5 *分辨率),(INT)(11.0 *分辨率),1,分辨率,RasterColor.FromKnownColor(RasterKnownColor.Red)))
        {
            //写两到QR酒吧codeS
            WriteQR code(engine.Writer,图像,QRBar codeSymbolModel.Model1AutoSize,QR数据1,真正的);            //保存图像
            使用(光栅codeCS codeCS =新Raster codeCS())
            {
                codecs.Save(形象,映像文件名称,RasterImageFormat.CcittGroup4,1);
            }
        }
    }


解决方案

这是Maen从LEADTOOLS支持。

我检查你的code和注意以下内容:

1)当你调用RasterImage.Create()方法,它会创建一个包含一个空的红图像,你随后传递给writeQRTag()函数,然后保存使用给定文件名的新RasterImage对象。
当你保存它,红色被黑色所取代,因为你使用的文件格式仅支持黑白。由于您使用的一个新的形象,旧的图像丢失(覆盖)。

如果你想写从原始文件中的图像上栏code,你不应该创建一个新的形象。相反,您需要使用您使用codecs.Load(已加载的图像),并写了吧code就可以了。

2)code执行多种加载和保存操作。通常情况下,除非你的应用需要不同的文件格式(PDF,BMP和TIFF)你不需要这么做。

3)创建了光栅codeCS对象的不同实例,但实际上只使用其中一个。有没有必要在code中的4个光栅化codeCS对象3。

如果您仍然面临的问题与使用我们的工具包的code,您可以给我们在电子邮件中细节 support@leadtools.com ,我们会尽力帮助你。

My current code writes a qr code but it over writes my file with just the qr code. I am not sure how to adjust the size of the qr code to be placed in one corner of the document rather than taking up the whole page. Also not sure if the RasterImage.Create means that it creates a new file with just the qr and discard my original file?

Code: - Convert PDF to Bmp to add QR then saving back to PDF

 public void PDFFileExample()
    {
        RasterCodecs codecs1 = new RasterCodecs();

        codecs1.Options.Pdf.InitialPath = @"C:\LEADTOOLS 18\Bin\Dotnet4\Win32";
        codecs1.Dispose();
        RasterCodecs codecs2 = new RasterCodecs();
        codecs2.ThrowExceptionsOnInvalidImages = true;
        System.Diagnostics.Debug.Assert(codecs2.Options.Pdf.InitialPath == @"C:\LEADTOOLS 18\Bin\Dotnet4\Win32");

        string pdfFile = @"C:\QRCodeTesting\bottomRight.pdf";
        string destFileName1 = @"C:\QRCodeTesting\bottomRightOutputTemp.pdf";
        string destFileName2 = @"C:\QRCodeTesting\bottomRightOutput.bmp";

        RasterCodecs codecs = new RasterCodecs();

        if (codecs.Options.Pdf.IsEngineInstalled)
        {
            // Resulting image pixel depth.
            codecs.Options.Pdf.Load.DisplayDepth = 24;
            codecs.Options.Pdf.Load.GraphicsAlpha = 4;
            codecs.Options.Pdf.Load.Password = "";

            // Type of font anti-aliasing to use.
            codecs.Options.Pdf.Load.TextAlpha = 1;
            codecs.Options.Pdf.Load.UseLibFonts = true;

            // Horizontal,vertical  display resolution in dots per inch.
            codecs.Options.RasterizeDocument.Load.XResolution = 150;
            codecs.Options.RasterizeDocument.Load.YResolution = 150;

            using (RasterImage image = codecs.Load(pdfFile, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
            {

                // Set the PDF version to be v1.4
                codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V14;

                try
                {
                    // Save the image back as PDF
                    codecs.Save(image, destFileName1, RasterImageFormat.RasPdf, 24);
                }
                catch (RasterException ex)
                {
                    if (ex.Code == RasterExceptionCode.FileFormat)
                        MessageBox.Show(string.Format("Image in file {0} is loaded", destFileName1));
                    else
                    {
                        MessageBox.Show(string.Format("Could not load the file {0}.{1}{2}", destFileName1, Environment.NewLine, ex.Message));
                    }
                }
            }

            // And load it back before saving it as BMP
            using (RasterImage image = codecs.Load(destFileName1))
            {
                codecs.Save(image, destFileName2, RasterImageFormat.Bmp, image.BitsPerPixel);
                writeQRTag(destFileName2);
            }
        }
        else
        {
            MessageBox.Show("PDF Engine is not found!");
        }

        // Clean up
        codecs.Dispose();

    }

QRCode writing Method

private void writeQRTag(string imageFileName)
    {
        BarcodeEngine engine = new BarcodeEngine();

        // Create the image to write the barcodes to
        int resolution = 300;
        using (RasterImage image = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.Red)))
        {
            // Write two QR barcodes
            WriteQRCode(engine.Writer, image, QRBarcodeSymbolModel.Model1AutoSize, "QR Data 1", true);

            // Save the image
            using (RasterCodecs codecs = new RasterCodecs())
            {
                codecs.Save(image, imageFileName, RasterImageFormat.CcittGroup4, 1);
            }
        }
    }

解决方案

This is Maen from LEADTOOLS support.

I checked your code and noticed the following:

1) When you call RasterImage.Create() method, it will create a new RasterImage object that contains an empty red image, which you subsequently pass to the writeQRTag() function then save using the given file name. When you save it, the red color is replaced by black because the file format you used only supports black and white. Since you're using a new image, the old image is lost (overwritten).

If you want to write the barcode on the image from the original file, you should NOT create a new image. Instead, you need to use the image you already loaded using codecs.Load() and write the barcode on it.

2) The code performs multiple load and save operations. Normally, you don't need to do that unless your application needs the different file formats (PDF, BMP and TIFF).

3) You create different instances of our RasterCodecs object but actually use only one of them. There's no need for 3 of the 4 RasterCodecs objects in the code.

If you still face problems with the code that uses our toolkit, you can send us the details in an email to support@leadtools.com and we will try to help you.

这篇关于LEADTOOLS加入QRBar code到现有的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆