我知道这是一个老问题。但是我没有找到任何合适的解决方案。我想旋转一个大的import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Emails {
public static void main(String args[]) throws IOException {
Scanner scanner = new Scanner(new File("rajeev.dat"));
ArrayList<String[]> lines = new ArrayList<>();
Pattern regex = Pattern.compile("(?!^([A-Za-z0-9.]+(?!@Google.org)|[A-Za-z0-9.]+(?!@Yahoo.net)))");
Pattern findComma = Pattern.compile(",");
while(scanner.hasNextLine()){
lines.add(scanner.nextLine().split(","));
}
for(String[] s: lines){
for(String s1: s){
System.out.println(s1);
}
System.out.println();
}
String temp = "";
String output = "";
output += lines.get(0)[0] + ":" + lines.get(0)[1] + ":";
for(int i = 2; i < lines.get(0).length; i++){
temp += lines.get(0)[i] + " ";
}
System.out.println(temp);
Matcher match = regex.matcher(temp);
String temp2 = "";
boolean nofail = false;
while(match.find()){
output += match.group().trim() + ":";
nofail = true;
}
if(nofail) {
System.out.println(output);
}
}
}
,对其进行一些处理,然后将其保存到bitmap
中。我正在使用下面的方法旋转file
。但是当我旋转多个位图时。我在低端设备上收到Bitmap
。我不想缩小位图。我该如何避免呢?
OOM
有没有比这更好的解决方案了?
答案 0 :(得分:0)
这是一种旋转位图而不会出现内存不足问题的方法。
Drawable getRotateDrawable(final Bitmap b, final float angle) {
final BitmapDrawable drawable = new BitmapDrawable(getResources(), b) {
@Override
public void draw(final Canvas canvas) {
canvas.save();
canvas.rotate(angle, b.getWidth() / 2, b.getHeight() / 2);
super.draw(canvas);
canvas.restore();
}
};
return drawable;
}
您还可以轻松地将可绘制对象转换为位图
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
答案 1 :(得分:-1)
尝试带有动画的Object Animator
ObjectAnimator rotatedrawable= ObjectAnimator.ofFloat(drawable ,
"rotation", 0f, 180f);//instade of 180 you can put any angle you want
rotatedrawable.setDuration(100); // animation duration
rotatedrawable.start();