我有一堂课,我在其中截取布局的屏幕截图并将其存储为 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();
}
}