我们正在为Android大学开发一个私人社交媒体应用程序。但是,我目前的Android App渲染图像速度非常慢。需要约。 5秒的图像出现,在这个时代,它的罪犯。
我们尝试了不同的选项,而我们当前的Android开发人员无法解决这个问题。谁能建议其他选择? 以下是我们迄今为止所做的工作。
前期几个问题: 1.我们在哪里弄乱这个过程?请指教 2.缩略图的大小是否正确? 3.有关Java库以便在发送到后端服务器之前压缩图像(无损)的建议
以下是我们遵循的步骤
1. Compress the image from device before sending to server via API - We are doing this for jpeg only. Need to do this for .PNG
AFAIK, this is the code used. As I am not an Android developer, I am not sure this is complete.
*Bitmap scaledBitmap = ImageCompression.compressImage(1328.0f, 1771.0f, sourceFile.getAbsolutePath());
FileOutputStream out = new FileOutputStream(destFile);
if (null != scaledBitmap)
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);
return destFile;
public static File getCompressedImage(File srcFile, File destFile) throws FileNotFoundException {
Bitmap scaledBitmap = ImageCompression.compressImage(1328.0f, 1771.0f, srcFile.getAbsolutePath());
FileOutputStream out = new FileOutputStream(destFile);
if (null != scaledBitmap)
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);
return destFile;
}
######### Used this code to do compression - https://gist.github.com/walteranyika/2db99439225a82d2c1497e6ab61a8a3d #################### ImageCompression.Java ######## Relevant parts are pasted here.
*Canvascanvas=null;
if(scaledBitmap!=null){
canvas=newCanvas(scaledBitmap);
canvas.setMatrix(scaleMatrix);
canvas.drawBitmap(bmp,middleX-bmp.getWidth()/2,middleY-bmp.getHeight()/2,newPaint(Paint.FILTER_BITMAP_FLAG));
}**
2. Server is creating thumbnails using thumbnilator
a. We are creating 4 sized thumbnails for 4 phone sizes with size less than 100 KB by reducing quality
i. All Portrait images and all width * height and in DP
ii. Small - 150 * 150
iii. Medium - 200 * 200
iv. Large - 210 * 420
v. X-Large - 500 * 640
3. Enabled BucketAccelerateConfiguration in AWS
4. Thumbnails along with original image is sent to target device from server via API
5. Using a combination of Glide and Picasso libraries to display thumbnails and original image in the backend
a. If thumbnails are empty, we are displaying original URL
b. If the thumbnails are available, we are displaying Thumbnail till original image is displayed
*if(TextUtils.isEmpty(thumbUrl)){
GlideApp.with(getContext())
.load(imageUrl)
.placeholder(R.drawable.image_placeholder)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.dontAnimate()
.dontTransform()
.into(imageView);
}else{
Picasso.with(context.getApplicationContext())
.load(thumbUrl)//thumbnailurlgoeshere
.placeholder(R.drawable.image_placeholder)
.resize(AppConstants.IMAGE_SIZE,AppConstants.IMAGE_HEIGHT)
.transform(HomeActivity.blurTransformation)
.into(imageView,newCallback(){
@Override
publicvoidonSuccess(){
Picasso.with(context.getApplicationContext())
.load(imageUrl)//imageurlgoeshere
.placeholder(imageView.getDrawable())
.into(imageView);
}
@Override
publicvoidonError(){
GlideApp.with(getContext())
.load(imageUrl)
.placeholder(R.drawable.image_placeholder)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.dontAnimate()
.dontTransform()
.into(imageView);
}
});
}
}*
答案 0 :(得分:0)
尝试使用Androids ThumbnailUtils并根据您的要求生成所选图像的缩略图,然后将其转换为位图并进行设置。
效果更快。
您可以在此处获取有关ThumbnailUtils的所有信息, https://developer.android.com/reference/android/media/ThumbnailUtils.html