Updated the Android Test app to use a wider viewfinder, to save images as PNGs instea...
[zxing.git] / androidtest / src / com / google / zxing / client / androidtest / SaveThread.java
index 583db57..166e495 100755 (executable)
@@ -36,8 +36,8 @@ final class SaveThread extends Thread {
 
   public Handler mHandler;
 
-  private CameraTestActivity mActivity;
-  private Rect mFramingRect;
+  private final CameraTestActivity mActivity;
+  private final Rect mFramingRect;
 
   SaveThread(CameraTestActivity activity, Rect framingRect) {
     mActivity = activity;
@@ -48,6 +48,7 @@ final class SaveThread extends Thread {
   public void run() {
     Looper.prepare();
     mHandler = new Handler() {
+      @Override
       public void handleMessage(Message message) {
         switch (message.what) {
           case R.id.save:
@@ -62,12 +63,13 @@ final class SaveThread extends Thread {
     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;
@@ -86,7 +88,7 @@ final class SaveThread extends Thread {
         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);
@@ -101,7 +103,7 @@ final class SaveThread extends Thread {
     message.sendToTarget();
   }
 
-  private OutputStream getNewPhotoOutputStream() {
+  private static OutputStream getNewPhotoOutputStream() {
     File sdcard = new File("/sdcard");
     if (sdcard.exists()) {
       File barcodes = new File(sdcard, "barcodes");
@@ -117,7 +119,7 @@ final class SaveThread extends Thread {
         }
       }
       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) {