0
我的服務器向我的android設備發送一個編碼的Base64字符串。之後,我在這個方法中解碼Base64字符串來繪製它。當我將它添加到Itemizedoverlay中時,我看不到圖像。如何解碼android中Base64編碼的jpeg圖像並在ImageView上看到它?
public Drawable seticon(String input){
byte[] b = Base64.decode(input, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(b, 0, b.length);
Drawable drawable = new BitmapDrawable(decodedByte);
drawable.setBounds(0, 0, 50, 50);
return drawable;
}
public void setphotopoint(String input){
Drawable drawable = seticon(input);
PhotoOverlay aPhotoOverlay = new PhotoOverlay(drawable, this);
OverlayItem overlayitem = new OverlayItem();
overlayitem.setMarker(drawable);
aPhotoOverlay.addOverlay(overlayitem);
overlays.add(aPhotoOverlay);
}
這是我PhotoOverlay的類
public class PhotoOverlay extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
Context mContext ;
public PhotoOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
this.mContext = context;
}
public PhotoOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
}
protected boolean onTap(int index) {
return true;
}
public void addOverlay(OverlayItem overlay) {
items.add(overlay);
//setLastFocusedIndex(-1);
populate();
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return items.get(i);
}
public void clear() {
items.clear();
populate();
}
public void removeOverlay(OverlayItem overlay) {
items.remove(overlay);
populate();
}
@Override
public int size() {
// TODO Auto-generated method stub
return items.size();
}
}
將二進制轉換爲Base64,這是否意味着我可以將jpeg轉換爲二進制>> Base64而不轉換爲位圖?如果是這樣,那太棒了! – 2013-02-12 19:00:21