Glideは20に精通しています.画像を回転する方法
http://mrfu.me/2016/02/28/Glide_How_to_Rotate_Images/
Glideで画像を回転する方法
実はandroidgraphics.Matrixクラスは、私たちが必要とする正確な方法(さらに多くの方法)を提供しています.このコードクリップは、画像を回転させるために使用されます.
特にGlideで役立つようにBitmappTransformationとして包みます.
上記のクラスが発生したことを知らない場合は、私たちが紹介したCustom Transformationsを見てみましょう.それはあなたが知っていることをすべて教えてくれます.
最後に、新しい変換の例を見てみましょう.
もちろん、2番目のパラメータを変更して、必要な回転角度を設定することができます.動的に設定することもできます!
これは、ライブラリに直接提供されていない場合でも、Glideで回転する必要があるすべてのコードと知識を提供する必要があります.もしこれがあなたにとって役に立つなら、コメントの中で私たちに知らせてください.
Glideで画像を回転する方法
実はandroidgraphics.Matrixクラスは、私たちが必要とする正確な方法(さらに多くの方法)を提供しています.このコードクリップは、画像を回転させるために使用されます.
Bitmap toTransform = ... // your bitmap source
Matrix matrix = new Matrix();
matrix.postRotate(rotateRotationAngle);
Bitmap.createBitmap(toTransform, 0, 0, toTransform.getWidth(), toTransform.getHeight(), matrix, true);
特にGlideで役立つようにBitmappTransformationとして包みます.
public class RotateTransformation extends BitmapTransformation {
private float rotateRotationAngle = 0f;
public RotateTransformation(Context context, float rotateRotationAngle) {
super( context );
this.rotateRotationAngle = rotateRotationAngle;
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
Matrix matrix = new Matrix();
matrix.postRotate(rotateRotationAngle);
return Bitmap.createBitmap(toTransform, 0, 0, toTransform.getWidth(), toTransform.getHeight(), matrix, true);
}
@Override
public String getId() {
return "rotate" + rotateRotationAngle;
}
}
上記のクラスが発生したことを知らない場合は、私たちが紹介したCustom Transformationsを見てみましょう.それはあなたが知っていることをすべて教えてくれます.
最後に、新しい変換の例を見てみましょう.
private void loadImageOriginal() {
Glide
.with( context )
.load( eatFoodyImages[0] )
.into( imageView1 );
}
private void loadImageRotated() {
Glide
.with( context )
.load( eatFoodyImages[0] )
.transform( new RotateTransformation( context, 90f ))
.into( imageView3 );
}
もちろん、2番目のパラメータを変更して、必要な回転角度を設定することができます.動的に設定することもできます!
これは、ライブラリに直接提供されていない場合でも、Glideで回転する必要があるすべてのコードと知識を提供する必要があります.もしこれがあなたにとって役に立つなら、コメントの中で私たちに知らせてください.