之前其他的步骤我就不说了,第一段 BufferedImage bufferedImage = imageReader.read(0); 得到了图片了..box.add( new ImageComponent(bufferedImage) );
new ImageComponent(bufferedImage) 看看这个类里的方法.
// Read the first image
BufferedImage bufferedImage = imageReader.read(0); // Create a JFrame for the image
JFrame frame = new JFrame(fileName);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Place the components in a Box Layout
Box box = new Box(BoxLayout.Y_AXIS);
frame.getContentPane().add(box); // Add the image
box.add( new ImageComponent(bufferedImage) ); // Display the JFrame
frame.pack();
frame.setSize(bufferedImage.getWidth(), bufferedImage.getHeight());
frame.setVisible(true);
/** JComponent used to display a Buffered Image. */
private class ImageComponent extends JComponent
{
/** Buffered Image displayed in the JComponent. */
private BufferedImage _bufferedImage; /**
* Constructs an Image Component.
*
* @param bufferedImage Buffered Image displayed in the JComponent.
*/
public ImageComponent(BufferedImage bufferedImage)
{
_bufferedImage = bufferedImage;
} /**
* Paints the image into the specified Graphics.
*
* @param g Graphics to paint into.
*/
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
g2d.drawImage(_bufferedImage, 0, 0, null);
}
}以上他可以显示出来图片出来
以下是我的代码,我希望能把dicom的图片 生成jpg格式的,BufferedImage bufferedImage = imageReader.read(0);
Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
// graphics.setBackground(Color.WHITE);
graphics.drawImage(bufferedImage, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), null);
FileOutputStream out = new FileOutputStream("D://hehe.jpg");
ImageIO.write(bufferedImage, "jpg", out);
out.close();如果我直接用了已经是jpg格式的图片可以没问题的生成,但是如果是读取的dicom的格式,图片生成了 但是大小是0KB..
为什么上面的程序g2d.drawImage(_bufferedImage, 0, 0, null); 这个画图和我将图片生成到本地有什么区别..
new ImageComponent(bufferedImage) 看看这个类里的方法.
// Read the first image
BufferedImage bufferedImage = imageReader.read(0); // Create a JFrame for the image
JFrame frame = new JFrame(fileName);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Place the components in a Box Layout
Box box = new Box(BoxLayout.Y_AXIS);
frame.getContentPane().add(box); // Add the image
box.add( new ImageComponent(bufferedImage) ); // Display the JFrame
frame.pack();
frame.setSize(bufferedImage.getWidth(), bufferedImage.getHeight());
frame.setVisible(true);
/** JComponent used to display a Buffered Image. */
private class ImageComponent extends JComponent
{
/** Buffered Image displayed in the JComponent. */
private BufferedImage _bufferedImage; /**
* Constructs an Image Component.
*
* @param bufferedImage Buffered Image displayed in the JComponent.
*/
public ImageComponent(BufferedImage bufferedImage)
{
_bufferedImage = bufferedImage;
} /**
* Paints the image into the specified Graphics.
*
* @param g Graphics to paint into.
*/
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
g2d.drawImage(_bufferedImage, 0, 0, null);
}
}以上他可以显示出来图片出来
以下是我的代码,我希望能把dicom的图片 生成jpg格式的,BufferedImage bufferedImage = imageReader.read(0);
Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
// graphics.setBackground(Color.WHITE);
graphics.drawImage(bufferedImage, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), null);
FileOutputStream out = new FileOutputStream("D://hehe.jpg");
ImageIO.write(bufferedImage, "jpg", out);
out.close();如果我直接用了已经是jpg格式的图片可以没问题的生成,但是如果是读取的dicom的格式,图片生成了 但是大小是0KB..
为什么上面的程序g2d.drawImage(_bufferedImage, 0, 0, null); 这个画图和我将图片生成到本地有什么区别..
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货