@Override
public boolean setDisplayMatrix(Matrix finalMatrix) {
if (finalMatrix == null)
throw new IllegalArgumentException("Matrix cannot be null");
ImageView imageView = getImageView();
if (null == imageView)
return false;
if (null == imageView.getDrawable())
return false;
mSuppMatrix.set(finalMatrix);
setImageViewMatrix(getDrawMatrix());
checkMatrixBounds();
return true;
}
java类android.graphics.Matrix的实例源码
PhotoViewAttacher.java 文件源码
项目:PicShow-zhaipin
阅读 36
收藏 0
点赞 0
评论 0
RotateLoadingLayout.java 文件源码
项目:ultrasonic
阅读 45
收藏 0
点赞 0
评论 0
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
super(context, mode, scrollDirection, attrs);
mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);
mHeaderImage.setScaleType(ScaleType.MATRIX);
mHeaderImageMatrix = new Matrix();
mHeaderImage.setImageMatrix(mHeaderImageMatrix);
mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
mRotateAnimation.setRepeatCount(Animation.INFINITE);
mRotateAnimation.setRepeatMode(Animation.RESTART);
}
CameraActivity.java 文件源码
项目:SortingHatAndroid
阅读 37
收藏 0
点赞 0
评论 0
public void onPreviewSizeChosen(final Size size, final int rotation) {
previewWidth = size.getWidth();
previewHeight = size.getHeight();
final Display display = getWindowManager().getDefaultDisplay();
final int screenOrientation = display.getRotation();
LOGGER.i("Sensor orientation: %d, Screen orientation: %d", rotation, screenOrientation);
sensorOrientation = rotation + screenOrientation;
LOGGER.i("Initializing at size %dx%d", previewWidth, previewHeight);
rgbBytes = new int[previewWidth * previewHeight];
rgbFrameBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888);
croppedBitmap = Bitmap.createBitmap(INPUT_SIZE, INPUT_SIZE, Bitmap.Config.ARGB_8888);
frameToCropTransform =
ImageUtils.getTransformationMatrix(previewWidth, previewHeight, INPUT_SIZE, INPUT_SIZE,
sensorOrientation, MAINTAIN_ASPECT);
Matrix cropToFrameTransform = new Matrix();
frameToCropTransform.invert(cropToFrameTransform);
yuvBytes = new byte[3][];
}
CameraConnectionFragment.java 文件源码
项目:android-image-classification
阅读 38
收藏 0
点赞 0
评论 0
/**
* Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
* This method should be called after the camera preview size is determined in
* setUpCameraOutputs and also the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(final int viewWidth, final int viewHeight) {
final Activity activity = getActivity();
if (null == textureView || null == previewSize || null == activity) {
return;
}
final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
final Matrix matrix = new Matrix();
final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
final float centerX = viewRect.centerX();
final float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
final float scale =
Math.max(
(float) viewHeight / previewSize.getHeight(),
(float) viewWidth / previewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
textureView.setTransform(matrix);
}
RYBDrawStrategyStateTwo.java 文件源码
项目:FancyView
阅读 36
收藏 0
点赞 0
评论 0
@Override
public void drawIcon(Canvas canvas, float fraction, Drawable drawable, int colorOfIcon,
WidthAndHeightOfView widthAndHeightOfView) {
int centerX = widthAndHeightOfView.getWidth() / 2;
int centerY = widthAndHeightOfView.getHeight() / 2 - 150;
canvas.save();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
float newFraction = (fraction - 0.65f) / 0.35f;
paint.setColor(Color.parseColor("#e53935"));
canvas.drawCircle(centerX, centerY - 50, 100 * (1 - newFraction), paint);
paint.setColor(Color.parseColor("#fdd835"));
canvas.drawCircle(centerX -35, centerY + 35,100 * (1 - newFraction), paint);
paint.setColor(Color.parseColor("#1e88e5"));
canvas.drawCircle(centerX + 35, centerY + 35, 100 * (1 - newFraction), paint);
canvas.restore();
canvas.save();
Path path = new Path();
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
canvas.concat(matrix);
path.addCircle(centerX, centerY, bitmap.getHeight() * 1.5f * newFraction, Path.Direction.CW);
canvas.clipPath(path);
canvas.drawBitmap(bitmap, centerX - bitmap.getWidth() / 2, centerY - bitmap.getHeight() / 2, paint);
canvas.restore();
}
Rotate3dAnimation.java 文件源码
项目:shareNote
阅读 41
收藏 0
点赞 0
评论 0
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final float fromDegrees = mFromDegrees;
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
final Matrix matrix = t.getMatrix();
mCamera.save();
switch (mRollType) {
case ROLL_BY_X:
mCamera.rotateX(degrees);
break;
case ROLL_BY_Y:
mCamera.rotateY(degrees);
break;
case ROLL_BY_Z:
mCamera.rotateZ(degrees);
break;
}
mCamera.getMatrix(matrix);
mCamera.restore();
matrix.preTranslate(-mPivotX, -mPivotY);
matrix.postTranslate(mPivotX, mPivotY);
}
ImageViewTouchBase.java 文件源码
项目:XERUNG
阅读 35
收藏 0
点赞 0
评论 0
protected void zoomOut(float rate) {
if (bitmapDisplayed.getBitmap() == null) {
return;
}
float cx = getWidth() / 2F;
float cy = getHeight() / 2F;
// Zoom out to at most 1x
Matrix tmp = new Matrix(suppMatrix);
tmp.postScale(1F / rate, 1F / rate, cx, cy);
if (getScale(tmp) < 1F) {
suppMatrix.setScale(1F, 1F, cx, cy);
} else {
suppMatrix.postScale(1F / rate, 1F / rate, cx, cy);
}
setImageMatrix(getImageViewMatrix());
center();
}
DefaultZoomableController.java 文件源码
项目:Zoomable
阅读 46
收藏 0
点赞 0
评论 0
/**
* Limits the translation so that there are no empty spaces on the sides if possible.
*
* <p> The image is attempted to be centered within the view bounds if the transformed image is
* smaller. There will be no empty spaces within the view bounds if the transformed image is
* bigger. This applies to each dimension (horizontal and vertical) independently.
*
* @param limitTypes whether to limit translation along the specific axis.
* @return whether limiting has been applied or not
*/
private boolean limitTranslation(Matrix transform, @LimitFlag int limitTypes) {
if (!shouldLimit(limitTypes, LIMIT_TRANSLATION_X | LIMIT_TRANSLATION_Y)) {
return false;
}
RectF b = mTempRect;
b.set(mImageBounds);
transform.mapRect(b);
float offsetLeft = shouldLimit(limitTypes, LIMIT_TRANSLATION_X) ?
getOffset(b.left, b.right, mViewBounds.left, mViewBounds.right, mImageBounds.centerX()) : 0;
float offsetTop = shouldLimit(limitTypes, LIMIT_TRANSLATION_Y) ?
getOffset(b.top, b.bottom, mViewBounds.top, mViewBounds.bottom, mImageBounds.centerY()) : 0;
if (offsetLeft != 0 || offsetTop != 0) {
transform.postTranslate(offsetLeft, offsetTop);
return true;
}
return false;
}
VideoFrameDrawer.java 文件源码
项目:AppRTC-Android
阅读 46
收藏 0
点赞 0
评论 0
/**
* Draws a VideoFrame.TextureBuffer. Calls either drawer.drawOes or drawer.drawRgb
* depending on the type of the buffer. You can supply an additional render matrix. This is
* used multiplied together with the transformation matrix of the frame. (M = renderMatrix *
* transformationMatrix)
*/
static void drawTexture(RendererCommon.GlDrawer drawer, VideoFrame.TextureBuffer buffer,
Matrix renderMatrix, int frameWidth, int frameHeight, int viewportX, int viewportY,
int viewportWidth, int viewportHeight) {
Matrix finalMatrix = new Matrix(buffer.getTransformMatrix());
finalMatrix.preConcat(renderMatrix);
float[] finalGlMatrix = RendererCommon.convertMatrixFromAndroidGraphicsMatrix(finalMatrix);
switch (buffer.getType()) {
case OES:
drawer.drawOes(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHeight, viewportX,
viewportY, viewportWidth, viewportHeight);
break;
case RGB:
drawer.drawRgb(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHeight, viewportX,
viewportY, viewportWidth, viewportHeight);
break;
default:
throw new RuntimeException("Unknown texture type.");
}
}
Camera2BasicFragment.java 文件源码
项目:JinsMemeBRIDGE-Android
阅读 37
收藏 0
点赞 0
评论 0
/**
* Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
* This method should be called after the camera preview size is determined in
* setUpCameraOutputs and also the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(int viewWidth, int viewHeight) {
Activity activity = getActivity();
if (null == mTextureView || null == mPreviewSize || null == activity) {
return;
}
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
float scale = Math.max(
(float) viewHeight / mPreviewSize.getHeight(),
(float) viewWidth / mPreviewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
mTextureView.setTransform(matrix);
}
ImageUtils.java 文件源码
项目:chat-sdk-android-push-firebase
阅读 40
收藏 0
点赞 0
评论 0
public static Bitmap scaleImage(Bitmap bitmap, int boxSize){
if (boxSize == 0)
return null;
// Determine how much to scale: the dimension requiring less scaling is
// closer to the its side. This way the image always stays inside your
// bounding box AND either x/y axis touches it.
float xScale = ((float) boxSize) / bitmap.getWidth();
float yScale = ((float) boxSize) / bitmap.getHeight();
float scale = (xScale <= yScale) ? xScale : yScale;
// Create a matrix for the scaling and add the scaling data
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
// Create a new bitmap and convert it to a format understood by the ImageView
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
BitmapUtils.java 文件源码
项目:android-titanium-imagecropper
阅读 48
收藏 0
点赞 0
评论 0
/**
* Rotate the given bitmap by the given degrees.<br>
* New bitmap is created and the old one is recycled.
*/
private static Bitmap rotateAndFlipBitmapInt(
Bitmap bitmap, int degrees, boolean flipHorizontally, boolean flipVertically) {
if (degrees > 0 || flipHorizontally || flipVertically) {
Matrix matrix = new Matrix();
matrix.setRotate(degrees);
matrix.postScale(flipHorizontally ? -1 : 1, flipVertically ? -1 : 1);
Bitmap newBitmap =
Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
if (newBitmap != bitmap) {
bitmap.recycle();
}
return newBitmap;
} else {
return bitmap;
}
}
Camera2VideoFragment.java 文件源码
项目:CommonsLab
阅读 35
收藏 0
点赞 0
评论 0
/**
* Configures the necessary {@link Matrix} transformation to `mTextureView`.
* This method should not to be called until the camera preview size is determined in
* openCamera, or until the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(int viewWidth, int viewHeight) {
Activity activity = getActivity();
if (null == mTextureView || null == mPreviewSize || null == activity) {
return;
}
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
float scale = Math.max(
(float) viewHeight / mPreviewSize.getHeight(),
(float) viewWidth / mPreviewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
}
mTextureView.setTransform(matrix);
}
Camera2Api.java 文件源码
项目:smart-lens
阅读 35
收藏 0
点赞 0
评论 0
/**
* Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
* This method should be called after the camera preview size is determined in
* setUpCameraOutputs and also the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(final int viewWidth, final int viewHeight) {
if (mPreviewSize == null) return;
final int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
final Matrix matrix = new Matrix();
final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
final RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
final float centerX = viewRect.centerX();
final float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
final float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
(float) viewWidth / mPreviewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
mAutoFitTextureView.setTransform(matrix);
}
FDCamera2Presenter.java 文件源码
项目:Image-Detection-Samples
阅读 46
收藏 0
点赞 0
评论 0
/**
* Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
* This method should be called after the camera preview size is determined in
* setUpCameraOutputs and also the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(int viewWidth, int viewHeight) {
if (isViewAvailable()) {
if (null == activityView.getTextureView()) {
return;
}
int rotation = activityView.getWindowManager().getDefaultDisplay().getRotation();
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
float scale = Math.max(
(float) viewHeight / previewSize.getHeight(),
(float) viewWidth / previewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
activityView.getTextureView().setTransform(matrix);
}
}
SVGAndroidRenderer.java 文件源码
项目:microMathematics
阅读 48
收藏 0
点赞 0
评论 0
private void popLayer(SvgElement obj) {
// If this is masked content, apply the mask now
if (state.style.mask != null && state.directRendering) {
// The masked content has been drawn, now we have to render the mask
// to a separate canvas
SVG.SvgObject ref = document.resolveIRI(state.style.mask);
duplicateCanvas();
renderMask((SVG.Mask) ref, obj);
Bitmap maskedContent = processMaskBitmaps();
// Retrieve the real canvas
canvas = canvasStack.pop();
canvas.save();
// Reset the canvas matrix so that we can draw the maskedContent
// exactly over the top of the root bitmap
canvas.setMatrix(new Matrix());
canvas.drawBitmap(maskedContent, 0, 0, state.fillPaint);
maskedContent.recycle();
canvas.restore();
}
statePop();
}
CameraConnectionFragment.java 文件源码
项目:AI_Calorie_Counter_Demo
阅读 57
收藏 0
点赞 0
评论 0
/**
* Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
* This method should be called after the camera preview size is determined in
* setUpCameraOutputs and also the size of `mTextureView` is fixed.
*
* @param viewWidth The width of `mTextureView`
* @param viewHeight The height of `mTextureView`
*/
private void configureTransform(final int viewWidth, final int viewHeight) {
final Activity activity = getActivity();
if (null == textureView || null == previewSize || null == activity) {
return;
}
final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
final Matrix matrix = new Matrix();
final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
final float centerX = viewRect.centerX();
final float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
final float scale =
Math.max(
(float) viewHeight / previewSize.getHeight(),
(float) viewWidth / previewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
textureView.setTransform(matrix);
}
ViewGroupUtilsHoneycomb.java 文件源码
项目:MaterialOCR
阅读 41
收藏 0
点赞 0
评论 0
static void offsetDescendantMatrix(ViewParent target, View view, Matrix m) {
final ViewParent parent = view.getParent();
if (parent instanceof View && parent != target) {
final View vp = (View) parent;
offsetDescendantMatrix(target, vp, m);
m.preTranslate(-vp.getScrollX(), -vp.getScrollY());
}
m.preTranslate(view.getLeft(), view.getTop());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (!view.getMatrix().isIdentity()) {
m.preConcat(view.getMatrix());
}
}
}
ThumbnailUtil.java 文件源码
项目:financisto1-holo
阅读 45
收藏 0
点赞 0
评论 0
/**
* Creates a centered bitmap of the desired size.
* @param source
* @param recycle whether we want to recycle the input
*/
public static Bitmap extractMiniThumb(
Bitmap source, int width, int height, boolean recycle) {
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 miniThumbnail = transform(matrix, source, width, height, true, recycle);
return miniThumbnail;
}
PinchImageView.java 文件源码
项目:godlibrary
阅读 52
收藏 0
点赞 0
评论 0
/**
* 执行当前outerMatrix到指定outerMatrix渐变的动画
*
* 调用此方法会停止正在进行中的手势以及手势动画.
* 当duration为0时,outerMatrix值会被立即设置而不会启动动画.
*
* @param endMatrix 动画目标矩阵
* @param duration 动画持续时间
*
* @see #getOuterMatrix(Matrix)
*/
public void outerMatrixTo(Matrix endMatrix, long duration) {
if (endMatrix == null) {
return;
}
//将手势设置为PINCH_MODE_FREE将停止后续手势的触发
mPinchMode = PINCH_MODE_FREE;
//停止所有正在进行的动画
cancelAllAnimator();
//如果时间不合法立即执行结果
if (duration <= 0) {
mOuterMatrix.set(endMatrix);
dispatchOuterMatrixChanged();
invalidate();
} else {
//创建矩阵变化动画
mScaleAnimator = new ScaleAnimator(mOuterMatrix, endMatrix, duration);
mScaleAnimator.start();
}
}
RNWebGLTextureView.java 文件源码
项目:react-native-webgl-view-shot
阅读 42
收藏 0
点赞 0
评论 0
public void run() {
Bitmap bitmap;
try {
bitmap = captureView(view);
}
catch (Exception e) {
return;
}
if (yflip) {
Matrix matrix = new Matrix();
matrix.postScale(1, -1);
boolean hasAlpha = bitmap.hasAlpha();
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
bitmap.setHasAlpha(hasAlpha);
}
int[] textures = new int[1];
glGenTextures(1, textures, 0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
this.attachTexture(textures[0]);
}
BitmapCompressor.java 文件源码
项目:tiny
阅读 32
收藏 0
点赞 0
评论 0
private static Bitmap matrixCompress(Bitmap bitmap, int baseline, boolean recycle) {
if (bitmap == null)
return null;
int bitmapWidth = bitmap.getWidth();
int bitmapHeight = bitmap.getHeight();
int maxValue = Math.max(bitmapWidth, bitmapHeight);
if (maxValue > baseline) {
Matrix matrix = new Matrix();
float rate = (float) baseline / (float) maxValue;
matrix.postScale(rate, rate);
Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, true);
if (recycle) {
bitmap.recycle();
bitmap = null;
}
return result;
} else {
return bitmap;
}
}
CompressEngine.java 文件源码
项目:FastAndroid
阅读 41
收藏 0
点赞 0
评论 0
private Bitmap rotatingImage(Bitmap bitmap) {
if (srcExif == null) return bitmap;
Matrix matrix = new Matrix();
int angle = 0;
int orientation = srcExif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
angle = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
angle = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
angle = 270;
break;
}
matrix.postRotate(angle);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
PinchImageView.java 文件源码
项目:SweepRobot
阅读 40
收藏 0
点赞 0
评论 0
/**
* 对图片按照一些手势信息进行缩放
*
* @param scaleCenter mScaleCenter
* @param scaleBase mScaleBase
* @param distance 手指两点之间距离
* @param lineCenter 手指两点之间中点
*
* @see #mScaleCenter
* @see #mScaleBase
*/
private void scaleAndRotate(PointF scaleCenter, float scaleBase, float distance, PointF lineCenter,float degree) {
if (!isReady()) {
return;
}
//计算图片从fit center状态到目标状态的缩放比例
float scale = scaleBase * distance;
Matrix matrix = MathUtils.matrixTake();
//按照图片缩放中心缩放,并且让缩放中心在缩放点中点上
matrix.postScale(scale, scale, scaleCenter.x, scaleCenter.y);
//按照图片缩放中心旋转,并且让缩放中心在缩放点中点上
matrix.postRotate(degree,scaleCenter.x,scaleCenter.y);
//让图片的缩放中点跟随手指缩放中点
matrix.postTranslate(lineCenter.x - scaleCenter.x, lineCenter.y - scaleCenter.y);
//应用变换
mOuterMatrix.set(matrix);
MathUtils.matrixGiven(matrix);
dispatchOuterMatrixChanged();
//重绘
invalidate();
}
PhoenixHeader.java 文件源码
项目:GitHub
阅读 37
收藏 0
点赞 0
评论 0
private void initView(Context context, AttributeSet attrs) {
mMatrix = new Matrix();
DensityUtil density = new DensityUtil();
mSunSize = density.dip2px(40);
setupAnimation();
setupPathsDrawable();
setMinimumHeight(density.dip2px(100));
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PhoenixHeader);
int primaryColor = ta.getColor(R.styleable.PhoenixHeader_phPrimaryColor, 0);
int accentColor = ta.getColor(R.styleable.PhoenixHeader_phAccentColor, 0);
if (primaryColor != 0) {
setBackgroundColor(primaryColor);
if (accentColor != 0) {
mDrawableSky.parserColors(primaryColor, accentColor);
} else {
mDrawableSky.parserColors(primaryColor);
}
}
ta.recycle();
}
MotionDetectorCamera2.java 文件源码
项目:habpanelviewer
阅读 36
收藏 0
点赞 0
评论 0
private void configureTransform(TextureView textureView) {
if (null == textureView || null == mPreviewSize || null == mActivity) {
return;
}
int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, textureView.getWidth(), textureView.getHeight());
RectF bufferRect = new RectF(0, 0, mPreviewSize.y, mPreviewSize.x);
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
float scale = Math.max(
(float) textureView.getHeight() / mPreviewSize.y,
(float) textureView.getWidth() / mPreviewSize.x);
matrix.postScale(scale, scale, centerX, centerY);
}
matrix.postRotate(-90 * rotation, centerX, centerY);
textureView.setTransform(matrix);
}
PageWidget.java 文件源码
项目:GitHub
阅读 58
收藏 0
点赞 0
评论 0
public PageWidget(Context context, String bookId,
List<BookMixAToc.mixToc.Chapters> chaptersList,
OnReadStateChangeListener listener) {
super(context, bookId, chaptersList, listener);
mPath0 = new Path();
mPath1 = new Path();
mMaxLength = (float) Math.hypot(mScreenWidth, mScreenHeight);
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL);
createDrawable();
ColorMatrix cm = new ColorMatrix();//设置颜色数组
float array[] = {0.55f, 0, 0, 0, 80.0f, 0, 0.55f, 0, 0, 80.0f, 0, 0, 0.55f, 0, 80.0f, 0, 0, 0, 0.2f, 0};
cm.set(array);
mColorMatrixFilter = new ColorMatrixColorFilter(cm);
mMatrix = new Matrix();
mTouch.x = 0.01f; // 不让x,y为0,否则在点计算时会有问题
mTouch.y = 0.01f;
}
ImageUtils.java 文件源码
项目:GitHub
阅读 36
收藏 0
点赞 0
评论 0
/**
* 快速模糊图片
* <p>先缩小原图,对小图进行模糊,再放大回原先尺寸</p>
*
* @param src 源图片
* @param scale 缩放比例(0...1)
* @param radius 模糊半径(0...25)
* @param recycle 是否回收
* @return 模糊后的图片
*/
public static Bitmap fastBlur(final Bitmap src,
@FloatRange(from = 0, to = 1, fromInclusive = false) final float scale,
@FloatRange(from = 0, to = 25, fromInclusive = false) final float radius,
final boolean recycle) {
if (isEmptyBitmap(src)) return null;
int width = src.getWidth();
int height = src.getHeight();
Matrix matrix = new Matrix();
matrix.setScale(scale, scale);
Bitmap scaleBitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
Canvas canvas = new Canvas();
PorterDuffColorFilter filter = new PorterDuffColorFilter(
Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP);
paint.setColorFilter(filter);
canvas.scale(scale, scale);
canvas.drawBitmap(scaleBitmap, 0, 0, paint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
scaleBitmap = renderScriptBlur(scaleBitmap, radius, recycle);
} else {
scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle);
}
if (scale == 1) return scaleBitmap;
Bitmap ret = Bitmap.createScaledBitmap(scaleBitmap, width, height, true);
if (scaleBitmap != null && !scaleBitmap.isRecycled()) scaleBitmap.recycle();
if (recycle && !src.isRecycled()) src.recycle();
return ret;
}
ImageUtil.java 文件源码
项目:FaceRecognition
阅读 38
收藏 0
点赞 0
评论 0
public static Bitmap convert(Bitmap a) {
int w = a.getWidth();
int h = a.getHeight();
Bitmap newb = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
Canvas cv = new Canvas(newb);
Matrix m = new Matrix();
//m.postScale(1, -1); //镜像垂直翻转
m.postScale(-1, 1); //镜像水平翻转
//m.postRotate(-90); //旋转-90度
Bitmap new2 = Bitmap.createBitmap(a, 0, 0, w, h, m, true);
cv.drawBitmap(new2, new Rect(0, 0, new2.getWidth(), new2.getHeight()),new Rect(0, 0, w, h), null);
return newb;
}
WoWoPathView.java 文件源码
项目:GitHub
阅读 37
收藏 0
点赞 0
评论 0
private void initImage() {
if (headImageRes != 0) {
bitmap = BitmapFactory.decodeResource(getResources(), headImageRes);
if (headImageWidth != 0 || headImageHeight != 0) bitmap = getResizedBitmap(bitmap, headImageWidth, headImageHeight);
bitmapOffsetX = bitmap.getWidth() / 2;
bitmapOffsetY = bitmap.getHeight() / 2;
bitmapPosition = new float[2];
bitmapTan = new float[2];
matrix = new Matrix();
}
}