我正在使用Picasso从URL中提取jpg,然后附加到EditText。可以看出我使用Target方法将URL中的图像输入到我的Drawable中,然后将其附加到我的EditText。但是,会发生错误:
The method BitmapDrawable(Resources, Bitmap) is undefined for the type new Target(){}
位置:
BitmapDrawable(getBaseContext().getResources(), bitmap);
出现什么问题?如何为我的操作正确配置此Target类实现?
附加到EditText的方法:
public void appendToMessageHistory(final String username,
final String message) {
if (username != null && message != null) {
Picasso.with(getBaseContext()).load("http://localhost:3000/uploads/campaign/image/2/2.jpg").into(new Target() {
@Override
public void onPrepareLoad(Drawable arg0) {
}
@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
Drawable drawImage = BitmapDrawable(
getBaseContext().getResources(), bitmap);
messageHistoryText.append(Html.fromHtml("<b>" + username
+ ":" + "</b>" + "<br>"));
messageHistoryText.append(Html.fromHtml(message + "<hr>"
+ "<br>")
+ System.getProperty("line.separator") + "");
messageHistoryText.append(Html.fromHtml("<img src = '"
+ drawImage + "'/>", imageGetter, null));
}
@Override
public void onBitmapFailed(Drawable arg0) {
}
});
}
}
答案 0 :(得分:1)
我怀疑您在new
之前忘记了BitmapDrawable
关键字。
Drawable drawImage = BitmapDrawable(
getBaseContext().getResources(), bitmap);
应该是
Drawable drawImage = new BitmapDrawable(
getBaseContext().getResources(), bitmap);