forked from finally-vince/ZXingMini
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YooJia.Chen
committed
Nov 25, 2015
1 parent
1e024bf
commit fa06337
Showing
9 changed files
with
254 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
zxing/src/main/java/com/github/yoojia/zxing/camera/CameraPreview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.github.yoojia.zxing.camera; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.Matrix; | ||
import android.graphics.Rect; | ||
import android.graphics.YuvImage; | ||
import android.hardware.Camera; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
final class CameraPreview { | ||
|
||
public final byte[] data; | ||
public final Camera camera; | ||
|
||
public CameraPreview(byte[] data, Camera camera) { | ||
this.data = data; | ||
this.camera = camera; | ||
} | ||
|
||
public Bitmap capture(){ | ||
final Camera.Parameters parameters = camera.getParameters(); | ||
final int width = parameters.getPreviewSize().width; | ||
final int height = parameters.getPreviewSize().height; | ||
final YuvImage yuv = new YuvImage(data, parameters.getPreviewFormat(), width, height, null); | ||
final ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
yuv.compressToJpeg(new Rect(0, 0, width, height), 100, out);// Best | ||
final byte[] bytes = out.toByteArray(); | ||
final Bitmap src = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); | ||
final Matrix matrix = new Matrix(); | ||
matrix.setRotate(90); | ||
final int originWidth = src.getWidth(); | ||
final int originHeight = src.getHeight(); | ||
final int targetWH = originWidth > originHeight ? originHeight : originWidth; | ||
final int offsetX = originWidth > originHeight ? (originWidth - originHeight): 0; | ||
final int offsetY = originWidth > originHeight ? 0 : (originHeight - originWidth); | ||
return Bitmap.createBitmap(src, offsetX, offsetY, targetWH, targetWH, matrix, true); | ||
} | ||
} |
Oops, something went wrong.