WebService, Android-dan rasm yaratish

Ya'ni, WebService-ga ulangan ushbu ilovam bor va u erda ma'lumotni allaqachon olaman, endi rasm aloqasini olishni istayman va imageView bu tasvirni havoladan oladi. Bu ham mumkinmi? Har qanday yordamni qadrlang: D

        @Override
    protected Void doInBackground(Void... params) {
        HttpHandler sh = new HttpHandler();

        String jsonStr = sh.makeServiceCall(url);
        Log.e(TAG, "Response from URL: " + jsonStr);

        if (jsonStr != null) {
            try {

                JSONArray array = new JSONArray(jsonStr);
                for (int i = 0; i < array.length(); i++) {

                    JSONObject jsonObject = array.getJSONObject(i);

                    JSONArray paises = jsonObject.optJSONArray("paises");

                    if (paises != null) {
                        for (int j = 0; j < paises.length(); j++) {
                            JSONObject jsonObject1 = paises.getJSONObject(j);
                            System.out.println(jsonObject1.optString("Designacao"));
                            String K_PAIS = jsonObject1.getString("K_PAIS");
                            String Designacao = jsonObject1.getString("Designacao");
                            String URL_IMAGE_SMALL = jsonObject1.getString("URL_IMAGE_SMALL");
                            String URL_IMAGEM = "http://something.something.pt" + URL_IMAGE_SMALL;

                            new DownloadImage(imageView6).execute(URL_IMAGEM);

                            HashMap pais = new HashMap<>();

                            pais.put("K_PAIS", K_PAIS);
                            pais.put("Designacao", Designacao);
                            pais.put("URL_IMAGE_SMALL", URL_IMAGE_SMALL);
                            pais.put("URL_IMAGEM", URL_IMAGEM);
                            listaPaises.add(pais);


                        }
                    }
                    System.out.println(jsonObject.optString("Designacao"));
                }



            } catch (final JSONException e) {
                Log.e(TAG, "Json parsing error: " + e.getMessage());
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Json parsin error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                    }
                });
            }
        } else {
            Log.e(TAG, "Couldn't get json from server.");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(), "Couldn't get json from server. Check LogCat for possible errpr!", Toast.LENGTH_LONG).show();
                }
            });
        }
        return null;



    }
{...}
public class DownloadImage extends AsyncTask {
    ImageView bmImage;

    public DownloadImage(ImageView bmImage) {
        this.bmImage = (ImageView) bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.d("Error", e.getStackTrace().toString());

        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
}
2
qo'shib qo'ydi muallif H4SN, manba

6 javoblar

Siz ajoyib rasm kutubxonasini Picasso dan foydalanishingiz mumkin.

Misol:

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

Gradle orqali qo'shilishni qo'shish:

compile 'com.squareup.picasso:picasso:2.5.2'
1
qo'shib qo'ydi

uchinchi tomon kutubxonasidan foydalanishni xohlamasangiz, buni sinab ko'ring.

 new DownloadImage(imamgeview).execute(url);

Async vazifasini yaratish

 public class DownloadImage extends AsyncTask {
    CircleImageView bmImage;

    public DownloadImage(ImageView bmImage) {
        this.bmImage = (CircleImageView) bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.d("Error", e.getStackTrace().toString());

        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
}

Umid qilamanki, u sizning ishingizda ishlaydi

0
qo'shib qo'ydi
Ha, siz haqsiz..
qo'shib qo'ydi muallif Nilesh Rathod, manba
uning ishi yoki sizning holatingizda emas ..........?
qo'shib qo'ydi muallif Nilesh Rathod, manba
kodingizni bu yerga joylashtirib qo'ying, men sizga yordam bera olaman
qo'shib qo'ydi muallif Nilesh Rathod, manba
Bu yerda urlni yoqing
qo'shib qo'ydi muallif Nilesh Rathod, manba
Ya'ni, "yangi DownloadImage (imamgeview) .execute (url)" da aniqlik kiritish uchun; «url» bog'lanish joyi saqlanadigan o'zgaruvchidir, to'g'rimi?
qo'shib qo'ydi muallif alb, manba
hech qanday dastur cho'kib ketmaydi ... Bu o'zgaruvchiga (URL_IMAGEM) jsonli String va men uni bajarishga qo'shaman (), lekin omad yo'q
qo'shib qo'ydi muallif alb, manba
Xabarni tahrirladim
qo'shib qo'ydi muallif alb, manba
URL manzilini tushintirmadingizmi?
qo'shib qo'ydi muallif alb, manba

step 1: create class named DownloadImage

public class DownloadImage extends AsyncTask {
    CircleImageView bmImage;

    public DownloadImage(ImageView bmImage) {
        this.bmImage = (CircleImageView) bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.d("Error", e.getStackTrace().toString());

        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
}

Step 2: execute AsyncTask

new DownloadImage(imgUserProfile).execute(userProfileUrl);

**Json Url like this: ** https://graph.facebook.com/1220130444748799/picture?height=400&width=400&migration_overrides=%7Boctober_2012%3Atrue%7D

0
qo'shib qo'ydi

Ilovangizda build.gradle qo'shing

compile 'com.github.bumptech.glide:glide:3.7.0'

urldan rasmni yuklash uchun ushbu koddan foydalaning

 Glide.with(getApplicationContext()).load("image_url").into(ImageView);
0
qo'shib qo'ydi

Siz o'zingizning ImageView-ni XML-da joylashtirishingiz kerak. Keyin Picasso yoki Glide .

0
qo'shib qo'ydi

har qanday uchinchi tomon kutubxonasidan foydalanishingiz mumkin namuna glide kutubxonasidan foydalaning

ushbu kutubxona url dan ImageView ga rasmni olib kelishga yordam beradi.

misol:

Glide.with(context).load(image_url).into(your_image_view);

here is link for that library : https://github.com/bumptech/glide

0
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb