38 lines
874 B
Java
38 lines
874 B
Java
|
|
package com.util;
|
||
|
|
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.io.InputStream;
|
||
|
|
import java.net.HttpURLConnection;
|
||
|
|
import java.net.MalformedURLException;
|
||
|
|
import java.net.URL;
|
||
|
|
|
||
|
|
import android.graphics.Bitmap;
|
||
|
|
import android.graphics.BitmapFactory;
|
||
|
|
|
||
|
|
public class BitMapUtil {
|
||
|
|
public static Bitmap generateBitMap(String url) throws IOException {
|
||
|
|
URL myFileUrl = null;
|
||
|
|
Bitmap bitmap = null;
|
||
|
|
myFileUrl = new URL(url);
|
||
|
|
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
|
||
|
|
conn.setDoInput(true);
|
||
|
|
conn.connect();
|
||
|
|
InputStream is = conn.getInputStream();
|
||
|
|
bitmap = BitmapFactory.decodeStream(is);
|
||
|
|
is.close();
|
||
|
|
conn.disconnect();
|
||
|
|
return bitmap;
|
||
|
|
}
|
||
|
|
public static Bitmap byteToBitmap(byte[] b){
|
||
|
|
if(b==null){
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
int len=b.length;
|
||
|
|
if(len!=0){
|
||
|
|
return BitmapFactory.decodeByteArray(b, 0,len);
|
||
|
|
}else{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|