使用以下代码导出图像,但是因为我指定的文件大小为40 80 120,因为它创建的每个图像都具有相同的大小。应考虑默认图像大小,并应创建@ 2x和@ 3x图像。
public class page2 extends ActionBarActivity {
ImageView b2;
int count = 0;
Handler handler = null;
Handler handler1 = null;
Runnable j = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page2);
Intent c = getIntent();
String name = c.getStringExtra("t");
Toast.makeText(getApplicationContext(), name, Toast.LENGTH_SHORT).show();
b2 = (ImageView) findViewById(R.id.redball);
// Animation animation = AnimationUtils.loadAnimation(page2.this, R.anim.fade);
// Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.activity_move);
// b2.startAnimation(animation);
// b2.startAnimation(animation1);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
count = count + 1;
Intent intentVibrate = new Intent(getApplicationContext(), VibrateService.class);
startService(intentVibrate);
}
});
handler1 = new Handler();
j = new Runnable() {
public void run() {
AbsoluteLayout.LayoutParams absParams =
(AbsoluteLayout.LayoutParams) b2.getLayoutParams();
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int width = displaymetrics.widthPixels;
int height = displaymetrics.heightPixels;
Random r = new Random();
absParams.x = r.nextInt(width);
absParams.y = r.nextInt(height);
b2.setLayoutParams(absParams);
Animation animation = AnimationUtils.loadAnimation(page2.this, R.anim.fade);
b2.startAnimation(animation);
handler1.postDelayed(j, 870);
}
};
handler1.postDelayed(j, 50);
handler = new Handler();
final Runnable t = new Runnable() {
public void run() {
Intent d = new Intent(getApplicationContext(), Page3.class);
d.putExtra("count", count);
d.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(d);
}
};
handler.postDelayed(t, 8000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_page2, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onBackPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
handler.removeCallbacks(t);
return true;
}
return super.onKeyDown(keyCode, event);
}
}
答案 0 :(得分:0)
以下是我发现基于默认图像生成@ 2x和@ 3x的解决方案:
# grab the identify string, make sure it succeeded
IMG_CHARS=$(identify "${file}" 2> /dev/null) || die "${file} is not a proper image"
# grab width and height
IMG_CHARS=$(echo "${IMG_CHARS}" | sed -n 's/\(^.*\)\ \([0-9]*\)x\([0-9]*\)\ \(.*$\)/\2 \3/p')
width=$(echo "${IMG_CHARS}" | awk '{print $1}')
height=$(echo "${IMG_CHARS}" | awk '{print $2}')
cp -p "$filename" "$png"
sips -Z "$(($width * 1))" "$(($height * 1))" "$png"
cp -p "$filename" "$twopng"
sips -Z "$(($width * 2))" "$(($height * 2))" "$twopng"
cp -p "$filename" "$threepng"
sips -Z "$(($width * 3))" "$(($height * 3))" "$threepng"