public Handler mHandler;
- private CameraTestActivity mActivity;
- private Rect mFramingRect;
+ private final CameraTestActivity mActivity;
+ private final Rect mFramingRect;
SaveThread(CameraTestActivity activity, Rect framingRect) {
mActivity = activity;
public void run() {
Looper.prepare();
mHandler = new Handler() {
+ @Override
public void handleMessage(Message message) {
switch (message.what) {
case R.id.save:
Looper.loop();
}
- // Save the center rectangle of the Y channel as a greyscale JPEG to the SD card
+ // Save the center rectangle of the Y channel as a greyscale PNG to the SD card.
private void save(byte[] data, int width, int height) {
int framingWidth = mFramingRect.width();
int framingHeight = mFramingRect.height();
- assert (framingWidth <= width);
- assert (framingHeight <= height);
+ if (framingWidth > width || framingHeight > height) {
+ throw new IllegalArgumentException();
+ }
int leftOffset = mFramingRect.left;
int topOffset = mFramingRect.top;
Bitmap.Config.ARGB_8888);
OutputStream outStream = getNewPhotoOutputStream();
if (outStream != null) {
- bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outStream);
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
try {
outStream.close();
Message message = Message.obtain(mActivity.mHandler, R.id.save_succeeded);
message.sendToTarget();
}
- private OutputStream getNewPhotoOutputStream() {
+ private static OutputStream getNewPhotoOutputStream() {
File sdcard = new File("/sdcard");
if (sdcard.exists()) {
File barcodes = new File(sdcard, "barcodes");
}
}
Date now = new Date();
- String fileName = now.getTime() + ".jpg";
+ String fileName = now.getTime() + ".png";
try {
return new FileOutputStream(new File(barcodes, fileName));
} catch (FileNotFoundException e) {