我正在getiing一個頁面的xml內容,並解析從這個XML的所有圖像Url的URL。 然後,我使用位圖將圖像顯示在imageviwer中。此外,我需要該圖像用於我的下一個版面設計。如何存儲圖像以供進一步使用,如果能夠如何操作,我可以將圖像存儲在可繪製文件夾中。我剛纔提到在下面,我需要保存的ImageView內容繪製文件夾中的代碼..Inputstream無法連接到一個URL
protected Void doInBackground(String... params) {
try {
url=new URL(UrlLink2) ;
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
InputStream isp=urlConnection.getInputStream();
DocumentBuilderFactory DBF=DocumentBuilderFactory.newInstance();
DocumentBuilder Db=DBF.newDocumentBuilder();
doc=Db.parse(isp);
Element rootElem=doc.getDocumentElement();
NodeList itemlist=rootElem.getElementsByTagName("item");
Node currentitem=null;
Node childnode=null;
Node ContentChild=null;
Node CddatatChild=null;
NodeList childnodeList=null;
NodeList CddataList=null;
NodeList ContentChilList=null;
for(int i=0;i<itemlist.getLength();i++){
currentitem=itemlist.item(i);
childnodeList=currentitem.getChildNodes();
for(int j=0;j<childnodeList.getLength();j++){
childnode=childnodeList.item(j);
if(childnode.getNodeName().equalsIgnoreCase("content:encoded")){
ContentChilList=childnode.getChildNodes();
ContentChilList.getLength();
CddatatChild=ContentChilList.item(0);
CddataList=CddatatChild.getChildNodes();
if(CddatatChild.getNodeName().equalsIgnoreCase("#cdata-section")){
GetCddata=CddatatChild.getTextContent().toString();
GetCddata=CddatatChild.getTextContent();
}
}
}
}
}
catch(Exception e){
}
try{
int i=0;
String ss=GetCddata;
Pattern PatternImgURLS = Pattern.compile("(?<=a href=\")(.*?)(?=\")");
Pattern PatternImgname = Pattern.compile("(?<=2014\\/09\\/)(.*?)(?=\\.)");
Matcher Imagematcher = PatternImgURLS.matcher(ss);
Imagematcher.matches();
while (Imagematcher.find()) {
ImgUrl=Imagematcher.toMatchResult().group();
ImageUrls.add(ImgUrl);
i++;
}
for(int count=0;count<ImageUrls.size();count++){
Matcher Namematcher = PatternImgname.matcher(ImageUrls.get(count));
Namematcher.matches();
while (Namematcher.find()) {
String MatchTxt=Namematcher.toMatchResult().group();
String lowerMatchTxt = MatchTxt.toLowerCase();
ImageName.add(lowerMatchTxt);
Log.v("dd",ImageName.get(count));
}
}
Log.v("dd",ImageUrls.get(0));
int t=ImageUrls.size();
Log.v("dd",toString().valueOf(t));
urlConnection.disconnect();
url=new URL(ImageUrls[0]) ;
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
InputStream isp2=urlConnection.getInputStream();
bitmap=BitmapFactory.decodeStream(isp2);
urlConnection.disconnect();
}
catch(Exception e){
Log.v("h",e.toString()) ; }
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
dialog.dismiss();
Here I am displaying---> Imageview.setImageBitmap(bitmap);
the image in Image viwer
Now how do I store the image from the imageviewer to
drawable folder in andriod is that possiable.
}
}