I am trying to implement an Android image filter library called GPUImage Located here.
I have tried to use it like below
public static GPUImageView img_bg;
img_bg = (GPUImageView) findViewById(R.id.img_bg);
categoryAdapter1.setOnClickLIstner(new OnClickLIstner() {
#Override
public void onClick(View v, Image image, int pos) {
Glide.with(NameArt.this)
.load(image.getDrawableId())
.centerCrop()
.dontAnimate()
.into(img_bg);
img_bg.setVisibility(View.VISIBLE);
}
});
But I am getting error like below
cannot resolve method 'into' (jp.co.cyberagent.android.gpuimage.GPUImageView)
I am unable to solve it because I am learning android and java yet. Let me know if any expert here can help me for solve the issue. Thanks
Ensure you are using right version of Glide your GPUImageView can deal with. Recent v4 brings API changes that are not backward compatible and since this lib you are using looks bit rusty and does not set properly dependencies, you got the clash. Enforce v3 of Glide, or drop dated library.
try this to load image in your GPUImage
new DownloadImage(img_bg).execute(url);
create a Async Task
public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
GPUImageView bmImage;
public DownloadImage(GPUImageView bmImage) {
this.bmImage = (GPUImageView ) 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);
}
}
i hope that it will work in your case
Related
I've started to face an issue with Glide Image Download.
My application is running on Glide version 4.8.0 and minSdkVersion 21, targetSdkVersion 26, and compileSdkVersion 28.
The problem is Glide is unable to download an image from Apple News and causes it to lock and crash application. The URL of the image is https://c.apple.news/AgEXQU9SSmFycEhYUUVlSkxKUE52XzN1M1EAMA
The code to execute the image download is:
Glide.with(context)
.setDefaultRequestOptions(getRequestOptionsForImage(item.ContentPersonStatusUpdate.widthURLImageWidth,context.getResources().getDimensionPixelSize(R.dimen.image_height_external_link),context))
.asBitmap()
.load(https://c.apple.news/AgEXQU9SSmFycEhYUUVlSkxKUE52XzN1M1EAMA)
.into(imageViewContent);
public static RequestOptions getRequestOptionsForImage(int width, int height, Context context){
return new RequestOptions().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).override(width,height).placeholder(context.getDrawable(R.drawable.ic_news_thumbnail_loading));
}
Any idea/solution about this issue? This problem only occurs for Apple News Image URLs.
***UPDATE
I've tried to download image with the code below. Getting no responses, even catch never firing.
new DownloadImageTask(imageViewContent).execute(https://c.apple.news/AgEXQU9SSmFycEhYUUVlSkxKUE52XzN1M1EAMA);
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap bmp = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
bmp = BitmapFactory.decodeStream(in);
} catch (Exception e) {
e.printStackTrace();
}
return bmp;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
Serkan your code is correct except the request option part.
i try below code and worked fine:
String url="https://c.apple.news/AgEXQU9SSmFycEhYUUVlSkxKUE52XzN1M1EAMA";
RequestOptions requestOptions = new RequestOptions();
requestOptions.error(R.drawable.img_placeholder);
Glide.with(context)
.setDefaultRequestOptions(requestOptions)
.load(url)
.into(imgImage);
i try your code too without request option like below:
Glide.with(context)
.asBitmap()
.load(url)
.into(imgImage);
and worked fine too
when i try to use with your request option code its tell me use #RequiresApi(LOLLIPOP) annotation. may you are testing app in below api and the method doesn't work.
I'm trying to load some images from my server to New App, but i don't have any result :
This is my MainActivity code :
import java.io.InputStream;
import static android.net.Uri.parse;
public class MainActivity extends Activity {
private ImageView iv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DownloadImageTask((ImageView)findViewById(R.id.loadimg)).execute(getString(R.string.link));
private class DownloadImageTask extends AsyncTask<String,Void,Bitmap>{
private final ImageView bmImage;
ImageView bmImg;
public DownloadImageTask (ImageView bmImage){
this.bmImage=bmImage;
}
protected Bitmap doInBackground (String...urls){
String underplay = urls[0];
Bitmap mIcon11 =null;
try {
InputStream in =new java.net.URL(underplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e){
Log.e("Error",e.getMessage());
e.printStackTrace();
}
return mIcon11 ;
}
}
The Result in emulator is not appear any thing just my Button ?
Add the following dependency to your build.gradle file under app:
dependencies {
compile 'com.squareup.picasso:picasso:2.3.2'
}
Then in your code you can simply load a bitmap or image from a server like so:
Picasso.with(this)
.load(IMAGE_URL)
.into(yourImageView);
Where this is the activity context. IMAGE_URL is the url of the image, example: http://yourapi.com/image_1034.png, and yourImageView is the ImageView, ImageButton, or other Custom View where you want to upload the image into.
Doing it this way is considered best practice, and reduces a lot of the boilerplate code you've written. Try building a scalable app writing AsyncTasks for every time you upload a Bitmap.
In your AsyncTask you need to implement:
protected void onPostExecute(Bitmap icon) {
iv.setImageBitmap(icon)
}
Can you try this code?
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.image);
I have an Android application that loading some information and one picture like a blog, but sometimes I got duplicates picture, I don't know what is the problem, but sometimes it works good.
Someone here can help me ?
Here's the code below:
"endereco" is the URL of picture and "view" is the context that I pass on the class that extends activity"
public void loadImg(final View view , final String endereco){
Thread nova = new Thread()
{
public void run() {
Bitmap img = null;
try
{
URL url = new URL(endereco);
HttpURLConnection conexao = (HttpURLConnection) url.openConnection();
InputStream input = conexao.getInputStream();
img = BitmapFactory.decodeStream(input);
Log.i("Funcionou","Foto: " + endereco);
} catch (Exception ex){
Log.i("Erro",ex.toString());
}
final Bitmap imgAux = img;
handler.post(new Runnable() {
#Override
public void run() {
ImageView imageView = (ImageView) view.findViewById(R.id.txtfoto);
imageView.setImageBitmap(imgAux);
}
});
}
};
nova.start();
nova.currentThread().interrupt();
}
If you are downloading an image from a wbepage or server i wouldnt do it in a thread give it its own AsyncTask it gives you a whole load of methods that allow you to better control over what you are downloading and what to do with it after it has been downloaded.
Check out the Android dev Docs http://developer.android.com/reference/android/os/AsyncTask.html
So I am using Picaso to load some images and cache them like so:
ImageView logo = (ImageView)findViewById(R.id.image_logo);
Picasso.with(VenueDetailsActivity.this).load(url).into(logo);
However, I have other images that should not be cached. However, it seems like as soon as Picaso is running in any point in the app, then it starts caching all images no matter if I use Picaso loading on them or not.
How can I not cache certain images using Picasso?
** Does Picasso setups your app that any image loading is cached regardless of using Picasso or not?**
The method I use to download my images are:
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = 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.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
If you don't want Picasso to cache an image you can use .skipMemoryCache() like so:
Picasso.with(VenueDetailsActivity.this).load(url).skipMemoryCache().into(logo);
For more information you can view the documentation here
I am downloading images in background for a list. I have noticed that even with AsycTask the scrolling is not smooth. After some hours of debugging, I have came to conclusion that the InputStream is the guilty one.
doInBackground should be working on a non-ui thread, then why does it impact the UI?
If I comment out the InputStream code, the scrolling is smooth.
I have 3 images in a row, so usually 3 images are loaded at the same time.
class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
final WeakReference<ImageView> imageViewReference;
public BitmapWorkerTask(ImageView imageView) {
// Use a WeakReference to ensure the ImageView can be garbage collected
imageViewReference = new WeakReference<ImageView>(imageView);
}
// Decode image in background.
#Override
protected Bitmap doInBackground(String... params) {
InputStream is = null;
try {
is = (InputStream) new URL(params[0]).getContent();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
// Once complete, see if ImageView is still around and set bitmap.
#Override
protected void onPostExecute(Bitmap bitmap) {
// REMOVED ON PURPOSE TO CONFIRM THAT INPUTSTREAM IS GUILTY
}
}