ページ数の多いGIFおよびTIFFからバーコードを読み取る方法
IronBarcode は、マルチページおよびマルチフレームの GIF や TIFF 画像形式を含む、さまざまな画像形式の入力をサポートしています。 これにより、ユーザーはTIFFまたはGIFファイルのフレームやページを手動で分割することなく、画像を簡単に使用することができます。これらのファイル形式を読み取るためにIronBarcodeの使用方法を探ってみましょう。
ページ数の多いGIFおよびTIFFからバーコードを読み取る方法
- Download the C# library for reading barcodes
- バーコード検出のためにGIFおよびTIFF画像を準備する
- マルチフレームのGIFおよびTIFF画像を
Read
メソッドに渡す - 精度とパフォーマンスを向上させるための画像フィルターとオプションの適用
- Convert images to multi-frame GIF and TIFF
IronBarcodeを始める
今日から無料トライアルでIronBarcodeをあなたのプロジェクトで使い始めましょう。
マルチフレームGIFおよびTIFF画像を読み取る
IronBarcodeを使用してマルチフレームのGIFおよびTIFF画像を読み取ることは、単一の画像を読み取るのと同じくらい簡単です。IronBarcodeは、BarcodeReader.Read
メソッドに複数ページの画像ファイルを容易に受け入れるためです。ユーザーは画像の準備を行う必要はなく、すべての処理はライブラリ内で内部化されています。
以下のコード例は、複数ページのGIFおよびTIFFファイルの読み取り方法を示しています:
:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-multi-page-frame-tiff-gif-read-tif.cs
using IronBarCode;
using System;
// Read barcode from TIF image
BarcodeResults results = BarcodeReader.Read("sample.tif");
// Output the barcodes value to console
foreach (var result in results)
{
Console.WriteLine(result.Value);
}
Imports IronBarCode
Imports System
' Read barcode from TIF image
Private results As BarcodeResults = BarcodeReader.Read("sample.tif")
' Output the barcodes value to console
For Each result In results
Console.WriteLine(result.Value)
Next result
画像をGIFおよびTIFF形式に変換
オープンソースライブラリであるIronDrawingを利用して、画像を複数ページのTIFFおよびGIFに変換する方法を学びます。 では、以下のコード例を見てみましょう。マルチページのGIFまたはTIFF画像を生成する方法です。
:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-multi-page-frame-tiff-gif-create-tiff-gif.cs
using IronBarCode;
using IronSoftware.Drawing;
using System.Collections.Generic;
// Import images
List<AnyBitmap> images = new List<AnyBitmap>()
{
AnyBitmap.FromFile("image1.png"),
AnyBitmap.FromFile("image2.png"),
AnyBitmap.FromFile("image3.png"),
AnyBitmap.FromFile("image4.jpg"),
AnyBitmap.FromFile("image5.jpg")
};
// Convert TIFF from images
AnyBitmap tiffImage = AnyBitmap.CreateMultiFrameTiff(images);
// Export TIFF
tiffImage.SaveAs("multiframetiff.tiff");
// Convert GIF from images
AnyBitmap gifImage = AnyBitmap.CreateMultiFrameGif(images);
// Export GIF
gifImage.SaveAs("multiframegif1.gif");
Imports IronBarCode
Imports IronSoftware.Drawing
Imports System.Collections.Generic
' Import images
Private images As New List(Of AnyBitmap)() From {AnyBitmap.FromFile("image1.png"), AnyBitmap.FromFile("image2.png"), AnyBitmap.FromFile("image3.png"), AnyBitmap.FromFile("image4.jpg"), AnyBitmap.FromFile("image5.jpg")}
' Convert TIFF from images
Private tiffImage As AnyBitmap = AnyBitmap.CreateMultiFrameTiff(images)
' Export TIFF
tiffImage.SaveAs("multiframetiff.tiff")
' Convert GIF from images
Dim gifImage As AnyBitmap = AnyBitmap.CreateMultiFrameGif(images)
' Export GIF
gifImage.SaveAs("multiframegif1.gif")
上記のコードスニペットから、画像ファイルをAnyBitmap
オブジェクトのリストにインポートすることで、最初にグループ化することができます。 このリストは、AnyBitmap.CreateMultiFrameTiff
および AnyBitmap.CreateMultiFrameGif
メソッドを呼び出す際のパラメーターとして使用して、マルチページのTIFFおよびマルチページのGIFオブジェクトをそれぞれ取得できます。
複数ページのGIFとTIFFの両方が画像を単一のファイルにまとめる方法を提供しますが、以下に示すように、これらのフォーマットにはいくつかの違いがあります。
Aspect | Multipage GIF | Multipage TIFF |
---|---|---|
Compression | GIF images use lossless compression, meaning that no image data is lost during compression. This results in relatively larger file sizes compared to formats with lossy compression. | TIFF files can use various compression methods, including lossless compression (such as LZW) and lossy compression (such as JPEG). This flexibility allows TIFF files to balance between file size and image quality. |
Color Depth | GIF supports up to 256 colors (8-bit color depth), which is limited compared to other formats. This limited color palette can result in a loss of detail and color accuracy, especially for photographs and images with gradients | TIFF supports various color depths, including 1-bit (binary), 8-bit (256 colors), 24-bit (true color), and more. This flexibility allows TIFF to store images with different levels of color detail. |
Transparency | GIF supports binary transparency, which means that a single color can be fully transparent, and the rest of the colors are fully opaque. This lack of partial transparency can sometimes lead to jagged edges in images with smooth transitions. | TIFF supports multiple forms of transparency, including binary transparency (similar to GIF) and alpha channel transparency. Alpha channel transparency allows for smooth transitions and semi-transparent pixels, providing high-quality transparency effects. |
Animation | GIF supports simple animations by combining multiple frames into a single file. Each frame can have its own time delay, creating a basic form of animation. GIF animations are widely supported on the web. | TIFF is not primarily designed for animations. While it can store multiple images, it lacks built-in animation support like GIF. Each page in a multipage TIFF file is typically a separate image rather than a frame in an animation sequence. |
高度なバーコード読み取り
IronBarcodeはすぐに使用できますが、一部の画像ではBarcodeReaderOptions
クラスを設定して、正確で高速なバーコード読み取りを実現する必要がある場合があります。 このクラスの詳細については、'画像ファイル(jpg、png、gif、tiff、svg、bmp)からのバーコードの読み取り方法'の記事をご覧ください。
以下のコードスニペットは、BarcodeReaderOptions
クラスで設定可能な必要なプロパティの例を示しています。
:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-multi-page-frame-tiff-gif-advance.cs
using IronBarCode;
using System;
// Configure filters
ImageFilterCollection filters = new ImageFilterCollection()
{
new SharpenFilter(3.5f),
new ContrastFilter(2)
};
// Configure options
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.QRCode,
ImageFilters = filters,
ExpectMultipleBarcodes = true,
Speed = ReadingSpeed.Balanced
};
// Read barcode from TIF image
BarcodeResults results = BarcodeReader.Read("sample.tif", options);
// Output the barcodes value to console
foreach (var result in results)
{
Console.WriteLine(result.Value);
}
Imports IronBarCode
Imports System
' Configure filters
Private filters As New ImageFilterCollection() From {
New SharpenFilter(3.5F),
New ContrastFilter(2)
}
' Configure options
Private options As New BarcodeReaderOptions() With {
.ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.QRCode,
.ImageFilters = filters,
.ExpectMultipleBarcodes = True,
.Speed = ReadingSpeed.Balanced
}
' Read barcode from TIF image
Private results As BarcodeResults = BarcodeReader.Read("sample.tif", options)
' Output the barcodes value to console
For Each result In results
Console.WriteLine(result.Value)
Next result
コードスニペットでは、BarcodeReaderOptions
プロパティを設定するだけでなく、SharpenFilter
および ContrastFilter
という特定のフィルタを適用します。 これらのフィルターは、バーコードの検出および読み取りのためにぼやけた画像の鮮明度を向上させるのに役立ちます。 画像補正フィルターの詳細については、'画像補正フィルターの使い方'の記事をご覧ください。
BarcodeReaderOptions
オブジェクトについては、ユーザーが画像ファイル内のすべての利用可能なバーコードをスキャンするために IronBarcode に ExpectMultipleBarcodes
を含めることをお勧めします。また、読み取りの精度とパフォーマンスのバランスを取るために Speed
もお勧めします。さらにパフォーマンスを向上させるために ExpectBarcodeTypes
、読み取りの精度を向上させるために ImageFilterCollection
オブジェクトで設定したフィルターを適用するために ImageFilters
を活用することをお勧めします。
ほとんどの使用ケースではBarcodeReaderOptions
オブジェクトの設定は任意ですが、マルチページGIFおよびTIFF画像ファイルからバーコードを読み取る際に、IronBarcodeを最大限に活用するために重要です。