I am developing BarCode Scanner Application. I am Using "zxing-orient-2.1.1" library for scanning the barcode. All are Perfectly working i.e. Torch, Autofocus, Icon of Application and it's give the value of Barcode.
But, I am not able to take snapshot of barcode. I don't know where i am use Snapshot Mehod. So, anyone please help for take snapshot when barcode scan completely and save in gallery.
In this library Snapshot Function is not available. So i am making the snapshot function and placed after of Initialise Scan on scanNow method. It's take the snapshot but it's takes snapshot of mainActivity and i want barcode snapshot.
Method of Library
public void scanNow(View view) {
try {
ZxingOrient integrator = new ZxingOrient(Fill_details.this);
integrator.setToolbarColor("#2979FF") // Sets Tool bar Color
.setInfoBoxColor("#2979FF") // Sets Info box color
.setInfo("Scan a code Image.")
.setBeep(true) // Doesn't play beep sound
.setVibration(true)// Sets info message in the info box
.initiateScan(Barcode.ONE_D_CODE_TYPES);
}catch(Exception e){
e.printStackTrace();
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//retrieve scan result
ZxingOrientResult scanResult = ZxingOrient.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null && resultCode==RESULT_OK) {
takeScreenshot();
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
String date = now.toString();
String time[] = date.split("G");
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Intent intent1 = new Intent(Fill_details.this,FinishingNSave.class);
intent1.putExtra("Content",contents);
intent1.putExtra("Format",format);
intent1.putExtra("time",time[0]);
startActivity(intent1);
} else if (resultCode == RESULT_CANCELED) {}
}
Snapshot Method
private void takeScreenshot() {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
openScreenshot(imageFile);
} catch (Throwable e) {
// Several error may come out with file handling or DOM
e.printStackTrace();
}
}
Open Screenshot
private void openScreenshot(File imageFile) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(imageFile);
intent.setDataAndType(uri, "image/*");
startActivity(intent);
}
LogCat
12-06 12:16:00.759 6114-6114/com.example.himanshusrivastava.reader E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
12-06 12:16:00.759 6114-6114/com.example.himanshusrivastava.reader E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
12-06 12:16:00.759 6114-6114/com.example.himanshusrivastava.reader E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
12-06 12:16:00.759 6114-6114/com.example.himanshusrivastava.reader E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
12-06 12:16:00.802 6114-6114/com.example.himanshusrivastava.reader D/MediaPlayer: setSubtitleAnchor in MediaPlayer
12-06 12:16:01.303 6114-6114/com.example.himanshusrivastava.reader I/CaptureActivity: AutoFocus state : true; Flash State : false
12-06 12:16:01.337 6114-6114/com.example.himanshusrivastava.reader I/DecodeHintManager: Hints from the Intent: {}
12-06 12:16:01.429 6114-6114/com.example.himanshusrivastava.reader I/com.google.zxing.client.android.camera.open.OpenCameraInterface: Opening camera #0
12-06 12:16:01.596 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Screen resolution: Point(1920, 1080)
12-06 12:16:01.599 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Supported preview sizes: 1920x1080 1280x960 1280x720 960x720 960x540 720x480 768x432 640x480 352x288 320x240 176x144
12-06 12:16:01.599 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Found preview size exactly matching screen size: Point(1920, 1080)
12-06 12:16:01.599 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Camera resolution: Point(1920, 1080)
12-06 12:16:01.614 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Initial camera parameters: Panorama-mode=false;Panorama-mode-direction=l2r;ae-bracket-hdr=Off;ae-bracket-hdr-values=Off,AE-Bracket;af-bracket=af-bracket-off;af-bracket-values=af-bracket-off,af-bracket-on;antibanding=auto;antibanding-values=off,60hz,50hz,auto;art-hdr-param=25,0;auto-exposure=center-weighted;auto-exposure-lock=false;auto-exposure-lock-supported=true;auto-exposure-values=frame-average,center-weighted,spot-metering,center-weighted,spot-metering-adv,center-weighted-adv;auto-hdr-supported=true;auto-whitebalance-lock=false;auto-whitebalance-lock-supported=true;avtimer=disable;blink_support=false;brightness-step=1;cache-video-buffers=disable;camera-mode=0;cds-mode-values=off,on,auto;chroma-flash=chroma-flash-off;chroma-flash-values=chroma-flash-off,chroma-flash-on;contrast=5;contrast-step=1;dbg-log-aec=off;dbg-log-aec-values=on,off;dbg-log-af=off;dbg-log-af-values=on,off;dbg-log-awb=off;dbg-log-awb-values=on,off;denoise=denoise-on;denoise-values=denoise-off,denoise-on;dis=disable;dis-values=enable,disable;effect=none;effect-values=none,mono,negative,solarize,sepia,posterize,whiteboard,blackboard,aqua,emboss,sketch,neon;enter-Panorama-mode=false;exposure-compensation=0;exposure-compensation-step=0.166667;face-detection=off;face-detection-values=off,on;face-pro=off;face-pro-values=off,on;fast-snap-supported=true;flash-mode=off;flash-mode-values=off,auto,on,torch;flawless-level=5;flawless-limitfps-need=true;flawless-maxfps=22;flawless-mode=off;flawless-mode-values=smart,manual,off;flip-mode-values=off,flip-v,flip-h,flip-vh;focal-length=3.59;focus-areas=(0,0,0,0,0);focus-distances=Infinity,Infinity,Infinity;focus-mode=auto;focus-mode-values=auto,infinity,fixed,macro,continuous-video,continuous-picture,manual;gesture_support=true;hdr-mode=hdr-mode-multiframe;hdr-mode-values=hdr-mode-multiframe;hdr-need-1x=false;hdr-need-1x-values=false,true;hdr-third=off;hdr-third-values=off,on;hfr-size-values=960x540;histogram=disable;histogram-values=enable,disable;horizontal-view-angle=65.9;hsr-video=off;instant-aec-values=;instant-capture-values=;internal-restart=true;iso=auto;iso-values=auto,ISO_HJR,ISO100,ISO200,ISO400,ISO800,ISO1600,ISO3200;jpeg-quality=95;jpeg-thumbnail-height=154;jpeg-thumbnail-quality=85;jpeg-thumbnail-size-values=256x154,240x160,320x320,320x240,256x144,240x144,176x144,240x320,144x176,0x0;jpeg-thumbnail-width=256;lensshade=enable;lensshade-values=enable,disable;long-shot=off;longshot-supported=true;luma-adaptation=3;manual-exposure-modes=off,exp-time-priority,iso-priority,user-setting;manual-focus-modes=off,scale-mode,diopter-mode;manual-wb-modes=off,color-temperature,rbgb-gains;max-brightness=6;max-contrast=10;max-exposure-compensation=12;max-exposure-time=679.417860;max-focus-pos-dac=1023;max-focus-pos-diopter=7;max-focus-pos-index=1023;max-focus-pos-ratio=100;max-iso=19200;max-num-detected-faces-hw=10;max-num-detected-faces-sw=10;max-num-focus-areas=1;max-num-metering-areas=10;max-saturation=10;max-sce-factor=100;max-sharpness=36;max-wb-cct=8000;max-wb-gain=4;max-zoom=60;mbg_camera_mode=hdr,night,smart,panorama,pro;mce=enable;mce-values=enable,disable;metering-areas=(0,0,0,0,0);min-brightness=0;min-contrast=0;min-exposure-compensation=-12;min-exposure-time=0.013434;min-focus-pos-dac=0;min-focus-pos-diopter=0;min-focus-pos-index=0;min-focus-pos-ratio=0;min-iso=100;min-saturation=0;min-sce-factor=-100;min-sharpness=0;min-wb-cct=2000;min-wb-gain=1;night-shot=off;night-shot-frames=3;night-shot-intensity=5;night-shot-light-intensity=60;night-shot-values=off,on;noise-reduction-mode=off;noise-reduction-mode-values=off,fast,high-quality;num-retro-burst-per-shutter=0;num-snaps-per-shutter=1;opti-zoom=opti-zoom-off;opti-zoom-values=opti-zoom-off,opti-zoom-on;picture-format=jpeg;picture-format-values=jpeg,bayer-mipi-10bggr;picture-size=4160x3120;picture-size-values=4160x3120,4160x2340,3840x2160,3264x2448,3264x1836,2592x1944,2592x1458,1920x1080,1440x1080,1280x960,1280x720,720x480,640x480,352x288,320x240,176x144;preferred-preview-size-for-video=1920x1080;preview-flip=
12-06 12:16:01.615 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Requesting flash mode value from among: [off]
12-06 12:16:01.615 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Supported flash mode values: [off, auto, on, torch]
12-06 12:16:01.615 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Can set flash mode to: off
12-06 12:16:01.615 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Flash mode already set to off
12-06 12:16:01.635 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: ROTATION_0 check: 0
12-06 12:16:01.635 6114-6114/com.example.himanshusrivastava.reader I/CameraConfiguration: Rotation Happened
12-06 12:16:01.643 6114-6114/com.example.himanshusrivastava.reader I/DecodeThread: Hints: {POSSIBLE_FORMATS=[CODABAR, CODE_39, CODE_93, CODE_128, EAN_8, EAN_13, ITF, RSS_14, RSS_EXPANDED, UPC_A, UPC_E, UPC_EAN_EXTENSION], NEED_RESULT_POINT_CALLBACK=com.google.zxing.client.android.ViewfinderResultPointCallback@5ab042}
12-06 12:16:01.920 6114-6114/com.example.himanshusrivastava.reader I/AutoFocusManager: Current focus mode 'auto'; use auto focus? true
12-06 12:16:01.932 6114-6114/com.example.himanshusrivastava.reader I/Choreographer: Skipped 33 frames! The application may be doing too much work on its main thread.
12-06 12:16:01.957 6114-6114/com.example.himanshusrivastava.reader D/CameraManager: Calculated framing rect: Rect(81, 830 - 999, 1215)
12-06 12:16:02.267 6114-6114/com.example.himanshusrivastava.reader E/Camera: CAMERA_MSG_ENV_DETECT 101058054
12-06 12:16:02.330 6114-6114/com.example.himanshusrivastava.reader E/Camera: CAMERA_MSG_ENV_DETECT 101058054
12-06 12:16:02.412 6114-6121/com.example.himanshusrivastava.reader W/art: Suspending all threads took: 5.062ms
12-06 12:16:02.437 6114-6114/com.example.himanshusrivastava.reader E/Camera: CAMERA_MSG_ENV_DETECT 101058054
12-06 12:16:02.478 6114-6114/com.example.himanshusrivastava.reader E/Camera: CAMERA_MSG_ENV_DETECT 101058054