郑州app开发android加载大图实例
为富顺等地区用户提供了全套网页设计制作服务,及富顺网站建设行业解决方案。主营业务为做网站、成都网站设计、富顺网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
MainActivity.java
package cn.xhhkj.image;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.bitmap;
import android.graphics.bitmapFactory;
import android.graphics.point;
import android.os.bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "结果是";
private static final int UpDATE_pROGRESS = 0;
public String path = src="/upload/article1/1.jpg";
private ImageView iv_image;
private int screenWidth;
private int screenHeight;
bitmap bitmap;
@Override
protected void onCreate(bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
public void init(){
iv_image = findViewbyId(R.id.iv_pic);
screenWidth = getWindowManager().getDefaultDisplay().getWidth();
screenHeight = getWindowManager().getDefaultDisplay().getHeight();
point outSize = new point();
getWindowManager().getDefaultDisplay().getSize(outSize);
Log.d(TAG,"宽度"+outSize.x+"高度"+outSize.y);
}
public void loadpic(View view) {
bitmap bitmap = bitmapFactory.decodeFile(path);
iv_image.setImagebitmap(bitmap);
//loadpic2();
}
public void loadpic2(){
bitmapFactory.Options option =new bitmapFactory.Options();
option.inJustDecodebounds = true;
int width = option.outWidth;
int height = option.outHeight;
if(width>screenWidth||height>screenHeight){
int widthIndex = Math.round((float)width/(float)screenWidth);
int heightIndex = Math.round((float)height/(float)screenHeight);
option.inSampleSize = Math.max(widthIndex, heightIndex);
}
option.inJustDecodebounds = false;
bitmap = bitmapFactory.decodeFile(path, option);
iv_image.setImagebitmap(bitmap);
}
public void loadpic3(){
bitmapFactory.Options option =new bitmapFactory.Options();
option.inSampleSize = 1;
bitmap bitmap = null;
int i = 1;
for(;;){
try {
option.inSampleSize = i;
bitmap = bitmapFactory.decodeFile(path, option);
break;
} catch (Error e) {
i*=2;
System.out.println("i = "+i);
}
}
iv_image.setImagebitmap(bitmap);
}
}
新闻标题:android加载大图实例
转载注明:https://www.cdcxhl.com/article12/scssdc.html
成都网站建设公司_创新互联,为您提供网站维护、网页设计公司、动态网站、服务器托管、移动网站建设、企业建站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联