summaryrefslogtreecommitdiff
path: root/samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.java
diff options
context:
space:
mode:
authorChristian Mehlmauer <FireFart@gmail.com>2010-05-20 21:02:04 +0200
committerChristian Mehlmauer <FireFart@gmail.com>2010-06-12 12:13:18 +0200
commit62e92d7a2a3fd2798901ec2e7c452ff0e4067163 (patch)
treef2e9f60c4735feb3a6e443a15578de58d0fb54d2 /samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.java
parent4b5c09f29e37c8d07dcba57e4c4da13089a9d63d (diff)
Cleaned up Samples by removing unsed imports and variables.
Changed deprecated Config.LOGD to Config.DEBUG Removed unnecessary whitespaces Change-Id: I01414dd83eb6f9a41e56762dd7fc00e7f1115039
Diffstat (limited to 'samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.java')
-rw-r--r--samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.java26
1 files changed, 11 insertions, 15 deletions
diff --git a/samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.java b/samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.java
index e3e5d9ae3..61fe9d5c2 100644
--- a/samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.java
+++ b/samples/ApiDemos/src/com/example/android/apis/graphics/CreateBitmap.java
@@ -16,13 +16,9 @@
package com.example.android.apis.graphics;
-import com.example.android.apis.R;
-
-import android.app.Activity;
import android.content.Context;
import android.graphics.*;
import android.os.Bundle;
-import android.view.KeyEvent;
import android.view.*;
import java.io.ByteArrayOutputStream;
@@ -34,11 +30,11 @@ public class CreateBitmap extends GraphicsActivity {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
-
+
private static final int WIDTH = 50;
private static final int HEIGHT = 50;
private static final int STRIDE = 64; // must be >= WIDTH
-
+
private static int[] createColors() {
int[] colors = new int[STRIDE * HEIGHT];
for (int y = 0; y < HEIGHT; y++) {
@@ -52,18 +48,18 @@ public class CreateBitmap extends GraphicsActivity {
}
return colors;
}
-
+
private static class SampleView extends View {
private Bitmap[] mBitmaps;
private Bitmap[] mJPEG;
private Bitmap[] mPNG;
private int[] mColors;
private Paint mPaint;
-
+
private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
int quality) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
- src.compress(format, quality, os);
+ src.compress(format, quality, os);
byte[] array = os.toByteArray();
return BitmapFactory.decodeByteArray(array, 0, array.length);
@@ -72,7 +68,7 @@ public class CreateBitmap extends GraphicsActivity {
public SampleView(Context context) {
super(context);
setFocusable(true);
-
+
mColors = createColors();
int[] colors = mColors;
@@ -84,7 +80,7 @@ public class CreateBitmap extends GraphicsActivity {
Bitmap.Config.RGB_565);
mBitmaps[2] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap.Config.ARGB_4444);
-
+
// these three will have their colors set later
mBitmaps[3] = Bitmap.createBitmap(WIDTH, HEIGHT,
Bitmap.Config.ARGB_8888);
@@ -95,10 +91,10 @@ public class CreateBitmap extends GraphicsActivity {
for (int i = 3; i <= 5; i++) {
mBitmaps[i].setPixels(colors, 0, STRIDE, 0, 0, WIDTH, HEIGHT);
}
-
+
mPaint = new Paint();
mPaint.setDither(true);
-
+
// now encode/decode using JPEG and PNG
mJPEG = new Bitmap[mBitmaps.length];
mPNG = new Bitmap[mBitmaps.length];
@@ -107,7 +103,7 @@ public class CreateBitmap extends GraphicsActivity {
mPNG[i] = codec(mBitmaps[i], Bitmap.CompressFormat.PNG, 0);
}
}
-
+
@Override protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
@@ -117,7 +113,7 @@ public class CreateBitmap extends GraphicsActivity {
canvas.drawBitmap(mPNG[i], 160, 0, null);
canvas.translate(0, mBitmaps[i].getHeight());
}
-
+
// draw the color array directly, w/o craeting a bitmap object
canvas.drawBitmap(mColors, 0, STRIDE, 0, 0, WIDTH, HEIGHT,
true, null);