android中怎么跳转到相册获取照片并得到url

android中怎么跳转到相册获取照片并得到url,第1张

方法/步骤

1

如下图所示,需要根据URL地址获取加载到图中Anroid机器人所在的位置,这是运行前的效果:

2

首先需根据URL地址获取,如下所示,urladdr即为地址,返回Drawable对象:

//download image from network using @urladdress

private Drawable loadImageFromNetwork(String urladdr) {

// TODO Auto-generated method stub

Drawable drawable = null;

try{

//judge if has picture locate or not according to filename

drawable = DrawablecreateFromStream(new URL(urladdr)openStream(), "imagejpg");

}catch(IOException e){

Logd("test",egetMessage());

}

if(drawable == null){

Logd("test","null drawable");

}else{

Logd("test","not null drawable");

}

return drawable;

}

3

获取到后,需要更新主线程UI资源,考虑到时间以及界面反应延迟等,所以采用线程加以处理,如下图所示:

// image

new Thread(new Runnable(){

Drawable drawable = loadImageFromNetwork(urladdress);

@Override

public void run(){

//post() is quite important,update pictures in UI main thread

imagepost(new Runnable(){

@Override

public void run(){

//TODO Auto-generated method stub

imagesetImageDrawable(drawable);

}

});

}

//download image from network using @urladdress

private Drawable loadImageFromNetwork(String urladdr) {

// 略(如 1 中所示)

}

})start(); //线程启动

4

说明:在上述示例代码中,image是ImageView类的一个对象,也就是APP中的一个显示图像组件,利用获取到的drawable去更新image,运行效果如下所示:

实现的功能为从服务器获取数据,在布局页面上显示。由于的个数是不确定的,因此采用在布局页面中定义多个ImageView来显示是不合理的。

(一)首先定义布局

android:id="@+id/id_layout_movie"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

/>

(二)加载显示时获取到布局文件

RelativeLayout rl_Movie = (RelativeLayout) findViewById(Ridid_layout_movie);

(三)依次循环服务器获取的数据,一张一张设置显示的位置

//newWidth为显示的宽度,newHeight为显示的高度

RelativeLayoutLayoutParams lp1 = new RelativeLayoutLayoutParams( newWidth, newHeight);

设置lp1leftMargin和lp1topMargin的值

(四)最后设置rl_MovieaddView(iv, lp1)将加入布局文件中

问题很简单,有两种可能:

1、iv对象是空的,即通过findViewById没有找到控件;

2、imageArray[i]是空的;

下个断点,然后watch一下这两个对象就知道了

您好,很高兴为您解答://根据坐标获取ImageView imageView = ((ImageView)v);Bitmap bitmap = ((BitmapDrawable)imageViewgetDrawable())getBitmap();int pixel = bitmapgetPixel(x,y);//获取颜色int redValue = Colorred(pixel);int blueValue = Colorblue(pixel);int greenValue = Colorgreen(pixel);​转载,仅供参考,如果我的回答没帮助到您,请继续追问。

[url]>

Bitmap bm = BitmapFactorydecodeFile(FilePath);//FilePath为路径及名字

ImageViewsetImageBitmap(bm);

以上就是关于android中怎么跳转到相册获取照片并得到url全部的内容,包括:android中怎么跳转到相册获取照片并得到url、android 存在数据库中的动态图片,如何读取出来,显示在ImageView中、android开发中向通过LayoutInflater获取到的对象中的组件赋值例如ImageView等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/10101161.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存