ページ数の多いGIFおよびTIFFからバーコードを読み取る方法

Hairil related to ページ数の多いGIFおよびTIFFからバーコードを読み取る方法
ハイリル ハシミ ビン オマル
2023年10月31日
更新済み 2024年12月10日
共有:
This article was translated from English: Does it need improvement?
Translated
View the article in English

IronBarcode は、マルチページおよびマルチフレームの GIF や TIFF 画像形式を含む、さまざまな画像形式の入力をサポートしています。 これにより、ユーザーはTIFFまたはGIFファイルのフレームやページを手動で分割することなく、画像を簡単に使用することができます。これらのファイル形式を読み取るためにIronBarcodeの使用方法を探ってみましょう。

IronBarcodeを始める

今日から無料トライアルでIronBarcodeをあなたのプロジェクトで使い始めましょう。

最初のステップ:
green arrow pointer


マルチフレーム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
$vbLabelText   $csharpLabel

画像を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")
$vbLabelText   $csharpLabel

上記のコードスニペットから、画像ファイルを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
$vbLabelText   $csharpLabel

コードスニペットでは、BarcodeReaderOptions プロパティを設定するだけでなく、SharpenFilter および ContrastFilter という特定のフィルタを適用します。 これらのフィルターは、バーコードの検出および読み取りのためにぼやけた画像の鮮明度を向上させるのに役立ちます。 画像補正フィルターの詳細については、'画像補正フィルターの使い方'の記事をご覧ください。

BarcodeReaderOptions オブジェクトについては、ユーザーが画像ファイル内のすべての利用可能なバーコードをスキャンするために IronBarcode に ExpectMultipleBarcodes を含めることをお勧めします。また、読み取りの精度とパフォーマンスのバランスを取るために Speed もお勧めします。さらにパフォーマンスを向上させるために ExpectBarcodeTypes、読み取りの精度を向上させるために ImageFilterCollection オブジェクトで設定したフィルターを適用するために ImageFilters を活用することをお勧めします。

ほとんどの使用ケースではBarcodeReaderOptionsオブジェクトの設定は任意ですが、マルチページGIFおよびTIFF画像ファイルからバーコードを読み取る際に、IronBarcodeを最大限に活用するために重要です。

Hairil related to 高度なバーコード読み取り
ハイリル ハシミ ビン オマル
ソフトウェアエンジニア
すべての優れたエンジニアと同じように、Hairilは熱心な学習者です。C#、Python、およびJavaの知識を洗練させ、その知識を活かしてIron Softwareのチームメンバーに価値を提供しています。Hairilはマレーシアのマラ工科大学(Universiti Teknologi MARA)で化学およびプロセス工学の学士号を取得し、Iron Softwareチームに加わりました。