Displaying Images from epub

170 views
Skip to first unread message

Aravind Srivatsan

unread,
Oct 16, 2012, 10:01:43 AM10/16/12
to epu...@googlegroups.com
I tried all methods from stackoverflow and other questions. But I cant get to display images. What am I doing wrong?

Right now I am using the following code:

                        String abspath = FILEPATH+File.separator+file;
  File filePath = new File(abspath+".epub");   
  InputStream epubInputStream = new BufferedInputStream(new FileInputStream(filePath));
  book = (new EpubReader()).readEpub(epubInputStream);
  int pos = abspath.lastIndexOf('/');
  DownloadResource(filePath, abspath.substring(0, pos));
  String data = "";
  Log.d("Size", ""+book.getContents().size());
  for(int i = 1; i< book.getContents().size(); i++) {
  data += new String(book.getContents().get(i).getData());
  }
  wv.loadDataWithBaseURL("file://mnt/sdcard/", data, "text/html", "utf-8", null);
}
catch (IOException e) {
  Log.e("epublib", e.getMessage());
}
private void DownloadResource(File FileObj, String directory) {
try {
InputStream epubis = new FileInputStream(FileObj);
book = (new EpubReader()).readEpub(epubis);
Toast.makeText(getActivity(), "Download Res", Toast.LENGTH_SHORT).show();

nl.siegmann.epublib.domain.Resources rst = book.getResources();
Collection<Resource> clrst = rst.getAll();
Iterator<Resource> itr = clrst.iterator();
while (itr.hasNext()) {
Resource rs = itr.next();
Toast.makeText(getActivity(), "ResCheck", Toast.LENGTH_SHORT).show();
if ((rs.getMediaType() == MediatypeService.JPG) || (rs.getMediaType() == MediatypeService.PNG) || (rs.getMediaType() == MediatypeService.GIF)) {
File oppath1 = new File(directory, "Images/"+ rs.getHref().replace("Images/", ""));

oppath1.getParentFile().mkdirs();
oppath1.createNewFile();
    
Toast.makeText(getActivity(), oppath1.getPath(), Toast.LENGTH_SHORT).show();
    
FileOutputStream fos1 = new FileOutputStream(oppath1);
fos1.write(rs.getData());
fos1.close();

if (rs.getMediaType() == MediatypeService.CSS) {
File oppath = new File(directory, "Styles/"+ rs.getHref().replace("Styles/", ""));

oppath.getParentFile().mkdirs();
oppath.createNewFile();

FileOutputStream fos = new FileOutputStream(oppath);
fos.write(rs.getData());
fos.close();
}
}
catch (Exception e) {
Log.v("error", e.getMessage());
}
}
Reply all
Reply to author
Forward
0 new messages