简体   繁体   中英

Is it possible to store image into pdf417 barcode?

Is it possible to store(Encode) image/Pictures into pdf417 barcode? if so is there any tutorial or sample code?

The barcode cannot just hold a reference to an image in a database. The customer also expect to be able to store any image he wants.

Thank you.

As ssasa mentionned you could store the image as a byte array:

public static byte[] GetBytes(Image image)
{
    byte[] byteArray = new byte[0];
    using (MemoryStream stream = new MemoryStream())
    {
        // you may want to choose another image format than PNG
        image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        stream.Close();

        byteArray = stream.ToArray();
    }
    return byteArray;
}

... or, if it MUST be a string , you could base64 encode it:

public static string GetBase64(Image image)
{
    Image yourImage;

    // using the function from the first example
    var imageBytes = GetBytes(yourImage);   

    var encodedString = Convert.ToBase64String(imageBytes);

    return Encoding.UTF8.GetBytes(encodedString);
}

Remember, though: a PDF417 barcode allows storing up to 2710 characters . While this is more than enough for most structures you'd ever want to encode, it's rather limitating for an image. It may be enough for small-sized bitmaps, monochrome images and/or highly compressed JPEGs, but don't expect being able to do much more than that, especially if you want to be able to store other data along.

If your customers expects to be able to store, as you say, any picture they want , you'd better be lowering their expectations as soon as possible before writing any code.

If it's an option, you may want to consider using QR Codes instead. Not that you'll work miracles with those either but you may like the added storage capacity.

Yes, Department of Defense Common Access Cards (CAC) store JPEG image of the cardholder:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM