2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Multimedia
22 /// This class contains the Media Vision barcode generate API.\n
23 /// These APIs can be used for generating the barcodes and QR codes.
24 /// Different encoding types <see cref="QrMode"/> , error correction codes <see cref="ErrorCorrectionLevel"/> and code versions are supported for QRCodes.
26 public static class BarcodeGenerator
29 /// Generates <see cref="MediaVisionSource"/> with barcode image.
32 /// If the text attribute of engine configuration is set to <see cref="TextAttribute.Visible"/> , InvalidOperationException will be thrown when type is <see cref="BarcodeType.QR"/>
34 /// <param name="config">The configuration of the bar code generator engine</param>
35 /// <param name="message">The message to be encoded in the barcode</param>
36 /// <param name="type">Type of the barcode to be generated</param>
37 /// <param name="source">The media vision source object which will be used to fill by the buffer with generated image</param>
38 /// <param name="qrConfig">The QrConfig object - required for QR codes only</param>
42 public static MediaVisionSource GenerateSource(BarcodeGeneratorEngineConfiguration config, string message, BarcodeType type, QrConfiguration qrConfig = null)
44 if (string.IsNullOrEmpty(message) ||
45 type == BarcodeType.Undefined ||
46 (type == BarcodeType.QR &&
48 qrConfig.ErrorCorrectionLevel == ErrorCorrectionLevel.Unavailable ||
49 qrConfig.Mode == QrMode.Unavailable ||
50 qrConfig.Version < 1 ||
51 qrConfig.Version > 40)))
53 throw new ArgumentException("Invalid parameter");
56 MediaVisionSource source = new MediaVisionSource();
57 int ret = (type == BarcodeType.QR) ?
58 Interop.MediaVision.BarCodeGenerator.GenerateSource(config._engineHandle, message, type, qrConfig.Mode, qrConfig.ErrorCorrectionLevel, qrConfig.Version, source._sourceHandle) :
59 Interop.MediaVision.BarCodeGenerator.GenerateSource(config._engineHandle, message, type, QrMode.Unavailable, ErrorCorrectionLevel.Unavailable, 0, source._sourceHandle);
60 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to generate source");
65 /// Generates image file with barcode.
68 /// If the text attribute of engine configuration is set to <see cref="TextAttribute.Visible"/> ,
69 /// InvalidOperationException will be thrown when type is <see cref="BarcodeType.QR"/>\n
71 /// <param name="config">The configuration of the bar code generator engine</param>
72 /// <param name="message">The message to be encoded in the barcode</param>
73 /// <param name="type">Type of the barcode to be generated</param>
74 /// <param name="imageConfig">The BarcodeImageConfig object that contains information about the file to be generated</param>
75 /// <param name="qrConfig">The QrConfig object - required for QR codes only</param>
79 public static void GenerateImage(BarcodeGeneratorEngineConfiguration config, string message, BarcodeType type, BarcodeImageConfiguration imageConfig, QrConfiguration qrConfig = null)
81 if (string.IsNullOrEmpty(message) ||
82 imageConfig == null ||
83 string.IsNullOrEmpty(imageConfig.Path) ||
84 type == BarcodeType.Undefined ||
85 (type == BarcodeType.QR &&
87 qrConfig.ErrorCorrectionLevel == ErrorCorrectionLevel.Unavailable ||
88 qrConfig.Mode == QrMode.Unavailable ||
89 qrConfig.Version < 1 ||
90 qrConfig.Version > 40)))
92 throw new ArgumentException("Invalid parameter");
95 int ret = (type == BarcodeType.QR) ?
96 Interop.MediaVision.BarCodeGenerator.GenerateImage(config._engineHandle,
102 qrConfig.ErrorCorrectionLevel,
105 imageConfig.Format) :
106 Interop.MediaVision.BarCodeGenerator.GenerateImage(config._engineHandle,
112 ErrorCorrectionLevel.Unavailable,
116 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to generate image");