日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

公司--下载svg图片

發布時間:2025/3/20 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 公司--下载svg图片 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

加載本地svg圖片:

SVGParserRenderer norDrawable = OtherPageConfigsManager.getInstance().getSVGParserRenderer(this,map.get("iconUrlNor"));public SVGParserRenderer getSVGParserRenderer(Context context, String svgPath){String config = "";if(iconLoadPathType == SAVE_TYPE_ASSETS)//本地存儲位置config = FileSystem.getFromAssets(context, "panelConfigFolder/"+svgPath);else if(iconLoadPathType == SAVE_TYPE_SDCARD)//SDK存儲位置config = "";//"file://"+FileSystem.getCacheRootDir(context, "").getPath()+ url;else if(iconLoadPathType == SAVE_TYPE_SYSTEM_DATA_FOLDER)//內部文件系統存儲位置//modify by chris.lei 添加中臺未配發右側在線客服圖標導致從內部文件中讀取不到信息客戶端首頁顯示空白的問題config = FileSystem.readFromFile(context, getConfigFile(context, "panelConfigFolder", svgPath).getPath());if(config == ""){config = FileSystem.getFromAssets(context, "panelConfigFolder/"+svgPath);}return SvgRes1.getSVGParserRenderer(context, config);//從配置文件獲取 }public static SVGParserRenderer getSVGParserRenderer(Context context, String svgContent) {return svgContent != null && !svgContent.equals("")?new SVGParserRenderer(context, parseCssStyleToSvg(svgContent)):null; }public static String parseCssStyleToSvg(String svgContent) {int startIndex = svgContent.indexOf("<style");int endIndex = svgContent.indexOf("</style>") + "</style>".length();String styleStr = null;if(startIndex >= 0 && endIndex >= 0) {styleStr = svgContent.substring(startIndex, endIndex); // styleStr = <style type="text/css"><![CDATA[.strokeColor{fill:#B0B0B0;}]]></style>if(styleStr != null && !styleStr.equals("")) {int startIndex1 = styleStr.indexOf(".");int endIndex1 = styleStr.lastIndexOf(".");int endendIndex = styleStr.lastIndexOf(";}") + ";}".length();String colorStr;if(startIndex1 == endIndex1) {colorStr = styleStr.substring(startIndex1 + ".".length(), endendIndex);} else {colorStr = styleStr.substring(startIndex1, endendIndex);}//colorStr = strokeColor{fill:#B0B0B0;}String[] fillColorArr = colorStr.split(";"); if(fillColorArr != null) {for(int i = 0; i < fillColorArr.length; ++i) {if(fillColorArr[i].contains("fill:")) {String[] nameColorArr = fillColorArr[i].split("fill:");if(nameColorArr != null) {int nameStartIndex = nameColorArr[0].indexOf(".") + ".".length();String name = nameColorArr[0].substring(nameStartIndex, nameColorArr[0].length() - 1);String color = nameColorArr[1];if(svgContent.contains("class=\"" + name + "\"")) {svgContent = svgContent.replace("class=\"" + name + "\"", "fill=\"" + color + "\"");}}}}}}svgContent = svgContent.replace(styleStr, "");}return svgContent; }parseCssStyleToSvg的行參 svgContent = <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="48px" height="48px" viewBox="0 0 48 48" enable-background="new 0 0 48 48" xml:space="preserve"> <style type="text/css"> <![CDATA[.strokeColor{fill:#B0B0B0;} ]]> </style> <path class="strokeColor" d="M3.494,24c0-0.587,0.476-1.063,1.063-1.063h38.886c0.588,0,1.063,0.476,1.063,1.063l0,0c0,0.587-0.475,1.062-1.063,1.062H4.557C3.97,25.063,3.494,24.587,3.494,24L3.494,24z"/> <g><g><g><path class="strokeColor" d="M3.806,23.249c0.415-0.414,1.088-0.414,1.502,0l17.054,17.053c0.415,0.415,0.415,1.087,0,1.503l0,0c-0.415,0.414-1.088,0.414-1.503,0L3.806,24.751C3.391,24.336,3.391,23.665,3.806,23.249L3.806,23.249z"/></g><g><path class="strokeColor" d="M22.361,6.196c0.415,0.415,0.415,1.087,0,1.502L5.308,24.751c-0.414,0.415-1.087,0.415-1.502,0l0,0c-0.415-0.415-0.415-1.087,0-1.503L20.858,6.196C21.273,5.781,21.946,5.781,22.361,6.196L22.361,6.196z"/></g></g> </g> </svg>返回 svgContent = <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"width="48px" height="48px" viewBox="0 0 48 48" enable-background="new 0 0 48 48" xml:space="preserve"> <path fill="#B0B0B0" d="M3.494,24c0-0.587,0.476-1.063,1.063-1.063h38.886c0.588,0,1.063,0.476,1.063,1.063l0,0c0,0.587-0.475,1.062-1.063,1.062H4.557C3.97,25.063,3.494,24.587,3.494,24L3.494,24z"/> <g><g><g><path fill="#B0B0B0" d="M3.806,23.249c0.415-0.414,1.088-0.414,1.502,0l17.054,17.053c0.415,0.415,0.415,1.087,0,1.503l0,0c-0.415,0.414-1.088,0.414-1.503,0L3.806,24.751C3.391,24.336,3.391,23.665,3.806,23.249L3.806,23.249z"/></g><g><path fill="#B0B0B0" d="M22.361,6.196c0.415,0.415,0.415,1.087,0,1.502L5.308,24.751c-0.414,0.415-1.087,0.415-1.502,0l0,0c-0.415-0.415-0.415-1.087,0-1.503L20.858,6.196C21.273,5.781,21.946,5.781,22.361,6.196L22.361,6.196z"/></g></g> </g> </svg>

下載網絡svg圖片:

if (norDrawable == null) {panelConfigsDownloader.startDownloadForSvgIcon(this,OtherPageConfigsManager.getInstance(),map.get("downloadUrl") + norFilePath, saveNorFilePath,new SvgIconOnDownloadCompleteListener(mKdsShortcutView[index], map, "iconUrlNor")); }public void startDownloadForSvgIcon(Context context,ConfigsManager configsManager,String svgDownloadUrl, String svgFilePath,OnDownloadCompleteListener onDownloadCompleteListener){ //下載配置文件 String parentFolder = configsManager.mConfigInfo.saveFolderName+"/"; //parentFolder = panelConfigFolder/ String fileName = ""; if(svgFilePath != null && !svgFilePath.equals("")){ //svgFilePath = ueditor/1431988818264.svgString[] saveFileDir = svgFilePath.split("/");for(int i = 0; i < saveFileDir.length; i++){if(saveFileDir[i].contains(".")){fileName = saveFileDir[i]; //fileName = 1431988818264.svgcontinue;}parentFolder += saveFileDir[i]; //parentFolder = panelConfigFolder/ueditor } }else{return;//說明不是需要下載的文件 }File file = configsManager.getConfigFile(context, parentFolder, fileName); //file = panelConfigFolder/ueditor/1431988818264.svg DownloadConfigFileThread downloadConfigFileThread = new DownloadConfigFileThread(context, svgDownloadUrl, file, onDownloadCompleteListener);if(!file.isDirectory() && !file.exists()) {//考慮已經存在同樣名字的文件或者目錄,//Logger.d("downloadConfigFile", "startDownloadForSvgIcon exists:"+file.exists());downloadConfigFileThread.start();//開始下載}else{Logger.i("快捷按鈕配置文件", "警告:該文件存在相同文件名,不進行下載更新,請知曉!");downloadConfigFileThread.onDownloadComplete();//已經存在也視為完成 } }public class DownloadConfigFileThread extends Thread {public synchronized void run(){try{URL url = new URL(downurl);// http://113.78.134.110:21800/api/config/app/ui/otherpage/online/66099/100000// 創建連接HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setConnectTimeout(30000);conn.setReadTimeout(30000);conn.connect();// 獲取文件大小int length = conn.getContentLength();//40674// 創建輸入流InputStream is = conn.getInputStream(); //處理文件路徑不存在的問題String dirFilePath = configFile.getPath();// /data/data/dongzheng.szkingdom.android.phone/files/panelConfigFolder/otherpage_temp.jsonString childDirPath = "";String[] path = dirFilePath.split("/");for(int i = 0; i < path.length-1;i++){if(path[i].contains("."))continue; childDirPath += "/" + path[i]; File file = new File(childDirPath);if(!file.exists()) {//考慮已經存在同樣名字的文件或者目錄,Logger.d("tag", "DownloadConfigFileThread mkdir newPath:"+file.getPath());file.mkdir();file.setExecutable(true, false);file.setReadable(true, false);file.setWritable(true, false);}}FileOutputStream fos = new FileOutputStream(configFile); // 輸出到文件 /data/data/dongzheng.szkingdom.android.phone/files/panelConfigFolder/otherpage_temp.json// 緩存byte buf[] = new byte[1024];int count = 0;// 寫入到文件中do{int numread = is.read(buf);count += numread;// 計算進度條位置 int progress = (int) (((float) count / length) * 100);float tempSpace = count / 1024.0f / 1024.0f;String downloadSpace = "";try{downloadSpace = String.format("%.3f",tempSpace)+"M";// > 1.0f ? (tempSpace+"M") : (count / 1024.0f+"KB");}catch(Exception e){} if (numread <= 0){//下載完成 mHandler.removeMessages(0);Message msg = Message.obtain();msg.what = 0;mHandler.sendMessage(msg);break;} // 寫入文件fos.write(buf, 0, numread);} while (true);// 點擊取消就停止下載. fos.close();is.close();}catch(Exception e){mHandler.removeMessages(1);mHandler.sendEmptyMessage(1);//e.printStackTrace(); }} }

?

總結

以上是生活随笔為你收集整理的公司--下载svg图片的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。