android获取imageview高度,android - 如何知道图像Android的大小(高度和宽度)? 不是ImageView的大小 - 堆栈内存溢出...

开发者正在尝试获取从图库导入并存储在内部存储中的图片的尺寸。他们遇到了问题,因为直接获取ImageView的大小只会返回屏幕尺寸,而不是图片的实际大小。目前的代码涉及启动图库选择图片,复制到内部存储,并尝试获取文件路径。现在需要找到方法来确定图片的高度和宽度。
摘要由CSDN通过智能技术生成

我需要知道我想在活动中使用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的高度和宽度的方法。

非常感谢,我完全被封锁了...对不起,很长的帖子,这是个土豆:🥔

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值