use of android.graphics.Matrix in project Signal-Android by WhisperSystems.
the class CanvasView method render.
public void render(Canvas canvas) {
if (this.canvas == null)
return;
float scaleX = 1.0F * canvas.getWidth() / this.canvas.getWidth();
float scaleY = 1.0F * canvas.getHeight() / this.canvas.getHeight();
Matrix matrix = new Matrix();
matrix.setScale(scaleX, scaleY);
for (int i = 0; i < this.historyPointer; i++) {
Path path = this.pathLists.get(i);
Paint paint = this.paintLists.get(i);
Path scaledPath = new Path();
path.transform(matrix, scaledPath);
Paint scaledPaint = new Paint(paint);
scaledPaint.setStrokeWidth(scaledPaint.getStrokeWidth() * scaleX);
canvas.drawPath(scaledPath, scaledPaint);
}
}
use of android.graphics.Matrix in project actor-platform by actorapp.
the class ImageHelper method fixExif.
private static Bitmap fixExif(Bitmap src, int exifOrientation) {
try {
final Matrix bitmapMatrix = new Matrix();
switch(exifOrientation) {
case 1:
// top left
break;
case 2:
bitmapMatrix.postScale(-1, 1);
// top right
break;
case 3:
bitmapMatrix.postRotate(180);
// bottom right
break;
case 4:
bitmapMatrix.postRotate(180);
bitmapMatrix.postScale(-1, 1);
// bottom left
break;
case 5:
bitmapMatrix.postRotate(90);
bitmapMatrix.postScale(-1, 1);
// left top
break;
case 6:
bitmapMatrix.postRotate(90);
// right top
break;
case 7:
bitmapMatrix.postRotate(270);
bitmapMatrix.postScale(-1, 1);
// right bottom
break;
case 8:
bitmapMatrix.postRotate(270);
// left bottom
break;
default:
// Unknown
break;
}
// Create new bitmap.
return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), bitmapMatrix, false);
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
use of android.graphics.Matrix in project TouchImageView by MikeOrtiz.
the class TouchImageView method sharedConstructing.
private void sharedConstructing(Context context) {
super.setClickable(true);
this.context = context;
mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
mGestureDetector = new GestureDetector(context, new GestureListener());
matrix = new Matrix();
prevMatrix = new Matrix();
m = new float[9];
normalizedScale = 1;
if (mScaleType == null) {
mScaleType = ScaleType.FIT_CENTER;
}
minScale = 1;
maxScale = 3;
superMinScale = SUPER_MIN_MULTIPLIER * minScale;
superMaxScale = SUPER_MAX_MULTIPLIER * maxScale;
setImageMatrix(matrix);
setScaleType(ScaleType.MATRIX);
setState(State.NONE);
onDrawReady = false;
super.setOnTouchListener(new PrivateOnTouchListener());
}
use of android.graphics.Matrix in project Carbon by ZieIony.
the class CheckableDrawable method renderSVGs.
private void renderSVGs() {
Rect bounds = getBounds();
if (bounds.width() <= 0 && bounds.height() <= 0)
return;
try {
{
SVG svg = SVG.getFromResource(context, checkedRes);
checkedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(checkedBitmap);
svg.setDocumentWidth(checkedBitmap.getWidth());
svg.setDocumentHeight(checkedBitmap.getHeight());
svg.renderToCanvas(canvas);
checkedShader = new BitmapShader(checkedBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Matrix matrix = new Matrix();
matrix.postTranslate(bounds.left, bounds.top);
checkedShader.setLocalMatrix(matrix);
}
{
SVG svg2 = SVG.getFromResource(context, uncheckedRes);
uncheckedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(uncheckedBitmap);
svg2.setDocumentWidth(uncheckedBitmap.getWidth());
svg2.setDocumentHeight(uncheckedBitmap.getHeight());
svg2.renderToCanvas(canvas);
}
{
SVG svg3 = SVG.getFromResource(context, filledRes);
filledBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(filledBitmap);
svg3.setDocumentWidth(filledBitmap.getWidth());
svg3.setDocumentHeight(filledBitmap.getHeight());
svg3.renderToCanvas(canvas);
}
maskBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
maskCanvas = new Canvas(maskBitmap);
radius = (float) (Math.sqrt(2) * bounds.width() / 2);
} catch (SVGParseException e) {
Log.e(CheckableDrawable.class.getSimpleName(), "There was an error parsing SVG");
} catch (NullPointerException e) {
// TODO: what is this catch for?
}
}
use of android.graphics.Matrix in project WoWoViewPager by Nightonke.
the class WoWoPathView method getResizedBitmap.
private Bitmap getResizedBitmap(Bitmap bm, float newWidth, float newHeight) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = 1, scaleHeight = 1;
if (newWidth != -1) {
scaleWidth = newWidth / width;
if (newHeight != -1) {
scaleHeight = newHeight / height;
} else {
scaleHeight = scaleWidth;
}
} else {
if (newHeight != -1) {
scaleWidth = scaleHeight = newHeight / height;
}
}
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
bm.recycle();
return resizedBitmap;
}
Aggregations