所以,这里是东西。我通过WebService的接收到的ImagePath。我存储在字符串中的ImagePath。现在我想字符串为位图,并在ImageView的显示图像进行转换。我试过很多codeS从互联网的例子,但都没有工作。
So, here is the thing. I am receiving an imagepath through WebService. I am storing the imagepath in a String. Now I want to convert the String to Bitmap and display the image in an imageView. I tried many codes from the examples in the internet but are not working.
尝试1:
Bitmap bm = BitmapFactory.decodeFile(imagelogo);
imageView2 = (ImageView) findViewById(R.id.imageView2);
imageView2.setImageBitmap(bm);
尝试2:首先,我将串来串的Base64,然后串的Base64为位图
Try 2: First I am converting String to string Base64 and then string Base64 to Bitmap.
byte[] data;
String base64;
{
try {
data = imagelogo.getBytes("UTF-8");
String base64 = Base64.encodeToString(data, Base64.DEFAULT);
Log.i("Base 64 ", base64);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public Bitmap StringToBitMap(String encodedString){
try {
byte [] encodeByte=Base64.decode(base64 ,Base64.DEFAULT);
Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
return bitmap;
} catch(Exception e) {
e.getMessage();
return null;
}
}
任何帮助将是AP preciated。先谢谢了。
Any help would be appreciated. Thanks in advance.
哦,上帝,你不能转换图像的路径字符串转换成位图!图像路径不是图像本身! 您需要通过图像路径从互联网上下载的图片,并将其存储到本地文件。在你需要调用这样的:
Oh God, you can't convert a String of image path into a Bitmap! The image path isn't the image itself! You need to download the image from internet through the image path and store it into a local file. The you need to call this:
Bitmap bm = BitmapFactory.decodeFile(localImagePath);
加载图像。