示例#1
0
 DmtxDecode(
     [In] byte[] image,
     [In] UInt32 width,
     [In] UInt32 height,
     [In] UInt32 bitmapStride,
     [In] DecodeOptions options,
     [In] DmtxDiagnosticImageCallback diagnosticImageCallback,
     [In] DiagnosticImageStyles diagnosticImageStyle,
     [In] DmtxDecodeCallback decodeCallback);
示例#2
0
        public static void Decode(
            Bitmap b,
            DecodeOptions options,
            DecodeCallback Callback,
            DiagnosticImageStyles diagnosticImageStyle, DecodeDiagnosticImageCallback DiagnosticImageCallback)
        {
            Exception decodeException = null;
            byte      status;

            try {
                int    bitmapStride;
                byte[] pxl = BitmapToByteArray(b, out bitmapStride);

                DmtxDiagnosticImageCallback diagnosticImageCallbackParam = null;
                if (DiagnosticImageCallback != null)
                {
                    diagnosticImageCallbackParam = delegate(IntPtr data, uint totalBytes, uint headerBytes) {
                        try {
                            byte[] pnmData = new byte[totalBytes];
                            Marshal.Copy(data, pnmData, 0, pnmData.Length);
                            using (MemoryStream pnmInputStream = new MemoryStream(pnmData)) {
                                Bitmap bm = PnmToBitmap(pnmInputStream);
                                DiagnosticImageCallback(bm);
                            }
                        } catch (Exception ex) {
                            decodeException = ex;
                        }
                    };
                }

                status = DmtxDecode(
                    pxl,
                    (UInt32)b.Width,
                    (UInt32)b.Height,
                    (UInt32)bitmapStride,
                    options,
                    diagnosticImageCallbackParam, diagnosticImageStyle,
                    delegate(DecodedInternal dmtxDecodeResult) {
                    DmtxDecoded result;
                    try {
                        result            = new DmtxDecoded();
                        result.Corners    = dmtxDecodeResult.Corners;
                        result.SymbolInfo = dmtxDecodeResult.SymbolInfo;
                        result.Data       = new byte[dmtxDecodeResult.DataSize];
                        for (int dataIdx = 0; dataIdx < dmtxDecodeResult.DataSize; dataIdx++)
                        {
                            result.Data[dataIdx] = Marshal.ReadByte(dmtxDecodeResult.Data, dataIdx);
                        }
                        Callback(result);
                        return(true);
                    } catch (Exception ex) {
                        decodeException = ex;
                        return(false);
                    }
                });
            } catch (Exception ex) {
                throw new DmtxException("Error calling native function.", ex);
            }
            if (decodeException != null)
            {
                throw decodeException;
            }
            if (status == RETURN_NO_MEMORY)
            {
                throw new DmtxOutOfMemoryException("Not enough memory.");
            }
            else if (status == RETURN_INVALID_ARGUMENT)
            {
                throw new DmtxInvalidArgumentException("Invalid options configuration.");
            }
            else if (status > 0)
            {
                throw new DmtxException("Unknown error.");
            }
        }