我有一個類,我把佈局的屏幕截圖存儲爲一個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