Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 放大图像视图_Android_Image_Zooming - Fatal编程技术网

Android 放大图像视图

Android 放大图像视图,android,image,zooming,Android,Image,Zooming,我正在使用这段代码,但我有一个问题:我的图像不是静态的,在可绘制的文件夹中,我从一个url获取它 我需要做什么改变?下面是我获取图像和缩放的代码 public class Zoom extends View { private Drawable image; private int zoomControler=200; public Zoom(Context context) { super(context); image=context.getResources().getDrawable(R

我正在使用这段代码,但我有一个问题:我的图像不是静态的,在可绘制的文件夹中,我从一个url获取它

我需要做什么改变?下面是我获取图像和缩放的代码

public class Zoom extends View {
private Drawable image;
private int zoomControler=200;
public Zoom(Context context)
{
super(context);
image=context.getResources().getDrawable(R.drawable.gallery_photo_1);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//here u can control the width and height of the images........ this line is very important
image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);

image.draw(canvas);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
zoomControler+=10;
if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
zoomControler-=10;
if(zoomControler<10)
zoomControler=10;
invalidate();
return true;
}
} 

你的问题是什么?imageview没有刷新,或者没有显示?????这段代码从drawable获取图像并使用drawable对象,我希望对从url获取并在另一个类上定义的imageview进行缩放。如果你愿意,我可以编辑代码。你现在可以用普通的imageResource进行缩放吗???可以用drawable中的图像进行缩放,但我不知道如何为imageView而不是drawable“声明”它。(imageview是在onCreate方法上定义的。)所以你可以缩放普通资源…我想你得到了一个uri来设置为imageview的图像,对吗????
try {
                          ImageView i = (ImageView)findViewById(R.id.icon);
                          Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());
                          i.setImageBitmap(bitmap); 
                        } catch (MalformedURLException e) {
                          e.printStackTrace();
                        } catch (IOException e) {
                          e.printStackTrace();
                        }