当我使用这段代码时,它只是用红色覆盖ImageLoadedListener并说它不能识别这样的方法。这是我第一次使用ImageMager,所以如果你能告诉我什么是错的,可以给我一个示例代码,我可以从中检查ImageManager的用法。还有一种方法可以保护设备上的图像,然后使用字符串或int(对于R.id.drawable)获取将来引用中的图像吗?
ImageView iv;
setContentView(R.layout.activity_main);
iv = (ImageView)findViewById(R.id.imageView);
ImageManager imageManager;
URI uri;
try {
uri = new URI("http://suburban-k9.com/wp-content/uploads/2011/03/small-dog-sydrome-300x300.jpg");
} catch (URISyntaxException e) {
e.printStackTrace();
uri=null;
}
Context context = getApplication().getApplicationContext();
imageManager = ImageManager.create(context);
Log.v("app", "LoadImageFromGoogle Manager created for Image #" + id);
imageManager.loadImage(new OnImageLoadedListener() {
@Override
public void onImageLoaded(Uri uri, Drawable drawable, boolean b) {
Log.v("app", "LoadImageFromGoogle Image loaded #" + id);
myBitmap = ((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
myBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Log.v("app", "LoadImageFromGoogle Image added #" + id);
}
},uri,android.R.drawable.btn_default);
iv.setImageBitmap(myBitmap);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}