Example usage for android.graphics Bitmap getPixels

List of usage examples for android.graphics Bitmap getPixels

Introduction

In this page you can find the example usage for android.graphics Bitmap getPixels.

Prototype

public void getPixels(@ColorInt int[] pixels, int offset, int stride, int x, int y, int width, int height) 

Source Link

Document

Returns in pixels[] a copy of the data in the bitmap.

Usage

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap fastblur(Bitmap bmImage, int radius) {

    // Stack Blur v1.0 from
    // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
    ///* w  ww  .  ja  v  a  2s.co  m*/
    // Java Author: Mario Klingemann <mario at quasimondo.com>
    // http://incubator.quasimondo.com
    // created Feburary 29, 2004
    // Android port : Yahel Bouaziz <yahel at kayenko.com>
    // http://www.kayenko.com
    // ported april 5th, 2012

    // This is a compromise between Gaussian Blur and Box blur
    // It creates much better looking blurs than Box Blur, but is
    // 7x faster than my Gaussian Blur implementation.
    //
    // I called it Stack Blur because this describes best how this
    // filter works internally: it creates a kind of moving stack
    // of colors whilst scanning through the image. Thereby it
    // just has to add one new block of color to the right side
    // of the stack and remove the leftmost color. The remaining
    // colors on the topmost layer of the stack are either added on
    // or reduced by one, depending on if they are on the right or
    // on the left side of the stack.
    //
    // If you are using this algorithm in your code please add
    // the following line:
    //
    // Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>

    Bitmap bmTemp = bmImage.copy(bmImage.getConfig(), true);

    if (radius < 1) {
        return (null);
    }

    int w = bmTemp.getWidth();
    int h = bmTemp.getHeight();

    int[] pix = new int[w * h];
    bmTemp.getPixels(pix, 0, w, 0, 0, w, h);

    int wm = w - 1;
    int hm = h - 1;
    int wh = w * h;
    int div = radius + radius + 1;

    int r[] = new int[wh];
    int g[] = new int[wh];
    int b[] = new int[wh];
    int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
    int vmin[] = new int[Math.max(w, h)];

    int divsum = (div + 1) >> 1;
    divsum *= divsum;
    int dv[] = new int[256 * divsum];
    for (i = 0; i < 256 * divsum; i++) {
        dv[i] = (i / divsum);
    }

    yw = yi = 0;

    int[][] stack = new int[div][3];
    int stackpointer;
    int stackstart;
    int[] sir;
    int rbs;
    int r1 = radius + 1;
    int routsum, goutsum, boutsum;
    int rinsum, ginsum, binsum;

    for (y = 0; y < h; y++) {
        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
        for (i = -radius; i <= radius; i++) {
            p = pix[yi + Math.min(wm, Math.max(i, 0))];
            sir = stack[i + radius];
            sir[0] = (p & 0xff0000) >> 16;
            sir[1] = (p & 0x00ff00) >> 8;
            sir[2] = (p & 0x0000ff);
            rbs = r1 - Math.abs(i);
            rsum += sir[0] * rbs;
            gsum += sir[1] * rbs;
            bsum += sir[2] * rbs;
            if (i > 0) {
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
            } else {
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
            }
        }
        stackpointer = radius;

        for (x = 0; x < w; x++) {

            r[yi] = dv[rsum];
            g[yi] = dv[gsum];
            b[yi] = dv[bsum];

            rsum -= routsum;
            gsum -= goutsum;
            bsum -= boutsum;

            stackstart = stackpointer - radius + div;
            sir = stack[stackstart % div];

            routsum -= sir[0];
            goutsum -= sir[1];
            boutsum -= sir[2];

            if (y == 0) {
                vmin[x] = Math.min(x + radius + 1, wm);
            }
            p = pix[yw + vmin[x]];

            sir[0] = (p & 0xff0000) >> 16;
            sir[1] = (p & 0x00ff00) >> 8;
            sir[2] = (p & 0x0000ff);

            rinsum += sir[0];
            ginsum += sir[1];
            binsum += sir[2];

            rsum += rinsum;
            gsum += ginsum;
            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;
            sir = stack[(stackpointer) % div];

            routsum += sir[0];
            goutsum += sir[1];
            boutsum += sir[2];

            rinsum -= sir[0];
            ginsum -= sir[1];
            binsum -= sir[2];

            yi++;
        }
        yw += w;
    }

    for (x = 0; x < w; x++) {
        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
        yp = -radius * w;
        for (i = -radius; i <= radius; i++) {
            yi = Math.max(0, yp) + x;

            sir = stack[i + radius];

            sir[0] = r[yi];
            sir[1] = g[yi];
            sir[2] = b[yi];

            rbs = r1 - Math.abs(i);

            rsum += r[yi] * rbs;
            gsum += g[yi] * rbs;
            bsum += b[yi] * rbs;

            if (i > 0) {
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
            } else {
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
            }

            if (i < hm) {
                yp += w;
            }
        }
        yi = x;
        stackpointer = radius;
        for (y = 0; y < h; y++) {
            // Preserve alpha channel: ( 0xff000000 & pix[yi] )
            pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];

            rsum -= routsum;
            gsum -= goutsum;
            bsum -= boutsum;

            stackstart = stackpointer - radius + div;
            sir = stack[stackstart % div];

            routsum -= sir[0];
            goutsum -= sir[1];
            boutsum -= sir[2];

            if (x == 0) {
                vmin[y] = Math.min(y + r1, hm) * w;
            }
            p = x + vmin[y];

            sir[0] = r[p];
            sir[1] = g[p];
            sir[2] = b[p];

            rinsum += sir[0];
            ginsum += sir[1];
            binsum += sir[2];

            rsum += rinsum;
            gsum += ginsum;
            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;
            sir = stack[stackpointer];

            routsum += sir[0];
            goutsum += sir[1];
            boutsum += sir[2];

            rinsum -= sir[0];
            ginsum -= sir[1];
            binsum -= sir[2];

            yi += w;
        }
    }

    bmTemp.setPixels(pix, 0, w, 0, 0, w, h);

    return bmTemp;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ??//  w  ww  . j a  v  a  2 s .  c  o m
 * 
 * @param img
 *            ?Bitmap
 * @return ??
 */
public static Bitmap convertGreyImg(Bitmap img) {
    int width = img.getWidth(); // ??
    int height = img.getHeight(); // ??

    int[] pixels = new int[width * height]; // ???

    img.getPixels(pixels, 0, width, 0, 0, width, height);
    int alpha = 0xFF << 24;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int grey = pixels[width * i + j];

            int red = ((grey & 0x00FF0000) >> 16);
            int green = ((grey & 0x0000FF00) >> 8);
            int blue = (grey & 0x000000FF);

            grey = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
            grey = alpha | (grey << 16) | (grey << 8) | grey;
            pixels[width * i + j] = grey;
        }
    }
    Bitmap result = Bitmap.createBitmap(width, height, Config.RGB_565);
    result.setPixels(pixels, 0, width, 0, 0, width, height);
    return result;
}

From source file:Main.java

public static void blur(Bitmap bitmap, int radius) {

    // Stack Blur v1.0 from
    // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
    ////from  ww w . j  ava 2s.c  om
    // Java Author: Mario Klingemann <mario at quasimondo.com>
    // http://incubator.quasimondo.com
    // created Feburary 29, 2004
    // Android port : Yahel Bouaziz <yahel at kayenko.com>
    // http://www.kayenko.com
    // ported april 5th, 2012

    // This is a compromise between Gaussian Blur and Box blur
    // It creates much better looking blurs than Box Blur, but is
    // 7x faster than my Gaussian Blur implementation.
    //
    // I called it Stack Blur because this describes best how this
    // filter works internally: it creates a kind of moving stack
    // of colors whilst scanning through the image. Thereby it
    // just has to add one new block of color to the right side
    // of the stack and remove the leftmost color. The remaining
    // colors on the topmost layer of the stack are either added on
    // or reduced by one, depending on if they are on the right or
    // on the left side of the stack.
    //
    // If you are using this algorithm in your code please add
    // the following line:
    //
    // Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>

    //        Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);

    if (radius < 1) {
        return;
    }

    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    int[] pix = new int[w * h];
    Log.d(TAG, w + " " + h + " " + pix.length);
    bitmap.getPixels(pix, 0, w, 0, 0, w, h);

    int wm = w - 1;
    int hm = h - 1;
    int wh = w * h;
    int div = radius + radius + 1;

    int r[] = new int[wh];
    int g[] = new int[wh];
    int b[] = new int[wh];
    int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
    int vmin[] = new int[Math.max(w, h)];

    int divsum = (div + 1) >> 1;
    divsum *= divsum;
    int dv[] = new int[256 * divsum];
    for (i = 0; i < 256 * divsum; i++) {
        dv[i] = (i / divsum);
    }

    yw = yi = 0;

    int[][] stack = new int[div][3];
    int stackpointer;
    int stackstart;
    int[] sir;
    int rbs;
    int r1 = radius + 1;
    int routsum, goutsum, boutsum;
    int rinsum, ginsum, binsum;

    for (y = 0; y < h; y++) {
        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
        for (i = -radius; i <= radius; i++) {
            p = pix[yi + Math.min(wm, Math.max(i, 0))];
            sir = stack[i + radius];
            sir[0] = (p & 0xff0000) >> 16;
            sir[1] = (p & 0x00ff00) >> 8;
            sir[2] = (p & 0x0000ff);
            rbs = r1 - Math.abs(i);
            rsum += sir[0] * rbs;
            gsum += sir[1] * rbs;
            bsum += sir[2] * rbs;
            if (i > 0) {
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
            } else {
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
            }
        }
        stackpointer = radius;

        for (x = 0; x < w; x++) {

            r[yi] = dv[rsum];
            g[yi] = dv[gsum];
            b[yi] = dv[bsum];

            rsum -= routsum;
            gsum -= goutsum;
            bsum -= boutsum;

            stackstart = stackpointer - radius + div;
            sir = stack[stackstart % div];

            routsum -= sir[0];
            goutsum -= sir[1];
            boutsum -= sir[2];

            if (y == 0) {
                vmin[x] = Math.min(x + radius + 1, wm);
            }
            p = pix[yw + vmin[x]];

            sir[0] = (p & 0xff0000) >> 16;
            sir[1] = (p & 0x00ff00) >> 8;
            sir[2] = (p & 0x0000ff);

            rinsum += sir[0];
            ginsum += sir[1];
            binsum += sir[2];

            rsum += rinsum;
            gsum += ginsum;
            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;
            sir = stack[(stackpointer) % div];

            routsum += sir[0];
            goutsum += sir[1];
            boutsum += sir[2];

            rinsum -= sir[0];
            ginsum -= sir[1];
            binsum -= sir[2];

            yi++;
        }
        yw += w;
    }
    for (x = 0; x < w; x++) {
        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
        yp = -radius * w;
        for (i = -radius; i <= radius; i++) {
            yi = Math.max(0, yp) + x;

            sir = stack[i + radius];

            sir[0] = r[yi];
            sir[1] = g[yi];
            sir[2] = b[yi];

            rbs = r1 - Math.abs(i);

            rsum += r[yi] * rbs;
            gsum += g[yi] * rbs;
            bsum += b[yi] * rbs;

            if (i > 0) {
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
            } else {
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
            }

            if (i < hm) {
                yp += w;
            }
        }
        yi = x;
        stackpointer = radius;
        for (y = 0; y < h; y++) {
            pix[yi] = 0xff000000 | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];

            rsum -= routsum;
            gsum -= goutsum;
            bsum -= boutsum;

            stackstart = stackpointer - radius + div;
            sir = stack[stackstart % div];

            routsum -= sir[0];
            goutsum -= sir[1];
            boutsum -= sir[2];

            if (x == 0) {
                vmin[y] = Math.min(y + r1, hm) * w;
            }
            p = x + vmin[y];

            sir[0] = r[p];
            sir[1] = g[p];
            sir[2] = b[p];

            rinsum += sir[0];
            ginsum += sir[1];
            binsum += sir[2];

            rsum += rinsum;
            gsum += ginsum;
            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;
            sir = stack[stackpointer];

            routsum += sir[0];
            goutsum += sir[1];
            boutsum += sir[2];

            rinsum -= sir[0];
            ginsum -= sir[1];
            binsum -= sir[2];

            yi += w;
        }
    }

    Log.d(TAG, w + " " + h + " " + pix.length);
    bitmap.setPixels(pix, 0, w, 0, 0, w, h);
}

From source file:com.adamas.client.android.MainActivity.java

protected Result decode(Uri uri) {
    try {//  w w w  .  ja v a  2  s.c om
        InputStream inputStream = getContentResolver().openInputStream(uri);
        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
        if (bitmap == null) {
            return null;
        }
        int width = bitmap.getWidth(), height = bitmap.getHeight();
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
        bitmap.recycle();
        bitmap = null;
        RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source));
        MultiFormatReader reader = new MultiFormatReader();
        try {
            com.google.zxing.Result result = reader.decode(bBitmap);
            return result;
        } catch (Exception e) {
            return null;
        }
    } catch (FileNotFoundException e) {
        return null;
    }
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ?//  ww  w . ja v  a  2s . c o m
 * 
 * @param bitmap
 *            
 * @return ??
 */
public static Bitmap nostalgic(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
    int pixColor = 0;
    int pixR = 0;
    int pixG = 0;
    int pixB = 0;
    int newR = 0;
    int newG = 0;
    int newB = 0;
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 0; i < height; i++) {
        for (int k = 0; k < width; k++) {
            pixColor = pixels[width * i + k];
            pixR = Color.red(pixColor);
            pixG = Color.green(pixColor);
            pixB = Color.blue(pixColor);
            newR = (int) (0.393 * pixR + 0.769 * pixG + 0.189 * pixB);
            newG = (int) (0.349 * pixR + 0.686 * pixG + 0.168 * pixB);
            newB = (int) (0.272 * pixR + 0.534 * pixG + 0.131 * pixB);
            int newColor = Color.argb(255, newR > 255 ? 255 : newR, newG > 255 ? 255 : newG,
                    newB > 255 ? 255 : newB);
            pixels[width * i + k] = newColor;
        }
    }
    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ?/*from   www. j av  a  2 s.c  om*/
 * 
 * @param bitmap
 *            
 * @return ??
 */
public static Bitmap emboss(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

    int pixR = 0;
    int pixG = 0;
    int pixB = 0;

    int pixColor = 0;

    int newR = 0;
    int newG = 0;
    int newB = 0;

    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    int pos = 0;
    for (int i = 1, length = height - 1; i < length; i++) {
        for (int k = 1, len = width - 1; k < len; k++) {
            pos = i * width + k;
            pixColor = pixels[pos];

            pixR = Color.red(pixColor);
            pixG = Color.green(pixColor);
            pixB = Color.blue(pixColor);

            pixColor = pixels[pos + 1];
            newR = Color.red(pixColor) - pixR + 127;
            newG = Color.green(pixColor) - pixG + 127;
            newB = Color.blue(pixColor) - pixB + 127;

            newR = Math.min(255, Math.max(0, newR));
            newG = Math.min(255, Math.max(0, newG));
            newB = Math.min(255, Math.max(0, newB));

            pixels[pos] = Color.argb(255, newR, newG, newB);
        }
    }

    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ?/*from  w w  w.j  a va2 s .co m*/
 * 
 * @param bitmap
 *            
 * @return ??
 */
public static Bitmap film(Bitmap bitmap) {
    // RGBA
    final int MAX_VALUE = 255;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

    int pixR = 0;
    int pixG = 0;
    int pixB = 0;

    int pixColor = 0;

    int newR = 0;
    int newG = 0;
    int newB = 0;

    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    int pos = 0;
    for (int i = 1, length = height - 1; i < length; i++) {
        for (int k = 1, len = width - 1; k < len; k++) {
            pos = i * width + k;
            pixColor = pixels[pos];

            pixR = Color.red(pixColor);
            pixG = Color.green(pixColor);
            pixB = Color.blue(pixColor);

            newR = MAX_VALUE - pixR;
            newG = MAX_VALUE - pixG;
            newB = MAX_VALUE - pixB;

            newR = Math.min(MAX_VALUE, Math.max(0, newR));
            newG = Math.min(MAX_VALUE, Math.max(0, newG));
            newB = Math.min(MAX_VALUE, Math.max(0, newB));

            pixels[pos] = Color.argb(MAX_VALUE, newR, newG, newB);
        }
    }

    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}

From source file:onion.chat.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK)
        return;//from ww  w .  ja v  a2 s.  c o  m
    if (requestCode == REQUEST_QR) {
        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        int width = bitmap.getWidth(), height = bitmap.getHeight();
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
        bitmap.recycle();
        RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source));
        MultiFormatReader reader = new MultiFormatReader();
        try {
            Result result = reader.decode(bBitmap);
            String str = result.getText();
            Log.i("ID", str);

            String[] tokens = str.split(" ", 3);

            if (tokens.length < 2 || !tokens[0].equals("Its Ur's")) {
                snack(getString(R.string.qr_invalid));
                return;
            }

            String id = tokens[1].toLowerCase();

            if (id.length() != 16) {
                snack(getString(R.string.qr_invalid));
                return;
            }

            if (db.hasContact(id)) {
                snack(getString(R.string.contact_already_added));
                return;
            }

            String name = "";
            if (tokens.length > 2) {
                name = tokens[2];
            }

            addContact(id, name);

            return;

        } catch (Exception ex) {
            snack(getString(R.string.qr_invalid));
            ex.printStackTrace();
        }
    } else if (requestCode == VOICE_RECOGNITION_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            ArrayList<String> textMatchList = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            String[] textTyped = new String[textMatchList.size()];
            String typeText = "";
            for (int i = 0; i < textMatchList.size(); i++) {
                textTyped[i] = textMatchList.get(i);
                typeText += textTyped[i];
            }
            if (!textMatchList.isEmpty()) {

                if (textMatchList.get(0).contains("open") || textMatchList.get(0).contains("OPEN")) {
                    String contName = "";
                    if (typeText.contains("open chat")) {
                        if (textMatchList.size() >= 2) {
                            contName = textMatchList.get(2);
                        }
                        if (contName != "") {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("chat:" + contName),
                                    getApplicationContext(), ChatActivity.class));
                        }
                    }
                    listen();
                } else if (textMatchList.get(0).contains("password")
                        || textMatchList.get(0).contains("PASSWORD")) {
                    String password = "password";

                    if (textMatchList.size() >= 2) {

                        password = textMatchList.get(0).replaceFirst("password ", "");

                    } else if (textMatchList.size() >= 1) {

                        password = textMatchList.get(0).replaceFirst("password ", "");

                    }
                    db.setPassword(password);
                    update();
                    String toSpeak = "password changed successfully to " + password;
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    listen();

                } else if (textMatchList.get(0).contains("change") || textMatchList.get(0).contains("CHANGE")) {
                    String name = "";
                    if (textMatchList.size() >= 2) {
                        name = textMatchList.get(2);
                    }
                    db.setName(name);
                    update();
                    snack(getString(R.string.snack_alias_changed));
                    String toSpeak = "Alias changed to " + name;
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                } else if (textMatchList.get(0).contains("tell") || textMatchList.get(0).contains("tell")) {
                    String id1 = "";
                    id1 = (tor.getID());
                    Toast.makeText(getApplicationContext(), id1, Toast.LENGTH_SHORT).show();
                    //t1.speak(id1, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                } else if (textMatchList.get(0).contains("enter") || textMatchList.get(0).contains("ENTER")) {
                    String id1 = "Yet to come";
                    Toast.makeText(getApplicationContext(), id1, Toast.LENGTH_SHORT).show();
                    //t1.speak(id1, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                } else if (textMatchList.get(0).contains("HELP") || textMatchList.get(0).contains("help")) {
                    String toSpeak = "Voice Commands that can be used are 1 Open chat with contact name 2 change with alias name 3 tell";
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                }

                else if (textMatchList.get(0).contains("close") || textMatchList.get(0).contains("CLOSE")) {
                    String toSpeak = "Closing Voice command";
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                }

                else {
                    // poString
                    String toSpeak = "I Can't Understand";
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    // t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                }

            }
            //Result code for various error.
        } else if (resultCode == RecognizerIntent.RESULT_AUDIO_ERROR) {

            String toSpeak = "Audio Error";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        } else if (resultCode == RecognizerIntent.RESULT_CLIENT_ERROR) {

            String toSpeak = "Client Error";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        } else if (resultCode == RecognizerIntent.RESULT_NETWORK_ERROR) {

            String toSpeak = "Network Error";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        } else if (resultCode == RecognizerIntent.RESULT_NO_MATCH) {

            String toSpeak = "No Match";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        } else if (resultCode == RecognizerIntent.RESULT_SERVER_ERROR) {

            String toSpeak = "Server Error";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        }

    }

}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ?//from   w  ww  . j  a  va 2 s  .c  om
 * 
 * @param bitmap
 *            
 * @param centerX
 *            ?X?
 * @param centerY
 *            ?Y?
 * @return ??
 */
public static Bitmap sunshine(Bitmap bitmap, int centerX, int centerY) {
    final int width = bitmap.getWidth();
    final int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

    int pixR = 0;
    int pixG = 0;
    int pixB = 0;

    int pixColor = 0;

    int newR = 0;
    int newG = 0;
    int newB = 0;
    int radius = Math.min(centerX, centerY);

    final float strength = 150F; //  100~150
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    int pos = 0;
    for (int i = 1, length = height - 1; i < length; i++) {
        for (int k = 1, len = width - 1; k < len; k++) {
            pos = i * width + k;
            pixColor = pixels[pos];

            pixR = Color.red(pixColor);
            pixG = Color.green(pixColor);
            pixB = Color.blue(pixColor);

            newR = pixR;
            newG = pixG;
            newB = pixB;

            // ????
            int distance = (int) (Math.pow((centerY - i), 2) + Math.pow(centerX - k, 2));
            if (distance < radius * radius) {
                // ??
                int result = (int) (strength * (1.0 - Math.sqrt(distance) / radius));
                newR = pixR + result;
                newG = pixG + result;
                newB = pixB + result;
            }

            newR = Math.min(255, Math.max(0, newR));
            newG = Math.min(255, Math.max(0, newG));
            newB = Math.min(255, Math.max(0, newB));

            pixels[pos] = Color.argb(255, newR, newG, newB);
        }
    }

    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}

From source file:com.codegarden.nativenavigation.JuceActivity.java

public final int[] renderGlyph(char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) {
    Path p = new Path();
    paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p);

    RectF boundsF = new RectF();
    p.computeBounds(boundsF, true);/*from w  w w  .j  a  v a  2 s  .  c  om*/
    matrix.mapRect(boundsF);

    boundsF.roundOut(bounds);
    bounds.left--;
    bounds.right++;

    final int w = bounds.width();
    final int h = Math.max(1, bounds.height());

    Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(bm);
    matrix.postTranslate(-bounds.left, -bounds.top);
    c.setMatrix(matrix);
    c.drawPath(p, paint);

    final int sizeNeeded = w * h;
    if (cachedRenderArray.length < sizeNeeded)
        cachedRenderArray = new int[sizeNeeded];

    bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h);
    bm.recycle();
    return cachedRenderArray;
}