我有一个类,我把布局的屏幕截图存储为一个JPEG文件....我遇到的问题是图像大小因屏幕分辨率而异。例如。如果我使用中等分辨率手机,图像大小约为50-60kb,但对于高分辨率则高达1.5mbs ....所以有什么办法可以保持图像大小不变,而不受屏幕尺寸或分辨率的影响?制作一个屏幕截图代码支持多种屏幕尺寸
public class abc extends Activity {
View content;
String fileName, fname;
static File file;
static String RECE;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.rece);
ImageView iv = (ImageView) findViewById(R.id.Ivsignature);
iv.setImageBitmap(Signature.sign);
Initialize();
content = findViewById(R.id.Rlrece);
ViewTreeObserver vto = content.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
public void onGlobalLayout() {
content.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
getScreen();
}
});
}
private void getScreen() {
View view = content;
View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
String myPath = Environment.getExternalStorageDirectory() + "/Rece";
File myDir = new File(myPath);
try {
myDir.mkdirs();
} catch (Exception e) {
}
fname = fileName + ".jpg";
file = new File(myDir, fname);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
b.compress(CompressFormat.JPEG, 100, fos);
// Toast.makeText(getApplicationContext(), fname + " saved",
// Toast.LENGTH_LONG).show();
Intent my = new Intent(getApplicationContext(),
DialogActivity.class);
my.putExtra("Rsystrace", DialogActivity.Systrace);
startActivityForResult(my, 1);
} catch (Throwable ex) {
Toast.makeText(getApplicationContext(),
"error: " + ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
http://developer.android.com/training/multiscreen/screensizes.html –
我正在采取屏幕截图,并将其保存为一个文件....我希望文件大小不变.. – Audi