Tag: image

用Java打印BufferedImage

有谁知道如何用Java打印BufferedImage?

在Java中为图像添加边框

我试图创建一个图像,通过将像素从旧位置复制到新坐标,在Java上为现有图像添加边框。 到目前为止,这就是我所做的: public static NewPic border (NewPic p, int borderWidth, Pixel borderColor) { int w = p.getWidth(); int h = p.getHeight(); Pixel src[][] = p.getBitmap(); Pixel tgt[][] = new Pixel[h][w]; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { tgt[y][x + y + borderWidth] […]

如何在Java中将<img … in html转换为byte

我在HtmlUnit无头浏览器中打开了一个网页。 现在该网页包含图像html标记,如下所示: 所以我只想要那个图像。 但问题是图像的相同src URL显示差异。 每次都是形象。 意思是,如果我们刷新img src URL,那么它会显示diff。 每次都是形象。 那么如何获取html页面上显示的图像。

Hex String to Image

我有一个hex字符串,看起来像: String hexImage =”0xFFD8FFE000104A46494600010200006400640000FFEC00114475636B79000100040000003C…” 我需要使用Java转换为图像。 我已经尝试使用org.apache.commons.codec.binary.Hex类首先转换为字节数组。 FileOutputStream稍后将其转储到文件中。 char[] charArr= hexImage.toCharArray(); byte[] byteArray = Hex.decodeHex(charArr); 但是Hex类中的解析器会出现扼流圈,并带有Decoderexception:奇数个字符。 无论我使用什么方法转换为字节数组,它都会失败。 fileformat绝对是JPEG。 我已经尝试从字符串中删除此 0xFF,但此时图像已损坏。 0xFF我认为是罪魁祸首 – 任何人都有任何想法,我需要做些什么才能纠正这个问题?

导出的JAR无法读取图像

我试图让图像显示在JPanel中。 这是我正在使用的代码: URL imageURL; BufferedImage image = null; ImageIcon icon; imageURL = getClass().getClassLoader().getResource(“images/audiorpglogo.png”); if (imageURL == null) { System.out.println(imageURL == null); try { imageURL = new File(“images/audiorpglogo.png”).toURI().toURL(); } catch (Exception e1) { imageURL = null; } } System.out.println(imageURL == null); try { image = ImageIO.read(imageURL); } catch (Exception e) { } System.out.println(image == null); icon […]

Addactionlistener不接受参数

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Concentration extends JFrame implements ActionListener { private JButton buttons[][]=new JButton[4][4]; int i,j,n; public Concentration() { super (“Concentration”); JFrame frame=new JFrame(); setSize(1000,1000); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel=new JPanel(new GridLayout(4,4)); panel.setSize(400, 400); for( i=0; i<buttons.length; i++){ for (j=0; j<buttons[i].length;j++){ n=i*buttons.length+buttons[i].length; buttons[i][j]=new JButton(); panel.add(buttons[i][j]); buttons[i][j].addActionListener(this); } } add(panel); pack(); setVisible(true); […]

扩展BufferedImage

为什么以下代码显示黑色图像而不是图片? 如何正确扩展BufferedImage? class SizeOfImage { public static void main(String[] args) throws Exception { URL url = new URL(“http://cloudbite.co.uk/wp-content/uploads/2011/03/google-chrome-logo-v1.jpg”); final BufferedImage bi = ImageIO.read(url); final String size = bi.getWidth() + “x” + bi.getHeight(); final CustomImg cstImg = new CustomImg(bi.getWidth(), bi.getHeight(), bi.getType()); SwingUtilities.invokeLater(new Runnable() { public void run() { JLabel l = new JLabel(size, new ImageIcon(cstImg), SwingConstants.RIGHT); […]

使用pdfBox从PDF中提取的图像的DPI

我正在使用java pdfBox库来validation带有嵌入式图像的单页pdf文件。 我知道pdf文件本身不包含DPI信息。 然而,文档中具有相同尺寸的图像在提取后具有不同的像素大小并且没有dpi元信息。 那么有可能以某种方式计算相对于pdf页面的图像大小或使用pdfBox提取其dpi信息(对于png或jpeg图像文件)的图像? 谢谢!

预览窗口(如打开的应用程序的Windows 7任务栏显示)

我想为我的“主窗口”创建一个“预览窗口”,所以如果我将鼠标指针指向特定的按钮或位置,那么它会在一个小窗口中显示主窗口预览,当我点击那个“预览窗口”时它应该返回“主窗口”。 例如,Windows 7任务栏为每个打开的应用程序创建预览。 我该如何向用户提供此function? 例如

如何使用透明填充缩放Graphics2D图像

我正在尝试编写一个小方法,它采用BufferedImage图像和新的宽度和高度,并通过根据图像向左/右或上/下添加透明边框来缩放保持纵横比的图像。 缩放工作正常,但对于我的生活,我不能让边框透明。 到目前为止,我在pastebin.com上发布了以下代码 ,可以很好地进行扩展。 我阅读了很多手册和其他SO问题无济于事。 我已经尝试了许多填充,复合类型,图像类型等的排列。有时我得到一个蓝色背景,有时是白色但它似乎永远不会透明。 BufferedImage newImg = new BufferedImage(newWidth, newHeight, img.getType()); Graphics2D g = newImg.createGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, newWidth, newHeight); g.drawImage(img, x, y, x + scaledWidth, y + scaledHeight, 0, 0, currentWidth, currentHeight, Color.WHITE, null); g.dispose(); return newImg; 知道我需要做什么Graphics2D才能使Color.WHITE背景透明并在新的上面绘制旧图像? 谢谢你的帮助。 编辑: 事实certificate,我遇到的问题是我试图用JPEG图像生成透明色。 JPEG不支持透明度。 咄。