+ -
当前位置:首页 → 问答吧 → 浏览图片 加Url 直接取得图片

浏览图片 加Url 直接取得图片

时间:2011-09-05

来源:互联网

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
public class Showimage extends Activity{ private ImageView mImageView1; Button bt_plist; Bundle bundle,bunde; String urlPic ;
@Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.showimage); setIntentdata(); findViews(); setListensers(); }
//宣告与查找介面元件
private void findViews() {   bt_plist = (Button)findViewById(R.id.showButton1);   mImageView1 = (ImageView) findViewById(R.id.myImageView1); mImageView1.setImageBitmap(loadImageFromUrl(urlPic)); } //添加特定介面元件控制流程
private void setListensers(){
  bt_plist.setOnClickListener(plist);
}
 
private Button.OnClickListener plist= new OnClickListener(){
  public void onClick(View v){
    Intent intent = new Intent();
       intent.setClass(Showimage.this,Display.class);
    intent.putExtras(bundle); startActivity(intent);
  } };
 
private static final int BUFFER_IO_SIZE = 8000;
private Bitmap loadImageFromUrl(final String urlPic) { try { BufferedInputStream bis = new BufferedInputStream(new URL(urlPic).openStream(), BUFFER_IO_SIZE); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos, BUFFER_IO_SIZE); copy(bis, bos); bos.flush(); return BitmapFactory.decodeByteArray(baos.toByteArray(), 0, baos.size()); } catch (IOException e) { // handle it properly e.printStackTrace(); return null; } } private void copy(final InputStream bis, final OutputStream baos) throws IOException { byte[] buf = new byte[256]; int l; while ((l = bis.read(buf)) >= 0) baos.write(buf, 0, l); } private void setIntentdata() {
 
  bundle = new Bundle(); bunde = Showimage.this.getIntent().getExtras(); bundle.putString("loginmode",bunde.getString("loginmode"));//登入模式 bundle.putString("account",bunde.getString("account"));//登入帐号 bundle.putString("d_p_barcode",bunde.getString("d_p_barcode"));
  bundle.putString("d_lat", bunde.getString("d_lat"));//纬度 bundle.putString("d_lng", bunde.getString("d_lng"));//经度 bundle.putString("back","Search");//倒

作者: a790418a   发布时间: 2011-09-05

应该说 下载的图片 像素太大 会错误....而不是容量大小

请问该如何解决

作者: a790418a   发布时间: 2011-09-07

热门下载

更多