从毕加索图片获取宽度和高度下载

时间:2015-07-28 21:06:18

标签: android image url fragment picasso

我正在使用一个利用Picasso下载图像的库(SliderLayout),但我不确定如何从下载的图像中提取宽度和高度。有什么想法吗?

    imageURLs = getActivity().getResources().getStringArray(R.array.image_urls);

    imageSlide = (SliderLayout) view.findViewById(R.id.gallery_slider);

    ArrayList<DefaultSliderView> slides = new ArrayList<DefaultSliderView>();

    for(int i = 0; i < imageURLs.length; i++){
        currentSlidePosition = i;

        DefaultSliderView slide = new DefaultSliderView(getActivity());
        slide.image(imageURLs[i]);

        //need width and height of image downloaded here

        slides.add(slide);
        imageSlide.addSlider(slide);

1 个答案:

答案 0 :(得分:2)

一种常见的方法是使用Picasso加载:

 Picasso.with(this).load("http://").into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            imgView.setImageBitmap(bitmap);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

        }
    });