我希望用户能够在Android中选择.PPT文件并让应用程序浏览每张幻灯片并将每张幻灯片设置为图库组件的图像。我正在使用Apache POI库来完成powerpoint。为了绕过在Android中使用JRE库,因为许多POI类需要它,我从这个repo:https://github.com/qhm123/POI-Android导入了src类,这样我就不使用Java内置的JRE类了。这是我到目前为止,但该程序不起作用,我真的不知道它是否有帮助。我的样本ppt是“Sickle Cell Anemia.ppt”。我究竟做错了什么?任何帮助将不胜感激!
package com.example.deskirassistant;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.pbdavey.awt.Graphics2D;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import and.awt.BufferedImage;
import and.awt.Color;
import and.awt.Dimension;
import and.awt.ImageIO;
import and.awt.geom.AffineTransform;
import and.awt.geom.Rectangle2D;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
public class MainActivity extends Activity {
public XSLFSlide[] slide;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView mImageView = (ImageView) findViewById(R.id.image1);
try {
ppt2png();
} catch (IOException e) {
e.printStackTrace();
}
}
private void ppt2png() throws IOException {
FileInputStream is = new FileInputStream("Sickle Cell Anemia.ppt");
XMLSlideShow ppt = new XMLSlideShow(is);
is.close();
double zoom = 2; // magnify it by 2
AffineTransform at = new AffineTransform();
at.setToScale(zoom, zoom);
Dimension pgsize = ppt.getPageSize();
slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
BufferedImage img = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
graphics.setTransform(at);
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
slide[i].draw(graphics, null, null, i);
}
}
}