如何重新设置bimpat的大小?

问答小助手 2013-04-26 10:37:30
加精
原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/2244

问题描述:

在我的程序中我需要重新设置 bitmap的大小,设置成imageview的大小,下面的代码报错了,如何改正,重新设置 bitmap的大小?
Bitmap bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), aMatrix, false);
Bitmap.createScaledBitmap(bmp, MyImageview_wt, MyImageview_ht, false);
MyImageview.setImageBitmap(bmp);


解决方案:
使用下面的代码试试:

public static Bitmap resizeBitMapImage1(String filePath, int targetWidth,
int targetHeight) {
Bitmap bitMapImage = null;
// First, get the dimensions of the image
Options options = new Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
double sampleSize = 0;
// Only scale if we need to
// (16384 buffer for img processing)
Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math
.abs(options.outWidth - targetWidth);
if (options.outHeight * options.outWidth * 2 >= 1638) {
// Load, scaling to smallest power of 2 that'll get it <= desired
// dimensions
sampleSize = scaleByHeight ? options.outHeight / targetHeight
: options.outWidth / targetWidth;
sampleSize = (int) Math.pow(2d,
Math.floor(Math.log(sampleSize) / Math.log(2d)));
}
// Do the actual decoding
options.inJustDecodeBounds = false;
options.inTempStorage = new byte[128];
while (true) {
try {
options.inSampleSize = (int) sampleSize;
bitMapImage = BitmapFactory.decodeFile(filePath, options);
break;
} catch (Exception ex) {
try {
sampleSize = sampleSize * 2;
} catch (Exception ex1) {
}
}
}
return bitMapImage;
}
...全文
1131 37 打赏 收藏 转发到动态 举报
写回复
用AI写文章
37 条回复
切换为时间正序
请发表友善的回复…
发表回复
阳光下的孩子 2013-05-07
  • 打赏
  • 举报
回复
Jobernowl 2013-05-06
  • 打赏
  • 举报
回复
感谢分享 辛苦了 先mark以后用到再回来看
xxxoos 2013-05-06
  • 打赏
  • 举报
回复
不错不错
为了木头 2013-05-05
  • 打赏
  • 举报
回复
奖励计划经济学院派在家庭主妇在此时间段你说明理由你
u010556885 2013-05-03
  • 打赏
  • 举报
回复
能帮忙解释一下这些代码吗?非常感谢!
赵Andy 2013-05-03
  • 打赏
  • 举报
回复
为什么没有解释?
dgsgyjpeje 2013-05-02
  • 打赏
  • 举报
回复
刚好用得上这些,谢谢楼主啊~~~太好了
怪人伽利略 2013-04-29
  • 打赏
  • 举报
回复
学习。。。。。。
u010489012 2013-04-28
  • 打赏
  • 举报
回复
u010495416 2013-04-28
  • 打赏
  • 举报
回复
好好哈。。。。。。////
永恒的吻 2013-04-27
  • 打赏
  • 举报
回复
谢谢 支持一下
u010477380 2013-04-27
  • 打赏
  • 举报
回复
麦田捕手 2013-04-27
  • 打赏
  • 举报
回复
标记收藏一些
u010484949 2013-04-27
  • 打赏
  • 举报
回复
谢谢 支持一下
u010475093 2013-04-27
  • 打赏
  • 举报
回复
henhao henhao henhao
u010484551 2013-04-27
  • 打赏
  • 举报
回复
很实用的代码.好东西
phoenier 2013-04-26
  • 打赏
  • 举报
回复
学习学习代码
u010463521 2013-04-26
  • 打赏
  • 举报
回复
这比较难
detective2005 2013-04-26
  • 打赏
  • 举报
回复
很实用的代码
  • 打赏
  • 举报
回复
需要用到的,mark一个
加载更多回复(6)
内容概要:本文围绕基于元模型优化算法的主从博弈多虚拟电厂动态定价与能量管理展开研究,提出了一种结合主从博弈框架与元模型优化算法的协同优化方法。通过构建多虚拟电厂之间的主从博弈模型,刻画其在电力市场中的交互行为与利益分配机制,并引入元模型(如代理模型、响应面模型)对复杂优化问题进行近似求解,显著提升了计算效率与求解精度。该方法能够有效处理含不确定性因素的动态定价、负荷调度与能量管理问题,在保障系统运行稳定性的基础上,实现经济性与可靠性的协同优化。研究还提供了完整的Matlab代码实现路径与仿真结果,验证了所提方法在多主体协同决策与资源优化配置方面的有效性与实用性。; 适合人群:具备一定电力系统、博弈论基础及Matlab编程能力,从事能源互联网、综合能源系统、电力市场机制设计等相关领域研究的科研人员与研究生。; 使用场景及目标:①用于多虚拟电厂参与电力市场的动态定价机制设计与博弈行为建模;②实现考虑可再生能源不确定性的分布式能源系统协同优化调度;③为多主体能源系统的市场出清、收益分配与策略性投标提供算法支撑与仿真平台。; 阅读建议:建议读者结合所提供的Matlab代码深入理解主从博弈的数学建模过程与元模型优化算法的具体实现细节,重点关注目标函数构造、约束处理及算法收敛性分析,并可进一步拓展至其他智能优化算法或多场景鲁棒性对比研究,以深化对复杂能源系统决策机制的理解。

80,492

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧