-3
私はクライアントのためにアンドロイドにepubブックリーダーアプリを作成しています。 私のアプリでは現在FolioReaderを使用していますが、画像は表示されません。 .epubファイルをアンドロイドに表示する他の方法はありますか?Android:.epubファイルの解析
ありがとうございます!
私はクライアントのためにアンドロイドにepubブックリーダーアプリを作成しています。 私のアプリでは現在FolioReaderを使用していますが、画像は表示されません。 .epubファイルをアンドロイドに表示する他の方法はありますか?Android:.epubファイルの解析
ありがとうございます!
ウェブビューでデータを読み込む際に、イメージを抽出してそれらのイメージへの参照を保持する必要があります。このコードを試してみてください
outPutFolder=getDir("example", Context.MODE_PRIVATE) + "/"+fileName +"/" ;
//your directory name
try {
epubInputStream=new FileInputStream(filePath);
} catch (IOException e1) {
e1.printStackTrace();
}
try {
book = (new EpubReader()).readEpub(epubInputStream);
} catch (IOException e) {
e.printStackTrace();
}
outPutFolder=getDir("example", Context.MODE_PRIVATE) + "/"+fileName +"/" ;
setOutPutFolder(outPutFolder);
DownloadResource(outPutFolder);
linezNew = "";
Spine spine = book.getSpine();
List<SpineReference> spineList = spine.getSpineReferences() ;
int count = spineList.size();
StringBuilder string = new StringBuilder();
for (int i = 0; count > i; i++) {
Resource res = spine.getResource(i);
try {
InputStream is = res.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
try {
String line;
while ((line = reader.readLine()) != null) {
linezNew = string.append(line + "\n").toString();
}
} catch (IOException e) {e.printStackTrace();}
} catch (IOException e) {
e.printStackTrace();
}
}
linezNew = linezNew.replace("../", "");
finalDataToLoad="<head><style>img{max-width: 100%; width:50%; height: 50%;}</style></head> "+linezNew;
webView.loadDataWithBaseURL("file://" + outPutFolder, finalDataToLoad, "text/html", "utf-8", null);
とDownloadResource機能がここ
private void DownloadResource(String directory) {
try {
Resources rst = book.getResources();
Collection<Resource> clrst = rst.getAll();
Iterator<Resource> itr = clrst.iterator();
while (itr.hasNext()) {
Resource rs = itr.next();
if ((rs.getMediaType() == MediatypeService.JPG)
|| (rs.getMediaType() == MediatypeService.PNG)
|| (rs.getMediaType() == MediatypeService.GIF)) {
Log.d("Href", rs.getHref());
File oppath1 = new File(directory, rs.getHref().replace("OEBPS/", ""));
oppath1.getParentFile().mkdirs();
oppath1.createNewFile();
System.out.println("Path : "+oppath1.getParentFile().getAbsolutePath());
FileOutputStream fos1 = new FileOutputStream(oppath1);
fos1.write(rs.getData());
fos1.close();
} else if (rs.getMediaType() == MediatypeService.CSS) {
File oppath = new File(directory, rs.getHref());
oppath.getParentFile().mkdirs();
oppath.createNewFile();
FileOutputStream fos = new FileOutputStream(oppath);
fos.write(rs.getData());
fos.close();
}
}
} catch (Exception e) {
}
}
filePathには、あなたのEPUBファイルへのパスです(EPUB libとSLF4Jライブラリを追加)、ファイル名は文字列
あるあなたのePubファイルの名前です。outPutFolder、linezNew、finalDataToLoadも
を文字列であるが、それはまだdisplaないEpubParser https://github.com/mertakdut/EpubParser – AMB
@SpringBreakerをお試しくださいying images – Ravi
@Redman Imageが不正な方法で表示されています – Ravi