我需要知道我想在活动中使用ImageView显示的图像的大小(高度和宽度)。 该图像可以比屏幕宽,然后,如果我得到ImageView的大小,它将返回我屏幕的大小...该图像存储在内部存储器中,我从图库中捕获它。 像这样->目的:
// IMPORT FROM EXTERNAL STORAGE
.setNegativeButton(R.string.import_sound, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, IMPORT_SOUND);
}
});
onActivityResult:
// Retrieves data from intent
Uri resultUri = data.getData();
// Create file's name
Date currentTime = Calendar.getInstance().getTime();
String extension = null;
if (resultUri != null) {
extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(getContentResolver().getType(resultUri));
}
String imageName = "gal_" + currentTime + extension;
File newFile = new File(getApplicationContext().getFilesDir().getAbsolutePath(), imageName);
// Copy from the gallery to internal storage's file
InputStream inputStream = null;
OutputStream outputStream = null;
try {
if (resultUri != null) {
inputStream = getContentResolver().openInputStream(resultUri);
}
outputStream = new FileOutputStream(newFile);
if (inputStream != null) {
IOUtils.copy(inputStream, outputStream);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (requestCode == IMPORT_PICTO) {
// Get file's path
m_picto = newFile.getAbsolutePath();
// Allows the system to destroy the file if leaves without saving
m_destroyPicto = true;
}
这是我绝对需要知道高度和宽度的图像。 我在网上寻找了这个,但是我只找到了如何知道尺寸(以kB ...为单位)或如何获取ImageView的高度和宽度的方法。
非常感谢,我完全被封锁了...对不起,很长的帖子,这是个土豆:🥔