本文整理匯總了Java中android.graphics.Rect.width方法的典型用法代碼示例。如果您正苦於以下問題:Java Rect.width方法的具體用法?Java Rect.width怎麽用?Java Rect.width使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Rect
的用法示例。
在下文中一共展示了Rect.width方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calcColorDistance
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* Calc color distance between average color in rect
* and each pixel
*/
private int calcColorDistance(Rect rect) {
int averageColor = averageColor(rect);
int red = Color.red(averageColor);
int green = Color.green(averageColor);
int blue = Color.blue(averageColor);
int colorSum = 0;
// Calculates the distance
for (int i = rect.left; i < rect.right; i++) {
for (int j = rect.top; j < rect.bottom; j++) {
int cellColor = pixelsBitmap[i][j];
colorSum += Math.abs(red - Color.red(cellColor));
colorSum += Math.abs(green - Color.green(cellColor));
colorSum += Math.abs(blue - Color.blue(cellColor));
}
}
// Calculates distance, and returns the result.
return colorSum / (3 * (rect.width() * rect.height())); //divide by 3, because use R. G. B.
}
示例2: updateDragging
import android.graphics.Rect; //導入方法依賴的package包/類
private void updateDragging(MotionEvent ev) {
setHotspot(ev.getX(), ev.getY());
int x = (int) ev.getX();
Rect oldBounds = mThumb.getBounds();
int halfThumb = oldBounds.width() / 2;
int addedThumb = mAddedTouchBounds;
int newX = x - mDragOffset + halfThumb;
int left = getPaddingLeft() + halfThumb + addedThumb;
int right = getWidth() - (getPaddingRight() + halfThumb + addedThumb);
if (newX < left) {
newX = left;
} else if (newX > right) {
newX = right;
}
int available = right - left;
float scale = (float) (newX - left) / (float) available;
if (isRtl()) {
scale = 1f - scale;
}
int progress = Math.round((scale * (mMax - mMin)) + mMin);
setProgress(progress, true);
}
示例3: updateProgressFromAnimation
import android.graphics.Rect; //導入方法依賴的package包/類
private void updateProgressFromAnimation(float scale) {
Rect bounds = mThumb.getBounds();
int halfThumb = bounds.width() / 2;
int addedThumb = mAddedTouchBounds;
int left = getPaddingLeft() + halfThumb + addedThumb;
int right = getWidth() - (getPaddingRight() + halfThumb + addedThumb);
int available = right - left;
int progress = Math.round((scale * (mMax - mMin)) + mMin);
//we don't want to just call setProgress here to avoid the animation being cancelled,
//and this position is not bound to a real progress value but interpolated
if (progress != getProgress()) {
mValue = progress;
notifyProgress(mValue, true);
updateProgressMessage(progress);
}
final int thumbPos = (int) (scale * available + 0.5f);
updateThumbPos(thumbPos);
}
示例4: measureTextWidthHeight
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* 計算最大len的Text的寬高度
*/
private void measureTextWidthHeight() {
Rect rect = new Rect();
for (int i = 0; i < adapter.getItemsCount(); i++) {
String s1 = getContentText(adapter.getItem(i));
paintCenterText.getTextBounds(s1, 0, s1.length(), rect);
int textWidth = rect.width();
if (textWidth > maxTextWidth) {
maxTextWidth = textWidth;
}
paintCenterText.getTextBounds("\u661F\u671F", 0, 2, rect); // 星期
int textHeight = rect.height();
if (textHeight > maxTextHeight) {
maxTextHeight = textHeight;
}
}
itemHeight = lineSpacingMultiplier * maxTextHeight;
}
示例5: draw
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public void draw(@NonNull Canvas canvas) {
Rect bounds = getBounds();
int width = bounds.width();
int height = bounds.height();
if (mPaint.getAlpha() == 0xFF) {
canvas.save();
canvas.translate(bounds.left-mStartX, bounds.top-mStartY);
if (mPaths != null) {
for (int i = 0; i < mPaths.size(); i++) {
if (mColors != null && i < mColors.size()) {
mPaint.setColor(mColors.get(i));
}
canvas.drawPath(mPaths.get(i), mPaint);
}
mPaint.setAlpha(0xFF);
}
canvas.restore();
} else {
createCachedBitmapIfNeeded(width, height);
if (!canReuseCache()) {
updateCachedBitmap(width, height);
updateCacheStates();
}
canvas.drawBitmap(mCachedBitmap, bounds.left, bounds.top, mPaint);
}
}
示例6: buildLuminanceSource
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* A factory method to build the appropriate LuminanceSource object based on the format
* of the preview buffers, as described by Camera.Parameters.
*
* @param data A preview frame.
* @param width The width of the image.
* @param height The height of the image.
* @return A PlanarYUVLuminanceSource instance.
*/
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
Rect rect = getFramingRectInPreview();
if (rect == null) {
return null;
}
// Go ahead and assume it's YUV rather than die.
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
rect.width(), rect.height(), false);
}
示例7: buildLuminanceSource
import android.graphics.Rect; //導入方法依賴的package包/類
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
Rect rect = getFramingRectInPreview();
int previewFormat = this.configManager.getPreviewFormat();
String previewFormatString = this.configManager.getPreviewFormatString();
switch (previewFormat) {
case 16:
case 17:
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect.height());
default:
if ("yuv420p".equals(previewFormatString)) {
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect.height());
}
throw new IllegalArgumentException("Unsupported picture format: " + previewFormat + LetvUtils.CHARACTER_BACKSLASH + previewFormatString);
}
}
示例8: drawText
import android.graphics.Rect; //導入方法依賴的package包/類
private void drawText(Canvas canvas, String num, int i) {
Rect mTextBound = new Rect();
pswTextPaint.getTextBounds(num, 0, num.length(), mTextBound);
Paint.FontMetrics fontMetrics = pswTextPaint.getFontMetrics();
float textX = (float) ((i * (borderWidth + spacingWidth)) + (borderWidth / 2 - mTextBound.width() / 2) + (0.45 * spacingWidth));
float textY = (height - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
if (saveResult != 0 || saveResult < result.size()) {
canvas.drawText(num, textX, textY, pswTextPaint);
}
}
示例9: onBoundsChange
import android.graphics.Rect; //導入方法依賴的package包/類
/**
*/
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
this.mSize = bounds.width();
this.updateOval();
}
示例10: buildLuminanceSource
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* A factory method to build the appropriate LuminanceSource object based on
* the format of the preview buffers, as described by Camera.Parameters.
*
* @param data A preview frame.
* @param width The width of the image.
* @param height The height of the image.
* @return A PlanarYUVLuminanceSource instance.
*/
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
// 掃碼區域大小,可以調整掃碼區域大小
Rect rect = activity.getCropRect();
if (rect == null) {
return null;
}
// Go ahead and assume it's YUV rather than die.
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect
.height(), false);
}
示例11: onBoundsChange
import android.graphics.Rect; //導入方法依賴的package包/類
@Override protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
int height = bounds.height();
int width = bounds.width();
numRectanglesHorizontal = (int) Math.ceil((width / rectangleSize));
numRectanglesVertical = (int) Math.ceil(height / rectangleSize);
generatePatternBitmap();
}
示例12: drawBorder
import android.graphics.Rect; //導入方法依賴的package包/類
private void drawBorder(Canvas canvas) {
int[] headRect = new int[4];
int[] bodyRect = new int[4];
if(mHeadOrientation == HEAD_ORIENTATION_LEFT){
headRect[0] = 0;
headRect[1] = mHeight/4;
headRect[2] = HEAD_WIDTH;
headRect[3] = mHeight*3/4;
bodyRect[0] = HEAD_WIDTH;
bodyRect[1] = 0;
bodyRect[2] = mWidth;
bodyRect[3] = mHeight;
}else if(mHeadOrientation == HEAD_ORIENTATION_RIGHT){
headRect[0] = mWidth - HEAD_WIDTH;
headRect[1] = mHeight/4;
headRect[2] = mWidth;
headRect[3] = mHeight*3/4;
bodyRect[0] = 0;
bodyRect[1] = 0;
bodyRect[2] = mWidth - HEAD_WIDTH;
bodyRect[3] = mHeight;
}
mBorderPaint.setStyle(Paint.Style.FILL);
canvas.drawRect(new RectF(headRect[0],headRect[1],headRect[2],headRect[3]),mBorderPaint);
mBorderPaint.setStyle(Paint.Style.STROKE);
Rect rect = new Rect(bodyRect[0], bodyRect[1], bodyRect[2], bodyRect[3]);
mBodyWidth = rect.width();
canvas.drawRect(rect,mBorderPaint);
}
示例13: cropBitmap
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* Crop image bitmap from URI by decoding it with specific width and height to down-sample if required.
*
* @param orgWidth used to get rectangle from points (handle edge cases to limit rectangle)
* @param orgHeight used to get rectangle from points (handle edge cases to limit rectangle)
* @param sampleMulti used to increase the sampling of the image to handle memory issues.
*/
private static BitmapSampled cropBitmap(Context context, Uri loadedImageUri, float[] points, int degreesRotated,
int orgWidth, int orgHeight, boolean fixAspectRatio, int aspectRatioX, int aspectRatioY,
int reqWidth, int reqHeight, boolean flipHorizontally, boolean flipVertically, int sampleMulti) {
// get the rectangle in original image that contains the required cropped area (larger for non rectangular crop)
Rect rect = getRectFromPoints(points, orgWidth, orgHeight, fixAspectRatio, aspectRatioX, aspectRatioY);
int width = reqWidth > 0 ? reqWidth : rect.width();
int height = reqHeight > 0 ? reqHeight : rect.height();
Bitmap result = null;
int sampleSize = 1;
try {
// decode only the required image from URI, optionally sub-sampling if reqWidth/reqHeight is given.
BitmapSampled bitmapSampled = decodeSampledBitmapRegion(context, loadedImageUri, rect, width, height, sampleMulti);
result = bitmapSampled.bitmap;
sampleSize = bitmapSampled.sampleSize;
} catch (Exception ignored) {
}
if (result != null) {
try {
// rotate the decoded region by the required amount
result = rotateAndFlipBitmapInt(result, degreesRotated, flipHorizontally, flipVertically);
// rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping
if (degreesRotated % 90 != 0) {
// extra crop because non rectangular crop cannot be done directly on the image without rotating first
result = cropForRotatedImage(result, points, rect, degreesRotated, fixAspectRatio, aspectRatioX, aspectRatioY);
}
} catch (OutOfMemoryError e) {
if (result != null) {
result.recycle();
}
throw e;
}
return new BitmapSampled(result, sampleSize);
} else {
// failed to decode region, may be skia issue, try full decode and then crop
return cropBitmap(context, loadedImageUri, points, degreesRotated, fixAspectRatio, aspectRatioX, aspectRatioY, sampleMulti,
rect, width, height, flipHorizontally, flipVertically);
}
}
示例14: getTextRect
import android.graphics.Rect; //導入方法依賴的package包/類
public void getTextRect(Context context, float scale, Rect outRect) {
Paint textPaint = getPaint(context, scale, false);
Paint outlineTextPaint = getPaint(context, scale, true);
Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
String[] text = preprocessText();
float fullheight = 0, fullwidth = 0;
float[] heightArray = new float[text.length];
float[] widthArray = new float[text.length];
for (int i = 0; i < text.length; i++) {
Rect bounds = new Rect();
if (outlineTextPaint != null) {
outlineTextPaint.getTextBounds(text[i], 0, text[i].length(), bounds);
} else {
textPaint.getTextBounds(text[i], 0, text[i].length(), bounds);
}
widthArray[i] = bounds.width();
heightArray[i] = fontMetrics.bottom - fontMetrics.top;
if (i < text.length - 1) {
heightArray[i] = heightArray[i] + (int) (heightArray[i] * (lineSpacing - 1));
}
fullheight += heightArray[i];
fullwidth = fullwidth < widthArray[i] ? widthArray[i] : fullwidth;
}
fullwidth = fullwidth * 1.2f;
fullheight = fullheight * 1.2f;
float fullWidthDP = fullwidth / context.getResources().getDisplayMetrics().density;
float fullHeightDP = fullheight / context.getResources().getDisplayMetrics().density;
widthTextRatio = fullWidthDP / (textSize * scale);
heightTextRatio = fullHeightDP / (textSize * scale);
outRect.set(0, 0, (int) fullwidth, (int) fullheight);
}
示例15: configureBounds
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* Determines bounds for the underlying drawable and a matrix that should be applied on it.
* Adopted from android.widget.ImageView
*/
@VisibleForTesting void configureBounds() {
Drawable underlyingDrawable = getCurrent();
Rect bounds = getBounds();
int viewWidth = bounds.width();
int viewHeight = bounds.height();
int underlyingWidth = mUnderlyingWidth = underlyingDrawable.getIntrinsicWidth();
int underlyingHeight = mUnderlyingHeight = underlyingDrawable.getIntrinsicHeight();
// If the drawable has no intrinsic size, we just fill our entire view.
if (underlyingWidth <= 0 || underlyingHeight <= 0) {
underlyingDrawable.setBounds(bounds);
mDrawMatrix = null;
return;
}
// If the drawable fits exactly, no transform needed.
if (underlyingWidth == viewWidth && underlyingHeight == viewHeight) {
underlyingDrawable.setBounds(bounds);
mDrawMatrix = null;
return;
}
// If we're told to scale to fit, we just fill our entire view.
// (ScaleType.getTransform would do, but this is faster)
if (mScaleType == ScaleType.FIT_XY) {
underlyingDrawable.setBounds(bounds);
mDrawMatrix = null;
return;
}
// We need to do the scaling ourselves, so have the underlying drawable use its preferred size.
underlyingDrawable.setBounds(0, 0, underlyingWidth, underlyingHeight);
mScaleType.getTransform(
mTempMatrix,
bounds,
underlyingWidth,
underlyingHeight,
(mFocusPoint != null) ? mFocusPoint.x : 0.5f,
(mFocusPoint != null) ? mFocusPoint.y : 0.5f);
mDrawMatrix = mTempMatrix;
}