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="qrConfig">The QrConfig object - required for QR codes only</param>
39 /// <param name="source">The media vision source object which will be used to fill by the buffer with generated image</param>
44 public static MediaVisionSource GenerateSource(BarcodeGeneratorEngineConfiguration config, string message, BarcodeType type, QrConfiguration qrConfig = null)
46 if (string.IsNullOrEmpty(message) ||
47 type == BarcodeType.Undefined ||
48 (type == BarcodeType.QR &&
50 qrConfig.ErrorCorrectionLevel == ErrorCorrectionLevel.Unavailable ||
51 qrConfig.Mode == QrMode.Unavailable ||
52 qrConfig.Version < 1 ||
53 qrConfig.Version > 40)))
55 throw new ArgumentException("Invalid parameter");
58 MediaVisionSource source = new MediaVisionSource();
59 int ret = (type == BarcodeType.QR) ?
60 Interop.MediaVision.BarCodeGenerator.GenerateSource(config._engineHandle, message, type, qrConfig.Mode, qrConfig.ErrorCorrectionLevel, qrConfig.Version, source._sourceHandle) :
61 Interop.MediaVision.BarCodeGenerator.GenerateSource(config._engineHandle, message, type, QrMode.Unavailable, ErrorCorrectionLevel.Unavailable, 0, source._sourceHandle);
62 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to generate source");
67 /// Generates image file with barcode.
70 /// If the text attribute of engine configuration is set to <see cref="TextAttribute.Visible"/> ,
71 /// InvalidOperationException will be thrown when type is <see cref="BarcodeType.QR"/>\n
73 /// <param name="config">The configuration of the bar code generator engine</param>
74 /// <param name="message">The message to be encoded in the barcode</param>
75 /// <param name="type">Type of the barcode to be generated</param>
76 /// <param name="imageConfig">The BarcodeImageConfig object that contains information about the file to be generated</param>
77 /// <param name="qrConfig">The QrConfig object - required for QR codes only</param>
81 public static void GenerateImage(BarcodeGeneratorEngineConfiguration config, string message, BarcodeType type, BarcodeImageConfiguration imageConfig, QrConfiguration qrConfig = null)
83 if (string.IsNullOrEmpty(message) ||
84 imageConfig == null ||
85 string.IsNullOrEmpty(imageConfig.Path) ||
86 type == BarcodeType.Undefined ||
87 (type == BarcodeType.QR &&
89 qrConfig.ErrorCorrectionLevel == ErrorCorrectionLevel.Unavailable ||
90 qrConfig.Mode == QrMode.Unavailable ||
91 qrConfig.Version < 1 ||
92 qrConfig.Version > 40)))
94 throw new ArgumentException("Invalid parameter");
97 int ret = (type == BarcodeType.QR) ?
98 Interop.MediaVision.BarCodeGenerator.GenerateImage(config._engineHandle,
104 qrConfig.ErrorCorrectionLevel,
107 imageConfig.Format) :
108 Interop.MediaVision.BarCodeGenerator.GenerateImage(config._engineHandle,
114 ErrorCorrectionLevel.Unavailable,
118 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to generate image");