单击按钮时将图像旋转 left/right 一个角度
Rotate image left/right by an angle on button click
使用picasso-transformations library for Image editing.There 有两个单独的左旋转按钮和右rotation.On 按钮点击,图像只旋转一次。我想在每次单击按钮时将图像旋转到各自的方向。
recyclerView.addOnItemTouchListener(new RecyclerClick(act, recyclerView, new RecyclerClickListener() {
@Override
public void onClick(View view, final int position) {
switch (position) {
case 0:
Picasso.with(act)
.load(selectedPhotoUri)
.rotate(90f)
.into(photo);
break;
case 1:
Picasso.with(act)
.load(selectedPhotoUri)
.rotate(90f)
.into(photo);
break;
}
}
也许实例变量有帮助。
像这样:
recyclerView.addOnItemTouchListener(new RecyclerClick(act, recyclerView, new RecyclerClickListener() {
int rotate = 0;
@Override
public void onClick(View view, final int position) {
switch (position) {
case 0:
rotate += 90f
break;
case 1:
rotate -= 90f;
break;
}
Picasso.with(act)
.load(selectedPhotoUri)
.rotate(rotate)
.into(photo);
}
}));
public static Image rotate(Image img, double angle) {
double sin = Math.abs(Math.sin(Math.toRadians(angle))),
cos = Math.abs(Math.cos(Math.toRadians(angle)));
int w = img.getWidth(null), h = img.getHeight(null);
int neww = (int) Math.floor(w*cos + h*sin),
newh = (int) Math.floor(h*cos + w*sin);
BufferedImage bimg = toBufferedImage(getEmptyImage(neww, newh));
Graphics2D g = bimg.createGraphics();
g.translate((neww-w)/2, (newh-h)/2);
g.rotate(Math.toRadians(angle), w/2, h/2);
g.drawRenderedImage(toBufferedImage(img), null);
g.dispose();
return toImage(bimg);
}
使用此代码旋转图像..并在单击按钮时调用此方法
使用picasso-transformations library for Image editing.There 有两个单独的左旋转按钮和右rotation.On 按钮点击,图像只旋转一次。我想在每次单击按钮时将图像旋转到各自的方向。
recyclerView.addOnItemTouchListener(new RecyclerClick(act, recyclerView, new RecyclerClickListener() {
@Override
public void onClick(View view, final int position) {
switch (position) {
case 0:
Picasso.with(act)
.load(selectedPhotoUri)
.rotate(90f)
.into(photo);
break;
case 1:
Picasso.with(act)
.load(selectedPhotoUri)
.rotate(90f)
.into(photo);
break;
}
}
也许实例变量有帮助。
像这样:
recyclerView.addOnItemTouchListener(new RecyclerClick(act, recyclerView, new RecyclerClickListener() {
int rotate = 0;
@Override
public void onClick(View view, final int position) {
switch (position) {
case 0:
rotate += 90f
break;
case 1:
rotate -= 90f;
break;
}
Picasso.with(act)
.load(selectedPhotoUri)
.rotate(rotate)
.into(photo);
}
}));
public static Image rotate(Image img, double angle) {
double sin = Math.abs(Math.sin(Math.toRadians(angle))),
cos = Math.abs(Math.cos(Math.toRadians(angle)));
int w = img.getWidth(null), h = img.getHeight(null);
int neww = (int) Math.floor(w*cos + h*sin),
newh = (int) Math.floor(h*cos + w*sin);
BufferedImage bimg = toBufferedImage(getEmptyImage(neww, newh));
Graphics2D g = bimg.createGraphics();
g.translate((neww-w)/2, (newh-h)/2);
g.rotate(Math.toRadians(angle), w/2, h/2);
g.drawRenderedImage(toBufferedImage(img), null);
g.dispose();
return toImage(bimg);
}
使用此代码旋转图像..并在单击按钮时调用此方法