Issue 1:
Glide Version: 4.6.0

Integration libraries: okhttp3-3.9.1

Update to 4.6.0, I got this issue.

Error:(10, 2) error: incompatible types: GlideModule cannot be converted to Annotation @GlideModule() ^

My Project used exteneded 'AppGlideModule' class.

What can I do this situation?

import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.ExternalCacheDiskCacheFactory
import com.bumptech.glide.load.engine.cache.LruResourceCache
import com.bumptech.glide.module.AppGlideModule

@GlideModule
class GlideModule : AppGlideModule(){
override fun applyOptions(context: Context, builder: GlideBuilder) {
builder.setDiskCache(ExternalCacheDiskCacheFactory(context, "cache", DISK_CACHE_SIZE))
.setMemoryCache(LruResourceCache(cacheSize.toLong()))
}

override fun isManifestParsingEnabled(): Boolean {
return false
}

companion object {
private val maxMemory = (Runtime.getRuntime().maxMemory() / 1024).toInt()
private val cacheSize = maxMemory / 8
private val DISK_CACHE_SIZE = 1024 * 1024 * 10
}
}

Issue 2:
Hi, we had issue on android where when taking pictures and saving the image, and sending it to our server, image is flipped on android, ios and web applications that we use to view the image. So we tried simple target with glide in hopes that when saving the image locally before sending to server, glide would work its magic and image would be in correct orienation. This does not happen, Here is what we did:

Take the picture and save the image in temporary location.

Pass the image uri into glide and resave the image again

Send final glide image to server

QUESTIONS:

Do i need to save the image twice? or is it possible for glide to load the taken photo from memory without having to temporarily save the file in order to obtain a file path location?

Is it possible to use simple targets to automatically put images in correct rotation when saving image to local storage? Images will be displayed on web, other social media outlets, android and ios app. So they need to be correctly oriented before sending to our server

If number 2 is not possible are there any advantages of saving the image file with Glide Simple Targets?

Please see my attached code

private class CameraPhotoImageTask extends AsyncTask<String, Void, Bitmap> {
int h=0;
int w=0;
private File imageFile = null;
private File temporaryImageFile = null;

public CameraPhotoImageTask() {
}

protected Bitmap doInBackground(String... urls) {
/* Image taken is represented into byte array and passed into "urls" array.
We will first convert byte array from urls[] into bitmap image called "loadedImage" */
//
Bitmap loadedImage = null;
byte[] decodedString = android.util.Base64.decode(urls[0], android.util.Base64.DEFAULT);
loadedImage = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

// Get the height and width of loadedImage. We will need this to pass into Glide
w = loadedImage.getWidth();
h = loadedImage.getHeight();
Log.i("Test", "Chosen resolution: " + w + ", " + h);

/*Here we will temporarily save the bitmap image(loadedImage) into a temporary file and directory
so that we can pass it to glide for processing. */
try {
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
loadedImage.compress(CompressFormat.JPEG, 70, ostream);
temporaryImageFile = makeFilewithDir(AppTools.PHOTO_DIR,temporaryImageFile);

if (temporaryImageFile == null) {
Toast.makeText(getBaseContext(), "Image Not saved",
Toast.LENGTH_SHORT).show();
}

FileOutputStream fout = new FileOutputStream(temporaryImageFile);
fout.write(ostream.toByteArray());
fout.close();

}catch (Exception e) {
e.printStackTrace();
}

/*Now we need to get the directory path of the temporary image file and represent it as a uri
before loading it into glide for processing */
final File tempFile = new File(temporaryImageFile.getPath().toString());
Uri imageUri = Uri.fromFile(tempFile);
Log.i("Test", "loaded image is " +imageUri);

// Now we can pass the imageURI file path into Glide and process the image into a newBitmap from Glide
//WARNING!!!!: Glide .into does not work on background thread. So we need to put it into UI thread before calling .into
CameraDemoActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
final File tempFile = new File(temporaryImageFile.getPath().toString());
Uri imageUri = Uri.fromFile(tempFile);
//Pass imageUri into Glide
Glide.with(getApplicationContext())// Need to use Application Context
.load(imageUri)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.centerCrop()
.into(new SimpleTarget<Bitmap>(w, h) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
/*Assign the newly converted bitmap to newImageFromGlide then save the location of the bitmap
to our local database. Reminder: Need to delete the temporaryImageFile once newBitmap from
Glide is saved will handle this later*/
try {
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
Bitmap newImageFromGlide = bitmap;
newImageFromGlide.compress(CompressFormat.JPEG, 70, ostream);

imageFile = makeFilewithDir(AppTools.PHOTO_DIR, imageFile);

if (imageFile == null) {
Toast.makeText(getBaseContext(), "Image Not saved",
Toast.LENGTH_SHORT).show();
}
FileOutputStream fout = new FileOutputStream(imageFile);
fout.write(ostream.toByteArray());
fout.close();
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATE_TAKEN,
System.currentTimeMillis());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.MediaColumns.DATA,
imageFile.getAbsolutePath());

CameraDemoActivity.this.getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

//We need to load the image into the active status and set local database parameters for the image
Log.i("Test", "loaded image is " +"Now we are taking");
Cursor activeStatus = myStatus.getActiveStatus();
if (activeStatus.getCount() > 0) {
activeStatus.moveToFirst();
final int id = activeStatus.getInt(activeStatus.getColumnIndex(myStatus.COLUMN_ID));
MyStatusMediaDB.insertMedia(id, 1, imageFile.getPath().toString(), "", 0, "", "");
}
activeStatus.close();
if (newImageFromGlide != null) {
newImageFromGlide.recycle();
newImageFromGlide = null;
}

CameraDemoActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
captureImage.setEnabled(true);
}
});
} catch (Exception e) {
e.printStackTrace();
CameraDemoActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
captureImage.setEnabled(true);
}
});
}

CameraDemoActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
captureImage.setEnabled(true);
}
});
}}); //End of Glide
}
});