Example usage for android.graphics Matrix setScale

List of usage examples for android.graphics Matrix setScale

Introduction

In this page you can find the example usage for android.graphics Matrix setScale.

Prototype

public void setScale(float sx, float sy) 

Source Link

Document

Set the matrix to scale by sx and sy.

Usage

From source file:Main.java

public static void prepareMatrix(Matrix matrix, boolean mirror, int displayOrientation, int viewWidth,
        int viewHeight) {
    matrix.setScale((float) (mirror ? -1 : 1), 1.0F);
    matrix.postRotate((float) displayOrientation);
    matrix.postScale((float) viewWidth / 2000.0F, (float) viewHeight / 2000.0F);
    matrix.postTranslate((float) viewWidth / 2.0F, (float) viewHeight / 2.0F);
}

From source file:Main.java

private static Matrix createTransform(Matrix transform, float scaleX, float scaleY, float translateX,
        float translateY) {
    transform.setScale(scaleX, scaleY);
    transform.postTranslate(translateX, translateY);
    return transform;
}

From source file:Main.java

public static int loadTexture(Resources resources, int resource, int internalFormat, boolean flip) {
    int[] textures = s_LOAD_TEXTURE_ID.get();
    if (textures == null) {
        textures = new int[1];
        s_LOAD_TEXTURE_ID.set(textures);
    }//from w w w.j a  v a  2s .c o  m

    glActiveTexture(GL_TEXTURE0);
    glGenTextures(1, textures, 0);

    int texture = textures[0];
    glBindTexture(GL_TEXTURE_2D, texture);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    Bitmap bitmap = BitmapFactory.decodeResource(resources, resource);

    final int width = bitmap.getWidth();
    final int height = bitmap.getHeight();

    if (flip) {
        Matrix matrix = new Matrix();
        matrix.setScale(1, -1);
        matrix.postTranslate(0, height);
        Bitmap flipBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);

        bitmap.recycle();
        bitmap = flipBitmap;
    }

    GLUtils.texImage2D(GL_TEXTURE_2D, 0, internalFormat, bitmap, GL_UNSIGNED_BYTE, 0);

    bitmap.recycle();

    glBindTexture(GL_TEXTURE_2D, 0);

    return texture;
}

From source file:Main.java

public static Bitmap extractThumbnail(Bitmap source, int width, int height, int options) {
    if (source == null)
        return null;

    float scale;//from   w w w  .  java2 s .c om
    if (source.getWidth() < source.getHeight())
        scale = width / (float) source.getWidth();
    else
        scale = height / (float) source.getHeight();
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    Bitmap thumbnail = transform(matrix, source, width, height, OPTIONS_SCALE_UP | options);
    return thumbnail;
}

From source file:Main.java

public static void prepareJpgMatrix(Matrix matrix, boolean mirror, int displayOrientation, int viewWidth,
        int viewHeight) {
    // Need mirror for front camera.
    matrix.setScale(mirror ? -1 : 1, 1);
    // This is the value for android.hardware.Camera.setDisplayOrientation.
    matrix.postRotate(displayOrientation);
    matrix.postTranslate(viewWidth / 2f, viewHeight / 2f);
}

From source file:Main.java

public static Bitmap extractThumbnail(Bitmap source, int width, int height, int options) {
    if (source == null) {
        return null;
    }/* w  ww.  j a v  a 2 s  .  c om*/

    float scale;
    if (source.getWidth() < source.getHeight()) {
        scale = width / (float) source.getWidth();
    } else {
        scale = height / (float) source.getHeight();
    }
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    Bitmap thumbnail = transform(matrix, source, width, height, OPTIONS_SCALE_UP | options);
    return thumbnail;
}

From source file:Main.java

/** create a coordination convert matrix
 * <br>//  w  ww . jav a 2 s. c o  m
 * See also {@link android.hardware.Camera.Face#rect}
 * */
private static Matrix createConvertMatrix(boolean frontCamera, float displayOrientation, float viewWidth,
        float viewHeight) {
    Matrix matrix = new Matrix();
    // Need mirror for front camera.
    boolean mirror = frontCamera;
    matrix.setScale(mirror ? -1 : 1, 1);
    // This is the value for android.hardware.Camera.setDisplayOrientation.
    matrix.postRotate(displayOrientation);
    // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
    // UI coordinates range from (0, 0) to (width, height).
    matrix.postScale(viewWidth / 2000f, viewHeight / 2000f);
    matrix.postTranslate(viewWidth / 2f, viewHeight / 2f);
    return matrix;
}

From source file:Main.java

/**
 * Creates a centered bitmap of the desired size.
 *
 * @param source original bitmap source/*from   w  w  w  . j a  va  2  s  .com*/
 * @param width targeted width
 * @param height targeted height
 * @param options options used during thumbnail extraction
 */
public static Bitmap crop(Bitmap source, int width, int height, int options) {
    if (source == null) {
        return null;
    }

    float scale;
    if (source.getWidth() < source.getHeight()) {
        scale = width / (float) source.getWidth();
    } else {
        scale = height / (float) source.getHeight();
    }
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    Bitmap thumbnail = transform(matrix, source, width, height, OPTIONS_SCALE_UP | options);
    return thumbnail;
}

From source file:Main.java

public static void prepareMatrix(Matrix matrix, boolean mirror, int displayOrientation, int viewWidth,
        int viewHeight) {
    // Need mirror for front camera.
    matrix.setScale(mirror ? -1 : 1, 1);
    // This is the value for android.hardware.Camera.setDisplayOrientation.
    matrix.postRotate(displayOrientation);
    // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
    // UI coordinates range from (0, 0) to (width, height).
    matrix.postScale(viewWidth / 2000f, viewHeight / 2000f);
    matrix.postTranslate(viewWidth / 2f, viewHeight / 2f);
}

From source file:Main.java

/**
 * A copy of the Android internals StoreThumbnail method, it used with the insertImage to
 * populate the android.provider.MediaStore.Images.Media#insertImage with all the correct
 * meta data. The StoreThumbnail method is private so it must be duplicated here.
 * @see android.provider.MediaStore.Images.Media (StoreThumbnail private method)
 *///from  w  ww .j  a v a  2 s.c om
private static final Bitmap storeThumbnail(ContentResolver cr, Bitmap source, long id, float width,
        float height, int kind) {

    // create the matrix to scale it
    Matrix matrix = new Matrix();

    float scaleX = width / source.getWidth();
    float scaleY = height / source.getHeight();

    matrix.setScale(scaleX, scaleY);

    Bitmap thumb = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);

    ContentValues values = new ContentValues(4);
    values.put(MediaStore.Images.Thumbnails.KIND, kind);
    values.put(MediaStore.Images.Thumbnails.IMAGE_ID, (int) id);
    values.put(MediaStore.Images.Thumbnails.HEIGHT, thumb.getHeight());
    values.put(MediaStore.Images.Thumbnails.WIDTH, thumb.getWidth());

    Uri url = cr.insert(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, values);

    try {
        OutputStream thumbOut = cr.openOutputStream(url);
        thumb.compress(Bitmap.CompressFormat.JPEG, 100, thumbOut);
        thumbOut.close();
        return thumb;
    } catch (FileNotFoundException ex) {
        return null;
    } catch (IOException ex) {
        return null;
    }
}