在我中,ProfileFargment.java
我正在创建用户的个人资料。现在,它具有个人资料图片(来自用户的Google个人资料图片)和横幅图片。我制作了一个按钮,该按钮基本上允许用户更改其横幅图片,但只能加载某些图像。我不知道这是否与图像的大小有关...这是我使用的代码:
纽扣
btnEditarFotoCapa.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openGallery(); // Chama a função para abrir a galeria
}
});
意图
private void openGallery(){
Intent gallery = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGES);
}
检索图库图片
// Caso a galeria tenha sido aberta, aplica a imagem na foto de capa
//
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == getActivity().RESULT_OK && requestCode == PICK_IMAGES){
imageUri = data.getData();
ImageView imgFotoCapa = getActivity().findViewById(R.id.imgFotoCapa);
Picasso.with(getContext()).load(imageUri).resize(446, 203).into(imgFotoCapa);
/* SharedPreferences myPrefs = getContext().getSharedPreferences("FotoCapa", Context.MODE_PRIVATE);
SharedPreferences.Editor myPrefsEdit = myPrefs.edit();
myPrefsEdit.putString("fotoCapa", imageUri.toString());
myPrefsEdit.commit(); */
}
}
我最近像您一样使用了Picasso库,但遇到了类似的问题。之所以未加载某些图片,是因为它们的尺寸较大。由于某些缓存问题,毕加索在下载大图像时会遇到一些问题。
这里是这个问题的一个例子GitHub Picasso Large Image Issue
ImageRequest示例
RequestQueue rq = Volley.newRequestQueue(context);
ImageRequest request = new ImageRequest(link, new
Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
setBackground(context,bitmap);
}
}, 0, 0, null, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Log.e("VolleyImage",error.toString());
}
});
rq.add(request);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句