Java源码示例:com.edmodo.cropper.cropwindow.edge.Edge
示例1
/**
* Updates the crop window by directly setting the Edge coordinates.
*
* @param x the new x-coordinate of this handle
* @param y the new y-coordinate of this handle
* @param imageRect the bounding rectangle of the image
* @param parentView the parent View containing the image
* @param snapRadius the maximum distance (in pixels) at which the crop
* window should snap to the image
*/
void updateCropWindow(float x,
float y,
Rect imageRect,
float snapRadius) {
final EdgePair activeEdges = getActiveEdges();
final Edge primaryEdge = activeEdges.primary;
final Edge secondaryEdge = activeEdges.secondary;
if (primaryEdge != null)
primaryEdge.adjustCoordinate(x, y, imageRect, snapRadius, UNFIXED_ASPECT_RATIO_CONSTANT);
if (secondaryEdge != null)
secondaryEdge.adjustCoordinate(x, y, imageRect, snapRadius, UNFIXED_ASPECT_RATIO_CONSTANT);
}
示例2
@Override
void updateCropWindow(float x,
float y,
float targetAspectRatio,
Rect imageRect,
float snapRadius) {
final EdgePair activeEdges = getActiveEdges(x, y, targetAspectRatio);
final Edge primaryEdge = activeEdges.primary;
final Edge secondaryEdge = activeEdges.secondary;
primaryEdge.adjustCoordinate(x, y, imageRect, snapRadius, targetAspectRatio);
secondaryEdge.adjustCoordinate(targetAspectRatio);
if (secondaryEdge.isOutsideMargin(imageRect, snapRadius)) {
secondaryEdge.snapToRect(imageRect);
primaryEdge.adjustCoordinate(targetAspectRatio);
}
}
示例3
private void drawRuleOfThirdsGuidelines(Canvas canvas) {
final float left = Edge.LEFT.getCoordinate();
final float top = Edge.TOP.getCoordinate();
final float right = Edge.RIGHT.getCoordinate();
final float bottom = Edge.BOTTOM.getCoordinate();
// Draw vertical guidelines.
final float oneThirdCropWidth = Edge.getWidth() / 3;
final float x1 = left + oneThirdCropWidth;
canvas.drawLine(x1, top, x1, bottom, mGuidelinePaint);
final float x2 = right - oneThirdCropWidth;
canvas.drawLine(x2, top, x2, bottom, mGuidelinePaint);
// Draw horizontal guidelines.
final float oneThirdCropHeight = Edge.getHeight() / 3;
final float y1 = top + oneThirdCropHeight;
canvas.drawLine(left, y1, right, y1, mGuidelinePaint);
final float y2 = bottom - oneThirdCropHeight;
canvas.drawLine(left, y2, right, y2, mGuidelinePaint);
}
示例4
/**
* Handles a {@link MotionEvent#ACTION_DOWN} event.
*
* @param x the x-coordinate of the down action
* @param y the y-coordinate of the down action
*/
private void onActionDown(float x, float y) {
final float left = Edge.LEFT.getCoordinate();
final float top = Edge.TOP.getCoordinate();
final float right = Edge.RIGHT.getCoordinate();
final float bottom = Edge.BOTTOM.getCoordinate();
mPressedHandle = HandleUtil.getPressedHandle(x, y, left, top, right, bottom, mHandleRadius);
if (mPressedHandle == null)
return;
// Calculate the offset of the touch point from the precise location
// of the handle. Save these values in a member variable since we want
// to maintain this offset as we drag the handle.
mTouchOffset = HandleUtil.getOffset(mPressedHandle, x, y, left, top, right, bottom);
invalidate();
}
示例5
void a(float f, float f1, float f2, Rect rect, float f3)
{
a.adjustCoordinate(f, f1, rect, f3, f2);
float f4 = Edge.LEFT.getCoordinate();
float f5 = Edge.TOP.getCoordinate();
float f6 = Edge.RIGHT.getCoordinate();
float f7 = (AspectRatioUtil.calculateWidth(f5, Edge.BOTTOM.getCoordinate(), f2) - (f6 - f4)) / 2.0F;
float f8 = f4 - f7;
float f9 = f7 + f6;
Edge.LEFT.setCoordinate(f8);
Edge.RIGHT.setCoordinate(f9);
if (Edge.LEFT.isOutsideMargin(rect, f3) && !a.isNewRectangleOutOfBounds(Edge.LEFT, rect, f2))
{
float f11 = Edge.LEFT.snapToRect(rect);
Edge.RIGHT.offset(-f11);
a.adjustCoordinate(f2);
}
if (Edge.RIGHT.isOutsideMargin(rect, f3) && !a.isNewRectangleOutOfBounds(Edge.RIGHT, rect, f2))
{
float f10 = Edge.RIGHT.snapToRect(rect);
Edge.LEFT.offset(-f10);
a.adjustCoordinate(f2);
}
}
示例6
void a(float f, float f1, float f2, Rect rect, float f3)
{
a.adjustCoordinate(f, f1, rect, f3, f2);
float f4 = Edge.LEFT.getCoordinate();
float f5 = Edge.TOP.getCoordinate();
float f6 = Edge.RIGHT.getCoordinate();
float f7 = Edge.BOTTOM.getCoordinate();
float f8 = (AspectRatioUtil.calculateHeight(f4, f6, f2) - (f7 - f5)) / 2.0F;
float f9 = f5 - f8;
float f10 = f8 + f7;
Edge.TOP.setCoordinate(f9);
Edge.BOTTOM.setCoordinate(f10);
if (Edge.TOP.isOutsideMargin(rect, f3) && !a.isNewRectangleOutOfBounds(Edge.TOP, rect, f2))
{
float f12 = Edge.TOP.snapToRect(rect);
Edge.BOTTOM.offset(-f12);
a.adjustCoordinate(f2);
}
if (Edge.BOTTOM.isOutsideMargin(rect, f3) && !a.isNewRectangleOutOfBounds(Edge.BOTTOM, rect, f2))
{
float f11 = Edge.BOTTOM.snapToRect(rect);
Edge.TOP.offset(-f11);
a.adjustCoordinate(f2);
}
}
示例7
private void a(float f1, float f2)
{
float f3 = Edge.LEFT.getCoordinate();
float f4 = Edge.TOP.getCoordinate();
float f5 = Edge.RIGHT.getCoordinate();
float f6 = Edge.BOTTOM.getCoordinate();
v = HandleUtil.getPressedHandle(f1, f2, f3, f4, f5, f6, s);
if (v == null)
{
return;
} else
{
u = HandleUtil.getOffset(v, f1, f2, f3, f4, f5, f6);
invalidate();
return;
}
}
示例8
private void a(Canvas canvas)
{
float f1 = Edge.LEFT.getCoordinate();
float f2 = Edge.TOP.getCoordinate();
float f3 = Edge.RIGHT.getCoordinate();
float f4 = Edge.BOTTOM.getCoordinate();
float f5 = Edge.getWidth() / 3F;
float f6 = f1 + f5;
canvas.drawLine(f6, f2, f6, f4, o);
float f7 = f3 - f5;
canvas.drawLine(f7, f2, f7, f4, o);
float f8 = Edge.getHeight() / 3F;
float f9 = f2 + f8;
canvas.drawLine(f1, f9, f3, f9, o);
float f10 = f4 - f8;
canvas.drawLine(f1, f10, f3, f10, o);
}
示例9
/**
* Gets the aspect ratio of the resulting crop window if this handle were
* dragged to the given point.
*
* @param x the x-coordinate
* @param y the y-coordinate
* @return the aspect ratio
*/
private float getAspectRatio(float x, float y) {
// Replace the active edge coordinate with the given touch coordinate.
final float left = (mVerticalEdge == Edge.LEFT) ? x : Edge.LEFT.getCoordinate();
final float top = (mHorizontalEdge == Edge.TOP) ? y : Edge.TOP.getCoordinate();
final float right = (mVerticalEdge == Edge.RIGHT) ? x : Edge.RIGHT.getCoordinate();
final float bottom = (mHorizontalEdge == Edge.BOTTOM) ? y : Edge.BOTTOM.getCoordinate();
final float aspectRatio = AspectRatioUtil.calculateAspectRatio(left, top, right, bottom);
return aspectRatio;
}
示例10
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// Draw translucent background for the cropped area.
drawBackground(canvas, mBitmapRect);
if (showGuidelines()) {
// Determines whether guidelines should be drawn or not
if (mGuidelines == GUIDELINES_ON) {
drawRuleOfThirdsGuidelines(canvas);
} else if (mGuidelines == GUIDELINES_ON_TOUCH) {
// Draw only when resizing
if (mPressedHandle != null)
drawRuleOfThirdsGuidelines(canvas);
} else if (mGuidelines == GUIDELINES_OFF) {
// Do nothing
}
}
// Draws the main crop window border.
canvas.drawRect(Edge.LEFT.getCoordinate(),
Edge.TOP.getCoordinate(),
Edge.RIGHT.getCoordinate(),
Edge.BOTTOM.getCoordinate(),
mBorderPaint);
drawCorners(canvas);
}
示例11
/**
* Indicates whether the crop window is small enough that the guidelines
* should be shown. Public because this function is also used to determine
* if the center handle should be focused.
*
* @return boolean Whether the guidelines should be shown or not
*/
public static boolean showGuidelines() {
if ((Math.abs(Edge.LEFT.getCoordinate() - Edge.RIGHT.getCoordinate()) < DEFAULT_SHOW_GUIDELINES_LIMIT)
|| (Math.abs(Edge.TOP.getCoordinate() - Edge.BOTTOM.getCoordinate()) < DEFAULT_SHOW_GUIDELINES_LIMIT))
return false;
else
return true;
}
示例12
private void drawBackground(Canvas canvas, Rect bitmapRect) {
final float left = Edge.LEFT.getCoordinate();
final float top = Edge.TOP.getCoordinate();
final float right = Edge.RIGHT.getCoordinate();
final float bottom = Edge.BOTTOM.getCoordinate();
/*-
-------------------------------------
| top |
-------------------------------------
| | | |
| | | |
| left | | right |
| | | |
| | | |
-------------------------------------
| bottom |
-------------------------------------
*/
// Draw "top", "bottom", "left", then "right" quadrants.
canvas.drawRect(bitmapRect.left, bitmapRect.top, bitmapRect.right, top, mBackgroundPaint);
canvas.drawRect(bitmapRect.left, bottom, bitmapRect.right, bitmapRect.bottom, mBackgroundPaint);
canvas.drawRect(bitmapRect.left, top, left, bottom, mBackgroundPaint);
canvas.drawRect(right, top, bitmapRect.right, bottom, mBackgroundPaint);
}
示例13
private boolean isCropperSelection(MotionEvent ev){
final float left = Edge.LEFT.getCoordinate();
final float top = Edge.TOP.getCoordinate();
final float right = Edge.RIGHT.getCoordinate();
final float bottom = Edge.BOTTOM.getCoordinate();
if (HandleUtil.getPressedHandle(ev.getX(), ev.getY(), left, top, right, bottom, HandleUtil.getTargetRadius(getContext())) == null) {
return false;
}
return true;
}
示例14
void a(float f, float f1, float f2, Rect rect, float f3)
{
EdgePair edgepair = a(f, f1, f2);
Edge edge = edgepair.primary;
Edge edge1 = edgepair.secondary;
edge.adjustCoordinate(f, f1, rect, f3, f2);
edge1.adjustCoordinate(f2);
if (edge1.isOutsideMargin(rect, f3))
{
edge1.snapToRect(rect);
edge.adjustCoordinate(f2);
}
}
示例15
private float a(float f, float f1)
{
float f2;
float f3;
if (c == Edge.LEFT)
{
f2 = f;
} else
{
f2 = Edge.LEFT.getCoordinate();
}
if (b == Edge.TOP)
{
f3 = f1;
} else
{
f3 = Edge.TOP.getCoordinate();
}
if (c != Edge.RIGHT)
{
f = Edge.RIGHT.getCoordinate();
}
if (b != Edge.BOTTOM)
{
f1 = Edge.BOTTOM.getCoordinate();
}
return AspectRatioUtil.calculateAspectRatio(f2, f3, f, f1);
}
示例16
void a(float f, float f1, Rect rect, float f2)
{
EdgePair edgepair = a();
Edge edge = edgepair.primary;
Edge edge1 = edgepair.secondary;
if (edge != null)
{
edge.adjustCoordinate(f, f1, rect, f2, 1.0F);
}
if (edge1 != null)
{
edge1.adjustCoordinate(f, f1, rect, f2, 1.0F);
}
}
示例17
private void b(Canvas canvas)
{
float f1 = Edge.LEFT.getCoordinate();
float f2 = Edge.TOP.getCoordinate();
float f3 = Edge.RIGHT.getCoordinate();
float f4 = Edge.BOTTOM.getCoordinate();
canvas.drawLine(f1 - D, f2 - C, f1 - D, f2 + E, p);
canvas.drawLine(f1, f2 - D, f1 + E, f2 - D, p);
canvas.drawLine(f3 + D, f2 - C, f3 + D, f2 + E, p);
canvas.drawLine(f3, f2 - D, f3 - E, f2 - D, p);
canvas.drawLine(f1 - D, f4 + C, f1 - D, f4 - E, p);
canvas.drawLine(f1, f4 + D, f1 + E, f4 + D, p);
canvas.drawLine(f3 + D, f4 + C, f3 + D, f4 - E, p);
canvas.drawLine(f3, f4 + D, f3 - E, f4 + D, p);
}
示例18
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
float f1 = Edge.LEFT.getCoordinate();
float f2 = Edge.TOP.getCoordinate();
float f3 = Edge.RIGHT.getCoordinate();
float f4 = Edge.BOTTOM.getCoordinate();
a(canvas, r);
if (showGuidelines())
{
if (A == 2)
{
a(canvas);
} else
if (A == 1)
{
if (v != null)
{
a(canvas);
}
} else
if (A != 0);
}
if (F == 2)
{
canvas.drawRect(f1, f2, f3, f4, n);
} else
{
canvas.drawCircle(f1 + (f3 - f1) / 2.0F, f2 + (f4 - f2) / 2.0F, (f4 - f2) / 2.0F - n.getStrokeWidth(), n);
}
b(canvas);
}
示例19
public RectF getActualCropRect()
{
Rect rect = ImageViewUtil.getBitmapRectCenterInside(g, e);
float f1 = (float)g.getWidth() / (float)rect.width();
float f2 = (float)g.getHeight() / (float)rect.height();
float f3 = Edge.LEFT.getCoordinate() - (float)rect.left;
float f4 = Edge.TOP.getCoordinate() - (float)rect.top;
float f5 = Edge.getWidth();
float f6 = Edge.getHeight();
float f7 = f3 * f1;
float f8 = f4 * f2;
float f9 = f7 + f1 * f5;
float f10 = f8 + f2 * f6;
return new RectF(Math.max(0.0F, f7), Math.max(0.0F, f8), Math.min(g.getWidth(), f9), Math.min(g.getHeight(), f10));
}
示例20
public Bitmap getCroppedImage(int i1, int j1)
{
if (g == null)
{
return null;
}
Rect rect = ImageViewUtil.getBitmapRectCenterInside(g, e);
float f1 = (float)g.getWidth() / (float)rect.width();
float f2 = (float)g.getHeight() / (float)rect.height();
float f3 = Edge.LEFT.getCoordinate() - (float)rect.left;
float f4 = Edge.TOP.getCoordinate() - (float)rect.top;
float f5 = Edge.getWidth();
float f6 = Edge.getHeight();
float f7 = f3 * f1;
float f8 = f4 * f2;
float f9 = f5 * f1;
float f10 = f6 * f2;
Debug.i("CropImageView", (new StringBuilder()).append(", actualCropWidth=").append(f9).append(", actualCropHeight=").append(f10).toString());
if (f9 < 100F || f10 < 100F)
{
return g;
}
Matrix matrix = new Matrix();
if ((float)i1 < f9 || (float)j1 < f10)
{
float f11 = (float)i1 / f9;
float f12 = (float)j1 / f10;
Debug.i("CropImageView", (new StringBuilder()).append("scaleWidth = ").append(f11).append(", scaleHeight=").append(f12).toString());
matrix.postScale(f11, f12);
}
return Bitmap.createBitmap(g, (int)f7, (int)f8, (int)f9, (int)f10, matrix, false);
}
示例21
public Bitmap getCroppedImage() {
Bitmap mCurrentDisplayedBitmap = getCurrentDisplayedImage();
Rect displayedImageRect = ImageViewUtil.getBitmapRectCenterInside(mCurrentDisplayedBitmap, photoView);
// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for width.
float actualImageWidth = mCurrentDisplayedBitmap.getWidth();
float displayedImageWidth = displayedImageRect.width();
float scaleFactorWidth = actualImageWidth / displayedImageWidth;
// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for height.
float actualImageHeight = mCurrentDisplayedBitmap.getHeight();
float displayedImageHeight = displayedImageRect.height();
float scaleFactorHeight = actualImageHeight / displayedImageHeight;
// Get crop window position relative to the displayed image.
float cropWindowX = Edge.LEFT.getCoordinate() - displayedImageRect.left;
float cropWindowY = Edge.TOP.getCoordinate() - displayedImageRect.top;
float cropWindowWidth = Edge.getWidth();
float cropWindowHeight = Edge.getHeight();
// Scale the crop window position to the actual size of the Bitmap.
float actualCropX = cropWindowX * scaleFactorWidth;
float actualCropY = cropWindowY * scaleFactorHeight;
float actualCropWidth = cropWindowWidth * scaleFactorWidth;
float actualCropHeight = cropWindowHeight * scaleFactorHeight;
// Crop the subset from the original Bitmap.
return Bitmap.createBitmap(mCurrentDisplayedBitmap, (int) actualCropX, (int) actualCropY, (int) actualCropWidth, (int) actualCropHeight);
}
示例22
VerticalHandleHelper(Edge edge) {
super(null, edge);
mEdge = edge;
}
示例23
HorizontalHandleHelper(Edge edge) {
super(edge, null);
mEdge = edge;
}
示例24
CornerHandleHelper(Edge horizontalEdge, Edge verticalEdge) {
super(horizontalEdge, verticalEdge);
}
示例25
/**
* Set the initial crop window size and position. This is dependent on the
* size and position of the image being cropped.
*
* @param bitmapRect the bounding box around the image being cropped
*/
private void initCropWindow(Rect bitmapRect) {
// Tells the attribute functions the crop window has already been
// initialized
if (initializedCropWindow == false)
initializedCropWindow = true;
if (mFixAspectRatio) {
// If the image aspect ratio is wider than the crop aspect ratio,
// then the image height is the determining initial length. Else,
// vice-versa.
if (AspectRatioUtil.calculateAspectRatio(bitmapRect) > mTargetAspectRatio) {
Edge.TOP.setCoordinate(bitmapRect.top);
Edge.BOTTOM.setCoordinate(bitmapRect.bottom);
final float centerX = getWidth() / 2f;
// Limits the aspect ratio to no less than 40 wide or 40 tall
final float cropWidth = Math.max(Edge.MIN_CROP_LENGTH_PX,
AspectRatioUtil.calculateWidth(Edge.TOP.getCoordinate(),
Edge.BOTTOM.getCoordinate(),
mTargetAspectRatio));
// Create new TargetAspectRatio if the original one does not fit
// the screen
if (cropWidth == Edge.MIN_CROP_LENGTH_PX)
mTargetAspectRatio = (Edge.MIN_CROP_LENGTH_PX) / (Edge.BOTTOM.getCoordinate() - Edge.TOP.getCoordinate());
final float halfCropWidth = cropWidth / 2f;
Edge.LEFT.setCoordinate(centerX - halfCropWidth);
Edge.RIGHT.setCoordinate(centerX + halfCropWidth);
} else {
Edge.LEFT.setCoordinate(bitmapRect.left);
Edge.RIGHT.setCoordinate(bitmapRect.right);
final float centerY = getHeight() / 2f;
// Limits the aspect ratio to no less than 40 wide or 40 tall
final float cropHeight = Math.max(Edge.MIN_CROP_LENGTH_PX,
AspectRatioUtil.calculateHeight(Edge.LEFT.getCoordinate(),
Edge.RIGHT.getCoordinate(),
mTargetAspectRatio));
// Create new TargetAspectRatio if the original one does not fit
// the screen
if (cropHeight == Edge.MIN_CROP_LENGTH_PX)
mTargetAspectRatio = (Edge.RIGHT.getCoordinate() - Edge.LEFT.getCoordinate()) / Edge.MIN_CROP_LENGTH_PX;
final float halfCropHeight = cropHeight / 2f;
Edge.TOP.setCoordinate(centerY - halfCropHeight);
Edge.BOTTOM.setCoordinate(centerY + halfCropHeight);
}
} else { // ... do not fix aspect ratio...
// Initialize crop window to have 10% padding w/ respect to image.
final float horizontalPadding = 0.1f * bitmapRect.width();
final float verticalPadding = 0.1f * bitmapRect.height();
Edge.LEFT.setCoordinate(bitmapRect.left + horizontalPadding);
Edge.TOP.setCoordinate(bitmapRect.top + verticalPadding);
Edge.RIGHT.setCoordinate(bitmapRect.right - horizontalPadding);
Edge.BOTTOM.setCoordinate(bitmapRect.bottom - verticalPadding);
}
}
示例26
private void drawCorners(Canvas canvas) {
final float left = Edge.LEFT.getCoordinate();
final float top = Edge.TOP.getCoordinate();
final float right = Edge.RIGHT.getCoordinate();
final float bottom = Edge.BOTTOM.getCoordinate();
// Draws the corner lines
// Top left
canvas.drawLine(left - mCornerOffset,
top - mCornerExtension,
left - mCornerOffset,
top + mCornerLength,
mCornerPaint);
canvas.drawLine(left, top - mCornerOffset, left + mCornerLength, top - mCornerOffset, mCornerPaint);
// Top right
canvas.drawLine(right + mCornerOffset,
top - mCornerExtension,
right + mCornerOffset,
top + mCornerLength,
mCornerPaint);
canvas.drawLine(right, top - mCornerOffset, right - mCornerLength, top - mCornerOffset, mCornerPaint);
// Bottom left
canvas.drawLine(left - mCornerOffset,
bottom + mCornerExtension,
left - mCornerOffset,
bottom - mCornerLength,
mCornerPaint);
canvas.drawLine(left,
bottom + mCornerOffset,
left + mCornerLength,
bottom + mCornerOffset,
mCornerPaint);
// Bottom left
canvas.drawLine(right + mCornerOffset,
bottom + mCornerExtension,
right + mCornerOffset,
bottom - mCornerLength,
mCornerPaint);
canvas.drawLine(right,
bottom + mCornerOffset,
right - mCornerLength,
bottom + mCornerOffset,
mCornerPaint);
}
示例27
/**
* Gets the cropped image based on the current crop window.
*
* @return a new Bitmap representing the cropped image
*/
public Bitmap getCroppedImage() {
RectF rect = mImageView.getDisplayRect();
Matrix matrix = mImageView.getDisplayMatrix();
float photoViewScale = (float)Math.sqrt(ImageViewUtil.getXScale(matrix)*ImageViewUtil.getXScale(matrix) +
ImageViewUtil.getXSkew(matrix)*ImageViewUtil.getXSkew(matrix));
Matrix orgScaleMatrix = new Matrix(matrix);
orgScaleMatrix.postScale(1 / photoViewScale, 1 / photoViewScale);
// Log.i("Cropper", "width=" + Math.round(rect.width() / photoViewScale) + " height=" + Math.round(rect.height() / photoViewScale)
// + " bitmapWidth=" + mBitmap.getWidth());
Bitmap rotateBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), orgScaleMatrix, true);
// Get crop window position relative to the displayed image.
// Log.i("Cropper", "Edge.LEFT=" + Edge.LEFT.getCoordinate() + " rect.left=" + rect.left
// + "Edge.TOP=" + Edge.TOP.getCoordinate() + " rect.top=" + rect.top);
final float cropWindowX = Edge.LEFT.getCoordinate() -rect.left;
final float cropWindowY = Edge.TOP.getCoordinate() -rect.top;
final float cropWindowWidth = Edge.getWidth();
final float cropWindowHeight = Edge.getHeight();
// Scale the crop window position to the actual size of the Bitmap.
float actualCropX = cropWindowX / photoViewScale;
float actualCropY = cropWindowY / photoViewScale;
float actualCropWidth = cropWindowWidth / photoViewScale;
float actualCropHeight = cropWindowHeight / photoViewScale;
// Crop the subset from the original Bitmap.
// Log.i("Cropper", "actualCropX="+ actualCropX +" actualCropY=" + actualCropY
// + " actualCropWidth=" + actualCropWidth + " actualCropHeight=" + actualCropHeight
// + " photoViewScale=" + photoViewScale + " rotateBitmap.width=" + rotateBitmap.getWidth());
if(actualCropX < 0){
actualCropWidth += actualCropX;
actualCropX = 0;
}
if(actualCropY < 0){
actualCropHeight += actualCropY;
actualCropY = 0;
}
if(actualCropWidth <0 || actualCropHeight<0){
return null;
}
if(actualCropWidth + actualCropX> rotateBitmap.getWidth()){
actualCropWidth = rotateBitmap.getWidth() - actualCropX;
}
if(actualCropHeight + actualCropY> rotateBitmap.getHeight()){
actualCropHeight = rotateBitmap.getHeight() - actualCropY;
}
final Bitmap croppedBitmap = Bitmap.createBitmap(rotateBitmap,
(int) actualCropX,
(int) actualCropY,
(int) actualCropWidth,
(int) actualCropHeight);
return croppedBitmap;
}
示例28
/**
* Gets the crop window's position relative to the source Bitmap (not the image
* displayed in the CropImageView).
*
* @return a RectF instance containing cropped area boundaries of the source Bitmap
*/
public RectF getActualCropRect() {
final Rect displayedImageRect = ImageViewUtil.getBitmapRectCenterInside(mBitmap, mImageView);
// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for width.
final float actualImageWidth = mBitmap.getWidth();
final float displayedImageWidth = displayedImageRect.width();
final float scaleFactorWidth = actualImageWidth / displayedImageWidth;
// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for height.
final float actualImageHeight = mBitmap.getHeight();
final float displayedImageHeight = displayedImageRect.height();
final float scaleFactorHeight = actualImageHeight / displayedImageHeight;
// Get crop window position relative to the displayed image.
final float displayedCropLeft = Edge.LEFT.getCoordinate() - displayedImageRect.left;
final float displayedCropTop = Edge.TOP.getCoordinate() - displayedImageRect.top;
final float displayedCropWidth = Edge.getWidth();
final float displayedCropHeight = Edge.getHeight();
// Scale the crop window position to the actual size of the Bitmap.
float actualCropLeft = displayedCropLeft * scaleFactorWidth;
float actualCropTop = displayedCropTop * scaleFactorHeight;
float actualCropRight = actualCropLeft + displayedCropWidth * scaleFactorWidth;
float actualCropBottom = actualCropTop + displayedCropHeight * scaleFactorHeight;
// Correct for floating point errors. Crop rect boundaries should not
// exceed the source Bitmap bounds.
actualCropLeft = Math.max(0f, actualCropLeft);
actualCropTop = Math.max(0f, actualCropTop);
actualCropRight = Math.min(mBitmap.getWidth(), actualCropRight);
actualCropBottom = Math.min(mBitmap.getHeight(), actualCropBottom);
final RectF actualCropRect = new RectF(actualCropLeft,
actualCropTop,
actualCropRight,
actualCropBottom);
return actualCropRect;
}
示例29
d(Edge edge)
{
super(edge, null);
a = edge;
}
示例30
b(Edge edge, Edge edge1)
{
super(edge, edge1);
}