本文整理汇总了Java中android.graphics.Matrix.setRotate方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.setRotate方法的具体用法?Java Matrix.setRotate怎么用?Java Matrix.setRotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Matrix
的用法示例。
在下文中一共展示了Matrix.setRotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setManualFocusAt
import android.graphics.Matrix; //导入方法依赖的package包/类
void setManualFocusAt(int x, int y) {
int mDisplayOrientation = getActivity().getWindowManager().getDefaultDisplay().getRotation();
float points[] = new float[2];
points[0] = (float) x / mTextureView.getWidth();
points[1] = (float) y / mTextureView.getHeight();
Matrix rotationMatrix = new Matrix();
rotationMatrix.setRotate(mDisplayOrientation, 0.5f, 0.5f);
rotationMatrix.mapPoints(points);
if (mPreviewRequestBuilder != null) {
mIsManualFocusing = true;
updateManualFocus(points[0], points[1]);
if (mPreviewSession != null) {
try {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_START);
mPreviewSession.capture(mPreviewRequestBuilder.build(), null, mBackgroundHandler);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
mPreviewSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
null, mBackgroundHandler);
} catch (CameraAccessException | IllegalStateException e) {
Log.e(TAG, "Failed to set manual focus.", e);
}
}
resumeAutoFocusAfterManualFocus();
}
}
示例2: rotate
import android.graphics.Matrix; //导入方法依赖的package包/类
/**
* 旋转图片
*
* @param source
* @param angle
* @param recycleSource
* @return
*/
public static Bitmap rotate(Bitmap source, int angle, boolean recycleSource) {
Bitmap result = null;
if (angle != 0) {
Matrix m = new Matrix();
m.setRotate(angle);
try {
result = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), m, true);
} catch (Throwable ex) {
LogUtil.e(ex.getMessage(), ex);
}
}
if (result != null) {
if (recycleSource && result != source) {
source.recycle();
source = null;
}
} else {
result = source;
}
return result;
}
示例3: tryToGetBitmap
import android.graphics.Matrix; //导入方法依赖的package包/类
private Bitmap tryToGetBitmap(File file, BitmapFactory.Options options, int rotate, boolean shouldScale) throws IOException, OutOfMemoryError {
Bitmap bmp;
if (options == null) {
bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
} else {
bmp = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
}
if (bmp == null) {
throw new IOException("The image file could not be opened.");
}
if (options != null && shouldScale) {
float scale = calculateScale(options.outWidth, options.outHeight);
bmp = this.getResizedBitmap(bmp, scale);
}
if (rotate != 0) {
Matrix matrix = new Matrix();
matrix.setRotate(rotate);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
return bmp;
}
示例4: savePhoto
import android.graphics.Matrix; //导入方法依赖的package包/类
private void savePhoto(byte[] data) throws IOException {
imageFile = getFileForImg();
if(imageFile != null){
int rotation;
if(cameraId == Camera.CameraInfo.CAMERA_FACING_BACK) {
rotation = 90;
}else if(cameraId == Camera.CameraInfo.CAMERA_FACING_FRONT){
rotation = -90;
}else{
Toast.makeText(CsVideo.this,"发生未知错误!",Toast.LENGTH_SHORT).show();
startRecordingView.setEnable(true);
return;
}
Bitmap bm0 = BitmapFactory.decodeByteArray(data, 0, data.length);
Matrix m = new Matrix();
m.setRotate(rotation,(float) bm0.getWidth() / 2, (float) bm0.getHeight() / 2);
final Bitmap bm = Bitmap.createBitmap(bm0, 0, 0, bm0.getWidth(), bm0.getHeight(), m, true);
bm.compress(Bitmap.CompressFormat.JPEG,100,new FileOutputStream(imageFile));
startUcrop("file://"+imageFile.getPath());
}else{
Toast.makeText(CsVideo.this,"发生未知错误!",Toast.LENGTH_SHORT).show();
startRecordingView.setEnable(true);
}
}
示例5: getRotatedBitmap
import android.graphics.Matrix; //导入方法依赖的package包/类
/**
* Figure out if the bitmap should be rotated. For instance if the picture was taken in
* portrait mode
*
* @param rotate
* @param bitmap
* @return rotated bitmap
*/
private Bitmap getRotatedBitmap(int rotate, Bitmap bitmap, ExifHelper exif) {
Matrix matrix = new Matrix();
if (rotate == 180) {
matrix.setRotate(rotate);
} else {
matrix.setRotate(rotate, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
}
try
{
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
exif.resetOrientation();
}
catch (OutOfMemoryError oom)
{
// You can run out of memory if the image is very large:
// http://simonmacdonald.blogspot.ca/2012/07/change-to-camera-code-in-phonegap-190.html
// If this happens, simply do not rotate the image and return it unmodified.
// If you do not catch the OutOfMemoryError, the Android app crashes.
}
return bitmap;
}
示例6: degreeBitmap
import android.graphics.Matrix; //导入方法依赖的package包/类
/**
*
* @param src
* @param degree
* @return
*/
public static Bitmap degreeBitmap(Bitmap src , float degree) {
if(degree == 0.0F) {
return src;
}
Matrix matrix = new Matrix();
matrix.reset();
matrix.setRotate(degree, src.getWidth() / 2, src.getHeight() / 2);
Bitmap resultBitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
boolean filter = true;
if(resultBitmap == null) {
LogUtil.e(TAG, "resultBmp is null: ");
filter = true;
} else {
filter = false;
}
if(resultBitmap != src) {
src.recycle();
}
LogUtil.d(TAG, "filter: " + filter + " degree:" + degree);
return resultBitmap;
}
示例7: updateDrawState
import android.graphics.Matrix; //导入方法依赖的package包/类
@Override
public void updateDrawState(TextPaint paint) {
paint.setStyle(Paint.Style.FILL);
Shader shader = new LinearGradient(0, 0, 0, paint.getTextSize() * colors.length, colors, null,
Shader.TileMode.MIRROR);
Matrix matrix = new Matrix();
matrix.setRotate(angle);
shader.setLocalMatrix(matrix);
paint.setShader(shader);
}
示例8: rotateBitmap
import android.graphics.Matrix; //导入方法依赖的package包/类
/**
* 用于压缩时旋转图片
*
* @throws IOException
* @throws OutOfMemoryError
*/
public static Bitmap rotateBitmap(String srcFilePath, Bitmap bitmap) throws IOException, OutOfMemoryError {
float degree = 0F;
try {
ExifInterface exif = new ExifInterface(srcFilePath);
switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90F;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180F;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270F;
break;
default:
break;
}
} catch (IOException e) {
e.printStackTrace();
// 01-23 11:03:04.040 W/ExifInterface(29568): Invalid image.
// 01-23 11:03:04.040 W/ExifInterface(29568): java.io.IOException: Invalid marker: 89
// 01-23 11:03:04.040 W/ExifInterface(29568): at android.media.ExifInterface.getJpegAttributes(ExifInterface.java:1656)
// 01-23 11:03:04.040 W/ExifInterface(29568): at android.media.ExifInterface.loadAttributes(ExifInterface.java:1360)
// 01-23 11:03:04.040 W/ExifInterface(29568): at android.media.ExifInterface.<init>(ExifInterface.java:1064)
}
Matrix matrix = new Matrix();
matrix.setRotate(degree, bitmap.getWidth(), bitmap.getHeight());
Bitmap b2 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
if (bitmap != b2) {
bitmap.recycle();
bitmap = b2;
}
return bitmap;
}
示例9: onPictureTaken
import android.graphics.Matrix; //导入方法依赖的package包/类
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
Matrix matrix = new Matrix();
matrix.setRotate(270);
File jpgFile = new File(Environment.getExternalStorageDirectory() + "/DCIM/camera");
if (!jpgFile.exists()) {
jpgFile.mkdir();
}
File jpgFile1 = new File(jpgFile.getAbsoluteFile(), System.currentTimeMillis() + ".jpg");
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
FileOutputStream fos = new FileOutputStream(jpgFile1);
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos);
// ToastUtils.show(getApplicationContext(), getString(R.string.save_success));
fos.close();
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(jpgFile1);
intent.setData(uri);
sendBroadcast(intent);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (Build.VERSION.SDK_INT >= 24) {
reset();
}
isTakingPhoto = false;
}
}
示例10: testCreation_hundredAndEightyDegrees
import android.graphics.Matrix; //导入方法依赖的package包/类
@Test
public void testCreation_hundredAndEightyDegrees() {
OrientedDrawable drawable =
new OrientedDrawable(mDrawable, 180, ExifInterface.ORIENTATION_ROTATE_180);
drawable.setBounds(mBounds);
drawable.draw(mCanvas);
Matrix expectedMatrix = new Matrix();
expectedMatrix.setRotate(180, drawable.getBounds().centerX(), drawable.getBounds().centerY());
assertFalse(drawable.mRotationMatrix.isIdentity());
AndroidGraphicsTestUtils.assertEquals(expectedMatrix, drawable.mRotationMatrix);
verifySetBounds(expectedMatrix);
}
示例11: rotateBitmap
import android.graphics.Matrix; //导入方法依赖的package包/类
/**
* 旋转图片
*/
private Bitmap rotateBitmap(Context context, Bitmap srcBitmap, float degree) {
Matrix matrix = new Matrix();
matrix.reset();
matrix.setRotate(degree);
Bitmap tempBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), matrix, true);
return tempBitmap;
}
示例12: testCreation_transpose
import android.graphics.Matrix; //导入方法依赖的package包/类
@Test
public void testCreation_transpose() {
OrientedDrawable drawable =
new OrientedDrawable(mDrawable, 0, ExifInterface.ORIENTATION_TRANSPOSE);
drawable.setBounds(mBounds);
drawable.draw(mCanvas);
Matrix expectedMatrix = new Matrix();
expectedMatrix.setRotate(270, drawable.getBounds().centerX(), drawable.getBounds().centerY());
expectedMatrix.postScale(1, -1);
assertFalse(drawable.mRotationMatrix.isIdentity());
AndroidGraphicsTestUtils.assertEquals(expectedMatrix, drawable.mRotationMatrix);
verifySetBounds(expectedMatrix);
}
示例13: fetchBitmapFromUri
import android.graphics.Matrix; //导入方法依赖的package包/类
/**
* Fetches a bitmap image from the device given the image's uri.
* @param imageUri Uri of the image on the device (either in the gallery or from the camera).
* @return A Bitmap representation of the image on the device, correctly orientated.
*/
private Bitmap fetchBitmapFromUri(Uri imageUri) {
try {
// Fetch the Bitmap from the Uri.
Bitmap selectedImage = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
// Fetch the orientation of the Bitmap in storage.
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cursor = getContentResolver().query(imageUri, orientationColumn, null, null, null);
int orientation = 0;
if (cursor != null && cursor.moveToFirst()) {
orientation = cursor.getInt(cursor.getColumnIndex(orientationColumn[0]));
}
if(cursor != null) {
cursor.close();
}
// Rotate the bitmap with the found orientation.
Matrix matrix = new Matrix();
matrix.setRotate(orientation);
selectedImage = Bitmap.createBitmap(selectedImage, 0, 0, selectedImage.getWidth(), selectedImage.getHeight(), matrix, true);
return selectedImage;
} catch (IOException e) {
showDialog(R.string.error_title_default, e.getMessage(), true);
e.printStackTrace();
return null;
}
}
示例14: setManualFocusAt
import android.graphics.Matrix; //导入方法依赖的package包/类
void setManualFocusAt(int x, int y) {
int mDisplayOrientation = mWindowManager.getDefaultDisplay().getRotation();
float points[] = new float[2];
points[0] = (float) x / mTextureView.getWidth();
points[1] = (float) y / mTextureView.getHeight();
Matrix rotationMatrix = new Matrix();
rotationMatrix.setRotate(mDisplayOrientation, 0.5f, 0.5f);
rotationMatrix.mapPoints(points);
if (mPreviewRequestBuilder != null) {
mIsManualFocusing = true;
updateManualFocus(points[0], points[1]);
if (mPreviewSession != null) {
try {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_START);
mPreviewSession.capture(mPreviewRequestBuilder.build(), null, mBackgroundHandler);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
mPreviewSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
null, mBackgroundHandler);
} catch (CameraAccessException | IllegalStateException e) {
Log.e(TAG, "Failed to set manual focus.", e);
}
}
resumeAutoFocusAfterManualFocus();
}
}
示例15: rotateAndFlipBitmapInt
import android.graphics.Matrix; //导入方法依赖的package包/类
/**
* 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;
}
}