栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Blackberry中显示URL中的图像

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Blackberry中显示URL中的图像

试试这个 -

URLBitmapField wmf= new  util.URLBitmapField("http://www.asianmirror.lk/english/images/stories/demo/hot_news/top_news/sanga1_latest.jpg")add(wmf);

// URLBitmapField类在下面给出-

public class URLBitmapField extends BitmapField implements URLDataCallback {EnpredImage result=null ;public static Bitmap myImage;public static EnpredImage _enpred_img=null ;int _imgWidth = 140;int _imgHeight = 140;int _imgMargin = 10;public URLBitmapField(String url) {    try {        http_image_data_extrator.getWebData(url, this);    }    catch (Exception e) {}}public Bitmap getBitmap() {    if (_enpred_img == null) return null;    return _enpred_img.getBitmap();}public void callback(final String data) {    if (data.startsWith("Exception")) return;    try {        byte[] dataArray = data.getBytes();        //bitmap = EnpredImage.createEnpredImage(dataArray, 0, dataArray.length);//no scale        _enpred_img = EnpredImage.createEnpredImage(dataArray, 0, dataArray.length); // with scale        _enpred_img = sizeImage(_enpred_img, _imgWidth, _imgHeight);    constants.image=_enpred_img;        //myImage=cropImage(_enpred_img.getBitmap());        setImage(_enpred_img);        UiApplication.getUiApplication().getActiveScreen().invalidate();    }    catch (final Exception e){}}public EnpredImage sizeImage(EnpredImage image, int width, int height) {      int currentWidthFixed32 = Fixed32.toFP(image.getWidth());      int currentHeightFixed32 = Fixed32.toFP(image.getHeight());      int requiredWidthFixed32 = Fixed32.toFP(width);      int requiredHeightFixed32 = Fixed32.toFP(height);      int scaleXFixed32 = Fixed32.div(currentWidthFixed32,        requiredWidthFixed32);      int scaleYFixed32 = Fixed32.div(currentHeightFixed32,        requiredHeightFixed32);      result = image.scaleImage32(scaleXFixed32, scaleYFixed32);      return result;}public class http_image_data_extrator {    static String url_="";    static StringBuffer rawResponse=null;    //static String result = null;         public static void getWebData(String url, final URLDataCallback callback) throws IOException {  //url_=url;      HttpConnection connection = null;        InputStream inputStream = null;     try {         if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)      && RadioInfo   .areWAFsSupported(RadioInfo.WAF_WLAN)) {  url += ";interface=wifi";         }         connection = (HttpConnection) Connector.open(url, Connector.READ, true);         String location=connection.getHeaderField("location");         if(location!=null){  if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)          && RadioInfo       .areWAFsSupported(RadioInfo.WAF_WLAN)) {      location += ";interface=wifi";  }  connection = (HttpConnection) Connector.open(location, Connector.READ, true);         }else{  connection = (HttpConnection) Connector.open(url, Connector.READ, true);}         inputStream = connection.openInputStream();byte[] responseData = new byte[10000];int length = 0;rawResponse = new StringBuffer();while (-1 != (length = inputStream.read(responseData))) {   rawResponse.append(new String(responseData, 0, length));}int responseCode = connection.getResponseCode();if (responseCode != HttpConnection.HTTP_OK){  throw new IOException("HTTP response pre: "+ responseCode);}         final String  result = rawResponse.toString();         UiApplication.getUiApplication().invokeAndWait(new Runnable() {    public void run(){      callback.callback(result);  }});       }       catch (final Exception ex) {UiApplication.getUiApplication().invokeLater(new Runnable() {    public void run() {        callback.callback("Exception (" + ex.getClass() + "): " + ex.getMessage());    }});       }    }}public interface URLDataCallback {    public void callback(String data);}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570209.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号