List of usage examples for android.graphics Canvas setMatrix
public void setMatrix(@Nullable Matrix matrix)
From source file:com.juce.JuceAppActivity.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);/* w w w . j av a 2 s .com*/ 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; }
From source file:org.egov.android.view.activity.CreateComplaintActivity.java
public String compressImage(String fromfilepath, String tofilepath) { Bitmap scaledBitmap = null;// www.j a va2s . c om BitmapFactory.Options options = new BitmapFactory.Options(); // by setting this field as true, the actual bitmap pixels are not loaded in the memory. Just the bounds are loaded. If // you try the use the bitmap here, you will get null. options.inJustDecodeBounds = true; Bitmap bmp = BitmapFactory.decodeFile(fromfilepath, options); int actualHeight = options.outHeight; int actualWidth = options.outWidth; // max Height and width values of the compressed image is taken as 816x612 float maxHeight = 816.0f; float maxWidth = 612.0f; float imgRatio = actualWidth / actualHeight; float maxRatio = maxWidth / maxHeight; // width and height values are set maintaining the aspect ratio of the image if (actualHeight > maxHeight || actualWidth > maxWidth) { if (imgRatio < maxRatio) { imgRatio = maxHeight / actualHeight; actualWidth = (int) (imgRatio * actualWidth); actualHeight = (int) maxHeight; } else if (imgRatio > maxRatio) { imgRatio = maxWidth / actualWidth; actualHeight = (int) (imgRatio * actualHeight); actualWidth = (int) maxWidth; } else { actualHeight = (int) maxHeight; actualWidth = (int) maxWidth; } } // setting inSampleSize value allows to load a scaled down version of the original image options.inSampleSize = calculateInSampleSize(options, actualWidth, actualHeight); // inJustDecodeBounds set to false to load the actual bitmap options.inJustDecodeBounds = false; // this options allow android to claim the bitmap memory if it runs low on memory options.inPurgeable = true; options.inInputShareable = true; options.inTempStorage = new byte[16 * 1024]; try { // load the bitmap from its path bmp = BitmapFactory.decodeFile(tofilepath, options); } catch (OutOfMemoryError exception) { exception.printStackTrace(); } try { scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.ARGB_8888); } catch (OutOfMemoryError exception) { exception.printStackTrace(); } float ratioX = actualWidth / (float) options.outWidth; float ratioY = actualHeight / (float) options.outHeight; float middleX = actualWidth / 2.0f; float middleY = actualHeight / 2.0f; Matrix scaleMatrix = new Matrix(); scaleMatrix.setScale(ratioX, ratioY, middleX, middleY); Canvas canvas = new Canvas(scaledBitmap); canvas.setMatrix(scaleMatrix); canvas.drawBitmap(bmp, middleX - bmp.getWidth() / 2, middleY - bmp.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG)); String attrLatitute = null; String attrLatituteRef = null; String attrLONGITUDE = null; String attrLONGITUDEREf = null; // check the rotation of the image and display it properly ExifInterface exif; try { exif = new ExifInterface(fromfilepath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); Log.d("EXIF", "Exif: " + orientation); Matrix matrix = new Matrix(); if (orientation == 6) { matrix.postRotate(90); Log.d("EXIF", "Exif: " + orientation); } else if (orientation == 3) { matrix.postRotate(180); Log.d("EXIF", "Exif: " + orientation); } else if (orientation == 8) { matrix.postRotate(270); Log.d("EXIF", "Exif: " + orientation); } attrLatitute = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); attrLatituteRef = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF); attrLONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); attrLONGITUDEREf = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF); scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true); } catch (IOException e) { e.printStackTrace(); } FileOutputStream out = null; try { out = new FileOutputStream(tofilepath); // write the compressed bitmap at the destination specified by filename. scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, out); ExifInterface exif2 = new ExifInterface(tofilepath); if (attrLatitute != null) { exif2.setAttribute(ExifInterface.TAG_GPS_LATITUDE, attrLatitute); exif2.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, attrLONGITUDE); } if (attrLatituteRef != null) { exif2.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, attrLatituteRef); exif2.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, attrLONGITUDEREf); } exif2.saveAttributes(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return tofilepath; }
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
private void drawWedge(Canvas canvas, float center, int i, RadialMenu menu, float degrees) { final float offset = mSubMenu != null ? mSubMenuOffset : mRootMenuOffset; final RadialMenuItem wedge = menu.getItem(i); final String title = wedge.getTitle().toString(); final float rotation = ((degrees * i) + offset); final boolean selected = wedge.equals(mFocusedItem); // Apply the appropriate color filters. if (wedge.hasSubMenu()) { mPaint.setColorFilter(mSubMenuFilter); } else {//from www. j ava2s. co m mPaint.setColorFilter(null); } wedge.offset = rotation; mTempMatrix.reset(); mTempMatrix.setRotate(rotation, center, center); mTempMatrix.postTranslate((mCenter.x - center), (mCenter.y - center)); canvas.setMatrix(mTempMatrix); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionColor : mOuterFillColor); mPaint.setShadowLayer(mShadowRadius, 0, 0, (selected ? mSelectionShadowColor : mTextShadowColor)); canvas.drawPath(mCachedOuterPath, mPaint); mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionTextFillColor : mTextFillColor); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(mTextSize); mPaint.setShadowLayer(mTextShadowRadius, 0, 0, mTextShadowColor); final String renderText = getEllipsizedText(mPaint, title, mCachedOuterPathWidth); // Orient text differently depending on the angle. if ((rotation < 90) || (rotation > 270)) { canvas.drawTextOnPath(renderText, mCachedOuterPathReverse, 0, (2 * mTextSize), mPaint); } else { canvas.drawTextOnPath(renderText, mCachedOuterPath, 0, -mTextSize, mPaint); } mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setColorFilter(null); }
From source file:com.googlecode.eyesfree.widget.RadialMenuView.java
private void drawWedge(Canvas canvas, int width, int height, float center, int i, RadialMenu menu, float degrees) { final float offset = mSubMenu != null ? mSubMenuOffset : mRootMenuOffset; final RadialMenuItem wedge = menu.getItem(i); final String title = wedge.getTitle().toString(); final float rotation = ((degrees * i) + offset); final boolean selected = wedge.equals(mFocusedItem); // Apply the appropriate color filters. if (wedge.hasSubMenu()) { mPaint.setColorFilter(mSubMenuFilter); } else {//from w w w . ja v a 2 s .co m mPaint.setColorFilter(null); } wedge.offset = rotation; mTempMatrix.reset(); mTempMatrix.setRotate(rotation, center, center); mTempMatrix.postTranslate((mCenter.x - center), (mCenter.y - center)); canvas.setMatrix(mTempMatrix); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionColor : mOuterFillColor); mPaint.setShadowLayer(mShadowRadius, 0, 0, (selected ? mSelectionShadowColor : mTextShadowColor)); canvas.drawPath(mCachedOuterPath, mPaint); mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionTextFillColor : mTextFillColor); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(mTextSize); mPaint.setShadowLayer(mTextShadowRadius, 0, 0, mTextShadowColor); final String renderText = getEllipsizedText(mPaint, title, mCachedOuterPathWidth); // Orient text differently depending on the angle. if ((rotation < 90) || (rotation > 270)) { canvas.drawTextOnPath(renderText, mCachedOuterPathReverse, 0, (2 * mTextSize), mPaint); } else { canvas.drawTextOnPath(renderText, mCachedOuterPath, 0, -mTextSize, mPaint); } mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setColorFilter(null); }
From source file:com.googlecode.eyesfree.widget.RadialMenuView.java
private void drawCorner(Canvas canvas, int width, int height, float center, int i) { final RadialMenuItem wedge = mRootMenu.getCorner(i); if (wedge == null) { return;/*ww w .ja v a 2 s . c om*/ } final float rotation = RadialMenu.getCornerRotation(i); final PointF cornerLocation = RadialMenu.getCornerLocation(i); final float cornerX = (cornerLocation.x * width); final float cornerY = (cornerLocation.y * height); final String title = wedge.getTitle().toString(); final boolean selected = wedge.equals(mFocusedItem); // Apply the appropriate color filters. if (wedge.hasSubMenu()) { mPaint.setColorFilter(mSubMenuFilter); } else { mPaint.setColorFilter(null); } wedge.offset = rotation; mTempMatrix.reset(); mTempMatrix.setRotate(rotation, center, center); mTempMatrix.postTranslate((cornerX - center), (cornerY - center)); canvas.setMatrix(mTempMatrix); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionColor : mCornerFillColor); mPaint.setShadowLayer(mShadowRadius, 0, 0, (selected ? mSelectionShadowColor : mTextShadowColor)); canvas.drawPath(mCachedCornerPath, mPaint); mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionTextFillColor : mCornerTextFillColor); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(mTextSize); mPaint.setShadowLayer(mTextShadowRadius, 0, 0, mTextShadowColor); final String renderText = getEllipsizedText(mPaint, title, mCachedCornerPathWidth); // Orient text differently depending on the angle. if (((rotation < 90) && (rotation > -90)) || (rotation > 270)) { canvas.drawTextOnPath(renderText, mCachedCornerPathReverse, 0, (2 * mTextSize), mPaint); } else { canvas.drawTextOnPath(renderText, mCachedCornerPath, 0, -mTextSize, mPaint); } mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setColorFilter(null); }
From source file:de.tlabs.ssr.g1.client.SourcesView.java
@Override public void onDraw(Canvas canvas) { // zooming animation if (scalingInterpolator.isActive()) { setCurrentScaling(scalingInterpolator.getCurrentValue()); }//from w w w. ja v a 2 s .c o m // translation animation if (translationXInterpolator.isActive() || translationYInterpolator.isActive()) { float transX = currentTranslation[0]; float transY = currentTranslation[1]; if (translationXInterpolator.isActive()) { transX = translationXInterpolator.getCurrentValue(); } if (translationYInterpolator.isActive()) { transY = translationYInterpolator.getCurrentValue(); } setCurrentTranslation(transX, transY); } // center rotation animation if (centerRotationInterpolator.isActive()) { setCurrentCenterRotation(centerRotationInterpolator.getCurrentValue()); } // calculate current viewport matrix if necessary if (getAndClearViewportFlag()) { recalculateViewportTransformation(); recalculateSizeScale(); } // clear background canvas.drawColor(0xFF000000); // draw audio scene canvas.setMatrix(viewportTransformation); synchronized (GlobalData.audioScene) { GlobalData.audioScene.draw(canvas, currentInverseScaling); } // reset matrix canvas.setMatrix(null); // draw size scale sizeScalePicture.draw(canvas); }
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
private void drawCorner(Canvas canvas, int width, int height, float center, int i) { final RadialMenuItem wedge = mRootMenu.getCorner(i); if (wedge == null) { return;/*from w ww.j a va 2s.c o m*/ } final float rotation = RadialMenu.getCornerRotation(i); final PointF cornerLocation = RadialMenu.getCornerLocation(i); if (cornerLocation == null) return; final float cornerX = (cornerLocation.x * width); final float cornerY = (cornerLocation.y * height); final String title = wedge.getTitle().toString(); final boolean selected = wedge.equals(mFocusedItem); // Apply the appropriate color filters. if (wedge.hasSubMenu()) { mPaint.setColorFilter(mSubMenuFilter); } else { mPaint.setColorFilter(null); } wedge.offset = rotation; mTempMatrix.reset(); mTempMatrix.setRotate(rotation, center, center); mTempMatrix.postTranslate((cornerX - center), (cornerY - center)); canvas.setMatrix(mTempMatrix); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionColor : mCornerFillColor); mPaint.setShadowLayer(mShadowRadius, 0, 0, (selected ? mSelectionShadowColor : mTextShadowColor)); canvas.drawPath(mCachedCornerPath, mPaint); mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionTextFillColor : mCornerTextFillColor); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(mTextSize); mPaint.setShadowLayer(mTextShadowRadius, 0, 0, mTextShadowColor); final String renderText = getEllipsizedText(mPaint, title, mCachedCornerPathWidth); // Orient text differently depending on the angle. if (((rotation < 90) && (rotation > -90)) || (rotation > 270)) { canvas.drawTextOnPath(renderText, mCachedCornerPathReverse, 0, (2 * mTextSize), mPaint); } else { canvas.drawTextOnPath(renderText, mCachedCornerPath, 0, -mTextSize, mPaint); } mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setColorFilter(null); }
From source file:com.android.talkback.contextmenu.RadialMenuView.java
private void drawCorner(Canvas canvas, int width, int height, float center, int i) { final RadialMenuItem wedge = mRootMenu.getCorner(i); if (wedge == null || !wedge.isVisible()) { return;/*w w w. j a v a 2s. co m*/ } final float rotation = RadialMenu.getCornerRotation(i); final PointF cornerLocation = RadialMenu.getCornerLocation(i); if (cornerLocation == null) return; final float cornerX = (cornerLocation.x * width); final float cornerY = (cornerLocation.y * height); final String title = wedge.getTitle().toString(); final boolean selected = wedge.equals(mFocusedItem); // Apply the appropriate color filters. if (wedge.hasSubMenu()) { mPaint.setColorFilter(mSubMenuFilter); } else { mPaint.setColorFilter(null); } wedge.offset = rotation; mTempMatrix.reset(); mTempMatrix.setRotate(rotation, center, center); mTempMatrix.postTranslate((cornerX - center), (cornerY - center)); canvas.setMatrix(mTempMatrix); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionColor : mCornerFillColor); mPaint.setShadowLayer(mShadowRadius, 0, 0, (selected ? mSelectionShadowColor : mTextShadowColor)); canvas.drawPath(mCachedCornerPath, mPaint); mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setStyle(Style.FILL); mPaint.setColor(selected ? mSelectionTextFillColor : mCornerTextFillColor); mPaint.setTextAlign(Align.CENTER); mPaint.setTextSize(mTextSize); mPaint.setShadowLayer(mTextShadowRadius, 0, 0, mTextShadowColor); final String renderText = getEllipsizedText(mPaint, title, mCachedCornerPathWidth); // Orient text differently depending on the angle. if (((rotation < 90) && (rotation > -90)) || (rotation > 270)) { canvas.drawTextOnPath(renderText, mCachedCornerPathReverse, 0, (2 * mTextSize), mPaint); } else { canvas.drawTextOnPath(renderText, mCachedCornerPath, 0, -mTextSize, mPaint); } mPaint.setShadowLayer(0, 0, 0, 0); mPaint.setColorFilter(null); }
From source file:com.pdftron.pdf.tools.Tool.java
public void onDraw(Canvas canvas, android.graphics.Matrix tfm) { // Draw page number if (mShowPageNum && mPageNumberIndicatorVisible) { int width = mPDFView.getWidth(); int height = mPDFView.getHeight(); int page_num = mPDFView.getCurrentPage(); boolean restore = false; float yOffset = 0; try {/*from w w w . j ava 2 s . co m*/ // During page sliding, PDFViewCtrl might apply extra transformation // matrix to Canvas for animation. However, page number should not // move; hence applying the inverse to offset it. if (!tfm.isIdentity()) { canvas.save(); restore = true; tfm.invert(mTempMtx1); canvas.getMatrix(mTempMtx2); mTempMtx2.postConcat(mTempMtx1); canvas.setMatrix(mTempMtx2); // Workaround for bug found in Android > ICS with hardware acceleration turned // ON. See http://code.google.com/p/android/issues/detail?id=24517 for more info if (Build.VERSION.SDK_INT >= 14 /*Build.VERSION_CODES.ICE_CREAM_SANDWICH*/ && mPDFView.isHardwareAccelerated()) { Rect rectangle = new Rect(); ((android.app.Activity) mPDFView.getContext()).getWindow().getDecorView() .getWindowVisibleDisplayFrame(rectangle); yOffset = rectangle.top; } } int page_count = mPDFView.getDoc().getPageCount(); String str = String.format(getStringFromResId(R.string.tools_misc_pagerange), page_num, page_count); Rect r = new Rect(); mPaint4PageNum.getTextBounds(str, 0, str.length(), r); float str_width = r.width(); float str_height = r.height(); float margin = str_height / 1.5f; float left = width - str_width * 1.5f - margin + mPDFView.getScrollX(); float top = mPDFView.getScrollY() + height - mPageNumPosAdjust - str_height * 3.0f + yOffset; float right = left + str_width + margin * 2; float bottom = top + str_height + margin * 2; mTempPageDrawingRectF.set(left, top, right, bottom); mPaint4PageNum.setColor( mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_background)); canvas.drawRoundRect(mTempPageDrawingRectF, margin, margin, mPaint4PageNum); mPaint4PageNum .setColor(mPDFView.getContext().getResources().getColor(R.color.tools_pageindicator_text)); left += margin; top += str_height / 2 + margin + mPaint4PageNum.descent(); canvas.drawText(str, left, top - 0.5f, mPaint4PageNum); } catch (Exception e) { } finally { if (restore) { canvas.restore(); } } } }