modify universal-image-loader - java

I am using this project universal-image-loader in order to display in a gridview several images. But I would like to modify these images with some html (for example add ads at the bottom of each images).
I saw the image are displayed by calling imageLoader.displayImage(..), in the method getView of the ImageAdapter.
I don't know what approach is better:
add a step in displayImage(...) in order to create a webview with my image and html and transform this webview in bitmap?
modify the getView of ImageAdapter which will create the webview and add an argument webview in displayeImage()?
...
...
I guess I don't have the choice, I have to use a webview.
Moreover in the method displayImage() of ImageLoader.java, i don't understand where the images are loaded, I guess this is somewhere in this line, but when I am looking in these methods I can't find/understand
ImageSize targetSize = getImageSizeScaleTo(imageView);
String memoryCacheKey = MemoryCacheUtil.generateKey(uri, targetSize);
cacheKeysForImageViews.put(imageView.hashCode(), memoryCacheKey);
Bitmap bmp = configuration.memoryCache.get(memoryCacheKey);
(How from a string built by an uri and ImageSize we can have a bitmap? where is the image?)

Images are loaded asynchronously. So your code piece is just a top of complex logic. Main work is done in LoadAndDisplayTask class but you don't need to touch it.
For your case you can create own BitmapDisplayer:
create BitmapDisplayer implementation
implement Bitmap display(Bitmap bitmap, ImageView imageView) method
in this method you can process incoming Bitmap as you want
set result Bitmap in ImageView and return result
Set your BitmapDisplayer into configuration.

Related

How can I get the ID from an image from camera or internal storage to put into Android EasySlider?

I'm programming a new app for my city and I need help with some code. I'm using the EasySliders library for Android, and I need to put images taken from either the camera or internal storage.
I could put them in ImageViews, but I want to put them into a slider. EasySlider needs 2 parameters:
A title for the image
An ID
How can I get the id from those pictures?
Bitmap bitmap;
bitmap = BitmapFactory.decodeFile(dir);
// Here is the problem, the bitmap is not an id and it causes an error
easySliders.add(new SliderItem("temporalname", bitmap));

Loading Database Image in List App is Stuck

I have save image path in database and image save in folder. Displaying image in list view app is stuck and slow. I not understand how to resolve this issue.
I am using following code:
strContactImage = customer.getPhotoPath();
Bitmap decodedImage = BitmapFactory.decodeFile(strContactImage);
customerImage.setImageBitmap(decodedImage);
customer.getPhotoPath() gets folder photo path image, and displays it properly, but when I added more than 20 records app slows down, and gets stuck.
Use uri to set image into image view instead of decoding into bitmap...
strContactImage = customer.getPhotoPath();
Uri uri=Uri.fromFile(new File(strContactImage));
// Set the uri into ImageView
customerImage.setImageURI(uri);
It might help you...
You can use any image caching library, here is the example of Picasso
strContactImage = customer.getPhotoPath();
Picasso.with(context)
.load(new File(strContactImage))
.into(customerImage);
check the size of the images they can effect the memory and make the app stuck and slow if they are take a lot of memory !
to fix that
take a look here
Load a Scaled Down Version into Memory
and check the method calculateInSampleSize() and decodeSampledBitmapFromResource()
it’s not worth loading a 1024x768 pixel image into memory if it will eventually be displayed in a 128x96 pixel thumbnail in an ImageView.
and you can use library that can help you to load image and they will take care about the memory usage and loading the image into Your View
Library :
Picasso
example :
Picasso.with(context).load(file).into(imageview);
Glide
example :
GlideApp.with(context).load(file).into(imageview);
Tools - check this for more about :
TinyPNG - Smart PNG and JPEG compression
Optimizilla

Efficient and fast way to encode images to Video/GIF in Android

I'm trying to make a video out of viewshots in an app.
I have succeeeded to get the images as Bitmaps using this code.
public Bitmap getScreenShot() {
View screenView = findViewById(R.id.button);
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
return bitmap;
}
I have encode images using SequenceEncoder like this :
for(Bitmap bitmap : bitmaps)
sequenceEncoder.encodeImage(bitmap);
I have got it working and got the file but it takes a lot of time.
I have also tried to use MediaMuxer(I used EncodeDecode) but failed to even get a video, I have tried to make a GIF(using AnimatedGifEncoder) but a lot of time too. I want a way to make this video in a very short time.

Android - Place fragment over ImageView PROGRAMMATICALLY (NO XML)

I have to add a fragment over an Imageview, but my ImageView goes on top and covers the other views. All this is done in a RelativeLayout.
things must be done dynamically (no xml). I want that my activity has an image, which can be set DYNAMICALLY, and my fragment (added dynamically) should have transparent background, and if this is not true, i can set it to transparent at run time.
This is the code to create the image:
ImageView img=new ImageView(this);
img.setImageResource(imgID);
img.setScaleType(ImageView.ScaleType.CENTER_CROP);
((ViewGroup)findViewById(android.R.id.content)).getRootView()).addView(img);
As you can see, the image works as background, i'm using a ImageView for its scaleType.
Is there a way to do so?
SOLUTION
solved, i added the image to the wrong container.
The function below, however, has been pretty useful. It has been taken from an other answer, and lets a view to get on the back of all the others.
public static void sendViewToBack(View child) {
final ViewGroup parent = (ViewGroup)child.getParent();
if (parent!=null) {
parent.removeView(child);
parent.addView(child, 0);
}
}

Android: Changing Wallpaper to Drawable

I'm using this code to change the wallpaper of the android home
WallpaperManager wm = WallpaperManager.getInstance(this);
wm.setBitmap(myBitmap);
I would like to set the background to a drawable. Is this possible?
You'll first have to convert the Drawable to a Bitmap. How to do this I found here. You'll need to use the BitmapFactory class, specifically the decodeResource() method.
Simply pass in the Resources and the Resource ID as parameters, like so:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.my_drawable);
wm.setBitmap(bmp);

Categories

Resources