Java源码示例:me.dm7.barcodescanner.core.DisplayUtils

示例1
public synchronized void updateFramingRect() {
    Point viewResolution = new Point(this.getWidth(), this.getHeight());
    int orientation = DisplayUtils.getScreenOrientation(this.getContext());
    int width;
    int height;
    if (this.mSquareViewFinder) {
        if (orientation != 1) {
            height = (int) ((float) this.getHeight() * 0.625F);
            width = height;
        } else {
            width = (int) ((float) this.getWidth() * 0.625F);
            height = width;
        }
    } else if (orientation != 1) {
        height = (int) ((float) this.getHeight() * 0.625F);
        width = (int) (1.4F * (float) height);
    } else {
        width = (int) ((float) this.getWidth() * 0.75F);
        height = (int) (0.75F * (float) width);
    }

    if (width > this.getWidth()) {
        width = this.getWidth() - 50;
    }

    if (height > this.getHeight()) {
        height = this.getHeight() - 50;
    }

    int leftOffset = (viewResolution.x - width) / 2;
    int topOffset = (viewResolution.y - height) / 2;
    this.mFramingRectF = new RectF(leftOffset, topOffset, leftOffset + width, topOffset + height);
}
 
示例2
public synchronized void updateFramingRect() {
    Point viewResolution = new Point(this.getWidth(), this.getHeight());
    int orientation = DisplayUtils.getScreenOrientation(this.getContext());
    int width;
    int height;
    if (this.mSquareViewFinder) {
        if (orientation != 1) {
            height = (int) ((float) this.getHeight() * 0.625F);
            width = height;
        } else {
            width = (int) ((float) this.getWidth() * 0.625F);
            height = width;
        }
    } else if (orientation != 1) {
        height = (int) ((float) this.getHeight() * 0.625F);
        width = (int) (1.4F * (float) height);
    } else {
        width = (int) ((float) this.getWidth() * 0.75F);
        height = (int) (0.75F * (float) width);
    }

    if (width > this.getWidth()) {
        width = this.getWidth() - 50;
    }

    if (height > this.getHeight()) {
        height = this.getHeight() - 50;
    }

    int leftOffset = (viewResolution.x - width) / 2;
    int topOffset = (viewResolution.y - height) / 2;
    this.mFramingRectF = new RectF(leftOffset, topOffset, leftOffset + width, topOffset + height);
}
 
示例3
public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Camera.Size size = parameters.getPreviewSize();
    int width = size.width;
    int height = size.height;
    if(DisplayUtils.getScreenOrientation(this.getContext()) == 1) {
        byte[] rawResult = new byte[data.length];

        int source;
        for(source = 0; source < height; ++source) {
            for(int bitmap = 0; bitmap < width; ++bitmap) {
                rawResult[bitmap * height + height - source - 1] = data[bitmap + source * width];
            }
        }

        source = width;
        width = height;
        height = source;
        data = rawResult;
    }

    Result var20 = null;
    PlanarYUVLuminanceSource var21 = this.buildLuminanceSource(data, width, height);
    if(var21 != null) {
        BinaryBitmap var22 = new BinaryBitmap(new HybridBinarizer(var21));

        try {
            var20 = this.mMultiFormatReader.decodeWithState(var22);
        } catch (ReaderException var16) {
            ;
        } catch (NullPointerException var17) {
            ;
        } catch (ArrayIndexOutOfBoundsException var18) {
            ;
        } finally {
            this.mMultiFormatReader.reset();
        }
    }

    if(var20 != null) {
        this.stopCamera();
        if(this.mResultHandler != null) {
            this.mResultHandler.handleResult(var20);
        }
    } else {
        camera.setOneShotPreviewCallback(this);
    }

}
 
示例4
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
    if(mResultHandler == null) {
        return;
    }
    
    try {
        Camera.Parameters parameters = camera.getParameters();
        Camera.Size size = parameters.getPreviewSize();
        int width = size.width;
        int height = size.height;

        if (DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
            byte[] rotatedData = new byte[data.length];
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++)
                    rotatedData[x * height + height - y - 1] = data[x + y * width];
            }
            int tmp = width;
            width = height;
            height = tmp;
            data = rotatedData;
        }

        Result rawResult = null;
        PlanarYUVLuminanceSource source = buildLuminanceSource(data, width, height);

        if (source != null) {
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
            try {
                rawResult = mMultiFormatReader.decodeWithState(bitmap);
            } catch (ReaderException re) {
                // continue
            } catch (NullPointerException npe) {
                // This is terrible
            } catch (ArrayIndexOutOfBoundsException aoe) {

            } finally {
                mMultiFormatReader.reset();
            }
        }

        final Result finalRawResult = rawResult;

        if (finalRawResult != null) {
            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                    // Stopping the preview can take a little long.
                    // So we want to set result handler to null to discard subsequent calls to
                    // onPreviewFrame.
                    ResultHandler tmpResultHandler = mResultHandler;
                    mResultHandler = null;

                    stopCameraPreview();
                    if (tmpResultHandler != null) {
                        tmpResultHandler.handleResult(finalRawResult);
                    }
                }
            });
        } else {
            camera.setOneShotPreviewCallback(this);
        }
    } catch(RuntimeException e) {
        // TODO: Terrible hack. It is possible that this method is invoked after camera is released.
        Log.e(TAG, e.toString(), e);
    }
}