You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2008/11/05 16:30:17 UTC
DO NOT REPLY [Bug 46153] New: Export the shape to images
https://issues.apache.org/bugzilla/show_bug.cgi?id=46153
Summary: Export the shape to images
Product: POI
Version: 3.5-dev
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: normal
Priority: P2
Component: HSLF
AssignedTo: dev@poi.apache.org
ReportedBy: jie.han@163.com
CC: jie.han@163.com
Created an attachment (id=22833)
--> (https://issues.apache.org/bugzilla/attachment.cgi?id=22833)
I put all PowerPoint shapes in the slide
When I use the following code to export the shape to jpeg file, I trace the
process and if the shape type is ShapeGroup in the Picuture's draw function
the getPictureData() function always get null value
--------------------------
public void draw(Graphics2D graphics){
AffineTransform at = graphics.getTransform();
ShapePainter.paint(this, graphics);
PictureData data = getPictureData();
data.draw(graphics, this);
graphics.setTransform(at);
}
Below is my code:
---------------------------
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hslf.model.AutoShape;
import org.apache.poi.hslf.model.Freeform;
import org.apache.poi.hslf.model.Line;
import org.apache.poi.hslf.model.MovieShape;
import org.apache.poi.hslf.model.OLEShape;
import org.apache.poi.hslf.model.Picture;
import org.apache.poi.hslf.model.Shape;
import org.apache.poi.hslf.model.ShapeGroup;
import org.apache.poi.hslf.model.SimpleShape;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.model.Table;
import org.apache.poi.hslf.model.TextBox;
import org.apache.poi.hslf.usermodel.PictureData;
import org.apache.poi.hslf.usermodel.SlideShow;
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class TestShape {
public static void main(String... strings) {
String path = "./src/testfiles/demo1.ppt";
try {
InputStream is = new FileInputStream(path);
SlideShow ppt = new SlideShow(is);
Slide[] slides = ppt.getSlides();
int i = 0;
// PPTXMLDump xdump = new PPTXMLDump();
int shpCount = 0;
for (Slide slide : slides) {
for (Shape shp : slide.getShapes()) {
Rectangle anchor = shp.getAnchor();
BufferedImage img = new
BufferedImage(anchor.width + 1,
anchor.height + 1,
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics =
img.createGraphics();
graphics.translate(-anchor.x,
-anchor.y);
if (shp instanceof Line) {
((Line) shp).draw(graphics);
} else if (shp instanceof Picture) {
((Picture) shp).draw(graphics);
} else if (shp instanceof TextBox) {
((TextBox) shp).draw(graphics);
} else if (shp instanceof MovieShape) {
((MovieShape)
shp).draw(graphics);
} else if (shp instanceof OLEShape) {
((OLEShape)
shp).draw(graphics);
} else if (shp instanceof Table) {
((Table) shp).draw(graphics);
} else if (shp instanceof Freeform) {
((Freeform)
shp).draw(graphics);
} else if (shp instanceof AutoShape) {
((AutoShape)
shp).draw(graphics);
} else if (shp instanceof ShapeGroup) {
((ShapeGroup)
shp).draw(graphics);
}
TestShape.writeToFile("./src/shape/slide-"
+ shp.getShapeId() +
".jpg", img);
System.out.println(shp.getClass().getName());
// }
}
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
public static void writeToFile(String fileName, BufferedImage img) {
try {
File file = new File(fileName);
FileOutputStream out;
out = new FileOutputStream(file);
JPEGImageEncoder encoder =
JPEGCodec.createJPEGEncoder(out);
com.sun.image.codec.jpeg.JPEGEncodeParam param =
encoder
.getDefaultJPEGEncodeParam(img);
param.setQuality(2f, true);
encoder.setJPEGEncodeParam(param);
encoder.encode(img);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ImageFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
DO NOT REPLY [Bug 46153] Export the shape to images
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=46153
Yegor Kozlov <ye...@dinom.ru> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |WONTFIX
--- Comment #1 from Yegor Kozlov <ye...@dinom.ru> 2008-11-16 05:44:01 PST ---
Try the latest svn build. Your code works fine with it.
Yegor
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
DO NOT REPLY [Bug 46153] Export the shape to images
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=46153
Jie Han <ji...@163.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|WONTFIX |FIXED
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org