Java 毕加索赢了';t加载图像(Android)
我正在尝试使用毕加索将图像加载到ImageView。最基本的东西 我知道这很简单,我很确定我做得很好,但由于某些原因,它不会起作用。我的应用程序中未显示任何照片。我发现有人有同样的问题(例如,这个),我的代码几乎与他们的固定版本完全相同,但仍然无法工作 这是我的密码 在MainActivity.java中,我有Java 毕加索赢了';t加载图像(Android),java,android,xml,Java,Android,Xml,我正在尝试使用毕加索将图像加载到ImageView。最基本的东西 我知道这很简单,我很确定我做得很好,但由于某些原因,它不会起作用。我的应用程序中未显示任何照片。我发现有人有同样的问题(例如,这个),我的代码几乎与他们的固定版本完全相同,但仍然无法工作 这是我的密码 在MainActivity.java中,我有 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(sav
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new MyFragment())
.commit();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ImageView image = (ImageView) rootView.findViewById(R.id.movie_image);
Picasso.with(getActivity()).load(Uri.parse("http://i.imgur.com/DvpvklR.png")).into(image);
return rootView;
}
在MyFragment.java中,我有
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new MyFragment())
.commit();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ImageView image = (ImageView) rootView.findViewById(R.id.movie_image);
Picasso.with(getActivity()).load(Uri.parse("http://i.imgur.com/DvpvklR.png")).into(image);
return rootView;
}
fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/movie_image" />
</FrameLayout>
任何建议都将不胜感激
编辑:Logcat
我以前在Logcat中收到毕加索的一些消息,但我再次检查,现在没有毕加索的日志。
它与另一个线程中的情况完全相同,该线程也有相同的问题,如下所示
02-23 16:41:36.857 28865-28865/com.example.enrico.prova D/Picasso﹕ Main created [R1] Request{http://www.online-image-editor.com//styles/2014/images/example_image.png}
02-23 16:41:36.858 28865-28884/com.example.enrico.prova D/Picasso﹕ Dispatcher enqueued [R1]+0ms
02-23 16:41:36.876 28865-29238/com.example.enrico.prova D/Picasso﹕ Hunter executing [R1]+16ms
02-23 16:41:36.883 28865-28884/com.example.enrico.prova D/Picasso﹕ Dispatcher batched [R1]+25ms for error
02-23 16:41:37.112 28865-28884/com.example.enrico.prova D/Picasso﹕ Dispatcher delivered [R1]+254ms
02-23 16:41:37.112 28865-28865/com.example.enrico.prova D/Picasso﹕ Main errored [R1]+255ms
更新:我知道了!这是因为我的应用程序中的目标sdk版本是23,而我的手机使用的是KitKat。当我将gradle中的依赖项更改为
compile'com.android.support:appcompat-v7:21.0.2'
而不是compile'com.android.support:appcompat-v7:23.1.1'
时,它就起作用了
再次感谢您的建议 试试看
Picasso.with(getActivity()).load("http://i.imgur.com/DvpvklR.png").into(image);
我认为您不需要解析Uri。尝试不使用
Uri。解析
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ImageView image = (ImageView) rootView.findViewById(R.id.movie_image);
Picasso.with(getActivity()).load("http://i.imgur.com/DvpvklR.png").into(image);
return rootView;
}
这是我的工作:
Picasso.with(getActivity())
.load("http://i.imgur.com/DvpvklR.png")
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.resizeDimen(R.dimen.list_detail_image_size,R.dimen.list_detail_image_size)
.centerInside()
.into(image);
它使用以下代码为我工作:
Picasso.with(this)
.load("http://i.imgur.com/DvpvklR.png")
.into(myImageView);
我不止一次使用过毕加索。
仅供参考:(PICU链接是一个JsonElement)
希望这能帮助你
这就是我构建方法的方式:
public void updatePic(JsonElement jsonObject){
Activity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
final ImageView imageUser=(ImageView)findViewById(R.id.user_profile_photo);
final Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
imageUser.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
imageUser.setTag(target);
Picasso.with(getApplicationContext())
.load(pic_link.getAsString())
.into(target);
}
});
}
主要错误在清单文件中
您应该更正:
致:
所有的图片都能用 我注意到,当我使用仿真器时,我看不到图像,并用一个简单的修复程序解决了它
确保使用https而不是http
https://image.tmdb.org/t/p/w185//2uNW4WbgBXL25BAbXGLnLqX71Sw.jpg
尝试在清单文件的应用程序标记中使用android:UseSlearTextTraffic=“true”
!当我用安卓截击面对同样的问题时 使用下面的链接
Picasso.Get().Load(imageUri).Placeholder(Resource.Drawable.patient_profile_pic).Resize(100, 100).Into(imgProflle);
没有插件
Xamarin或.Net
byte[] imageBytes;
using (var webClient = new WebClient())
{
imageBytes = webClient.DownloadData(imageUri);
}
Bitmap bitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
imgProflle.SetImageBitmap(bitmap);
加载(“)使用此功能感谢您的回复!我尝试过,但我的应用程序中仍然没有显示任何照片。代码中是否存在任何其他可能的缺陷?即使是相同的尝试,我也修改了帖子!如果您收到任何崩溃日志,您不会有任何损失让我知道吗?我尝试过,但我得到了错误照片。我在上面帖子的末尾添加了日志。您有厕所吗k请?非常感谢!您可以尝试以下配置:compileSdkVersion 23 buildToolsVersion'23.0.1'defaultConfig{minSdkVersion 15 targetSdkVersion 23}compile“com.android.支持:appcompat-v7:23.0.1“好吧,这真的很奇怪。所以我用相同的代码创建了另一个项目,只是为了尝试什么可行,什么不可行。在新的项目中,我尝试了更改前面提到的所有SDK版本配置,并且成功了。然后我试着改变你的建议,效果也不错。我还尝试将其更改回原来的版本(buildToolsVersion'23.0.2'和v7:23.1.1 lib等等),这次它以某种方式工作了。对于无法工作的旧项目,我尝试了为新项目工作的配置(SDKTarget21,…),但毕加索仍然无法加载。。我不知道发生了什么不幸的是这对我不起作用。。。代码中是否存在任何其他可能的缺陷?您是否收到任何崩溃日志?您是否能够加载任何图像,或者仅此图像有问题?对于未注意到错误的任何人,错误为characterr
,而不是s
,如果您添加了proguard规则,则建议在此加载。在我的例子中,毕加索在应用proguard规则后停止加载图像。解决了我的问题!我们切换到target sdk 28,从那以后,毕加索将不会通过HTTP加载图像。毕加索没有加载我的图像,这也解决了我的问题!