- Как загрузить ImageView по URL-адресу в Android? [закрытый]
- 23 ответов
- Download image from url in android
- How to Google reverse image search on Android devices
- How to Google reverse image search on a PC
- Google reverse image search using Chrome
- Google Reverse image search by uploading an image with Chrome
- Google Lens
- Use Labnol.org
- Download the Search By Image app
- Learn2Crack
- Android Load Image from Internet (URL) – Example
- Download image from url in android
Как загрузить ImageView по URL-адресу в Android? [закрытый]
Как вы используете изображение, на которое ссылается URL в ImageView ?
23 ответов
убедитесь, что у вас есть следующие разрешения установить в свой AndroidManifest.xml для доступа в интернет.
сначала вам нужно загрузить изображение
затем используйте Imageview.setImageBitmap для установки растрового изображения в ImageView
1. Пикассо позволяет без проблем загружать изображения в вашем приложении-часто в одной строке кода!
Использовать Gradle:
только одна строка кода!
2. скольжения библиотека загрузки и кэширования изображений для Android, ориентированная на плавную прокрутку
использовать Gradle в:
// для простого просмотра:
3. фреска — это мощная система для отображения изображений в Android приложения.Fresco заботится о загрузке и отображении изображений, поэтому у вас нет к.
Я написал класс, чтобы справиться с этим, поскольку это, похоже, повторяющаяся потребность в моих различных проектах:
UrlImageViewHelper заполнит ImageView с найденным изображением по URL.
образец сделает Изображение Google Поиск и загрузка/показать результаты асинхронно.
UrlImageViewHelper будет автоматически загрузите, сохраните и кэшируйте все URL-адреса изображения в BitmapDrawables. Дубликаты url не будут загружаться в память дважды. Битовая память управляется используя слабую справочную хэш-таблицу, так что как только изображение больше не будет используется вами, это будет мусор собранные автоматически.
в любом случае люди просят мой комментарий опубликовать его в качестве ответа. я отправляю.
Источник
Download image from url in android
Step 1 : create DownloadImageToSDcardActivity
Step 2 : create layout activity_download_image_to_sdcard
public class DownloadImageToSDcardActivity extends AppCompatActivity <
protected void onCreate(Bundle savedInstanceState) <
mImageView1 = (ImageView) findViewById(R.id.image);
public Bitmap getBitmapFromURL(String src) <
java.net.URL url = new java.net.URL(src);
HttpURLConnection connection = (HttpURLConnection) url
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
> catch (IOException e) <
public void button2(View view) <
private class DownloadImageFromTherad extends AsyncTask <
protected String doInBackground(String. params) <
protected void onPostExecute(String s) <
File sdCardDirectory = Environment.getExternalStorageDirectory();
File image = new File(sdCardDirectory, «test.png»);
boolean success = false;
// Encode the file as a PNG image.
Toast.makeText(getApplicationContext(), «Image saved with success»,
«Error during image saving» + mSavedInfo, Toast.LENGTH_LONG).show();
private String saveToInternalStorage(Bitmap bitmapImage)<
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir(«imageDir», Context.MODE_PRIVATE);
File mypath=new File(directory,»profile.jpg»);
FileOutputStream fos = null;
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
> catch (Exception e) <
> catch (IOException e) <
// useful method for retrieving image from Internal memory
private void loadImageFromStorage(String path)
File f=new File(path, «profile.jpg»);
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
catch (FileNotFoundException e)
public void showImage(View view) <
// source used for downloading and showing image :Brijesh Thakur :
Источник
How to Google reverse image search on Android devices
Wondering how to do a Google reverse image search? It’s actually effortless to do. The process isn’t as straightforward when using an Android device, though. You will need to dig around to find the Google reverse image search function on a mobile device. This is why we have created a handy guide for you to skip the guesswork and get right to searching.
How to Google reverse image search on a PC
Google reverse image search was made for PC, which is likely why the process hasn’t been streamlined in smartphones, tablets, and other mobile devices. Therefore, the process is dead simple when done on a computer. Let’s run you through the steps.
- All you have to do is open a browser and visit images.google.com.
- Click on the small camera icon, and then paste the URL of an image or upload one from your computer.
- After that, click the search button and Google will show you all the websites that used that image, other sizes of the image, as well as images similar to the one you have searched for.
Google reverse image search using Chrome
The fastest and easiest way to perform a Google reverse image search on your Android device is by using Google’s Chrome browser. Let’s say that you’re browsing the web and you come across an interesting image you want to reverse search. Here’s what you need to do.
- Open Chrome and find an image you want to reverse search.
- Tap and hold on the image.
- Select the Search Google for this image option.
That’s all there is to it. Simple. But what if you are trying to search for an image you have stored on your phone?
Google Reverse image search by uploading an image with Chrome
The previous section only helps you perform a Google reverse image search if the image you want to look up is online. If you want to search for an image you have stored in your handset, you can do so using the desktop site on your smartphone’s Chrome browser. Here’s how to do it!
- Open Chrome and go to images.google.com.
- Click on the 3-dot menu button on the top-right.
- Check the Desktop site box.
- Click on the camera button to the right of the search box.
- Select the Upload an Image tab.
- Hit Choose file.
- Select the app you want to choose the file with.
- Find the file and tap on it.
- Let Google work its magic.
Google Lens
The next best way to perform a Google reverse image search through an official Google solution is using Google Lens. This app uses AR and Google’s immense data pool to analyze images, both live and stored on your device, and grant information about what it sees.
- Download Google Lens from the Google Play Store. Many phones already have it, and the service can be accessed from the camera app.
- Open the Google Lens app.
- You can point your camera at anything and press Search. If you want to analyze a specific image, hit the photo icon on the top-right corner.
- Select the image you want to search.
- Google Lens will show a series of results.
Use Labnol.org
Don’t feel like downloading apps or dealing with workarounds? You can use a third-party website that will automate the process. One of our favorites is Labnol.org. Let’s show you how to use it.
- Open your browser and go to www.labnol.org/reverse/.
- Hit the Upload image button.
- Select the image you want to search.
- The website will upload the photo and load for a bit.
- When done loading, you can click on the Show matching images button.
- The website will redirect you to a Google reverse image search of the same image you uploaded.
Download the Search By Image app
If you perform more than one Google reverse image search for images you have on your device, it’s probably best to download a dedicated app to save some time. One of the best ones you can use is Search By Image, which basically works the same way as Labnol.org — get it from the Play Store via the button below.
- Download the Search by Image app and launch it.
- Tap on the + icon in the bottom right corner.
- Select Image Gallery.
- Pick any image.
- Tap the search button.
- Let the app work its magic.
Источник
Learn2Crack
Android Load Image from Internet (URL) – Example
Sometimes you may need to load an Image from URL in your Android app. If you are searching for a way, this tutorial shows you how to do this with less effort.
Here I have created an Android Studio project with package com.learn2crack.loadimageurl also Activity as MainActivity and layout as activity_main.
Adding Required Permissions
We need to add Internet permission in our AndroidManifest.xml.
Our activity layout has a Button and an ImageView to display the image.
Loading image via the Internet is time-consuming and if done in the main thread it makes the UI unresponsive . So we use AsyncTask to do this in a background thread. The decodeStream() method of the BitmapFactory class is used to load the image. We create a Listener interface to pass the image to Main Activity. The onImageLoaded() method will be called if the image is fetched successfully. The onError() method will be called if an error occurs.
The MainActivity implements the Listener interface. The fetched bitmap is set to ImageView using setImageBitmap() method. If an error occurs a Toast is displayed.
Try this in an Emulator or your own device.
Complete Project Files
You can download the complete project as zip or fork from our Github repository.
Note :
Last Updated On : Oct 15, 2016
Источник
Download image from url in android
Step 1 : create DownloadImageToSDcardActivity
Step 2 : create layout activity_download_image_to_sdcard
public class DownloadImageToSDcardActivity extends AppCompatActivity <
protected void onCreate(Bundle savedInstanceState) <
mImageView1 = (ImageView) findViewById(R.id.image);
public Bitmap getBitmapFromURL(String src) <
java.net.URL url = new java.net.URL(src);
HttpURLConnection connection = (HttpURLConnection) url
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
> catch (IOException e) <
public void button2(View view) <
private class DownloadImageFromTherad extends AsyncTask <
protected String doInBackground(String. params) <
protected void onPostExecute(String s) <
File sdCardDirectory = Environment.getExternalStorageDirectory();
File image = new File(sdCardDirectory, «test.png»);
boolean success = false;
// Encode the file as a PNG image.
Toast.makeText(getApplicationContext(), «Image saved with success»,
«Error during image saving» + mSavedInfo, Toast.LENGTH_LONG).show();
private String saveToInternalStorage(Bitmap bitmapImage)<
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir(«imageDir», Context.MODE_PRIVATE);
File mypath=new File(directory,»profile.jpg»);
FileOutputStream fos = null;
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
> catch (Exception e) <
> catch (IOException e) <
// useful method for retrieving image from Internal memory
private void loadImageFromStorage(String path)
File f=new File(path, «profile.jpg»);
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
catch (FileNotFoundException e)
public void showImage(View view) <
// source used for downloading and showing image :Brijesh Thakur :
Источник