javax.imageio

Text is missing when converting pdf file into image in java using pdfbox

一世执手 提交于 2019-12-23 12:46:26
问题 I want to convert a PDF page to image file. Text is missing when I convert a PDF page to image using java. The file which I want to convert 46_2.pdf after converting it shown me like 46_2.png Code: import java.awt.image.BufferedImage; import java.io.File; import java.util.List; import javax.imageio.ImageIO; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; public class ConvertPDFPageToImageWithoutText { public static void main(String[] args) { try { String

Convert a 2D array of int ranging from 0-256 into a grayscale png?

♀尐吖头ヾ 提交于 2019-12-23 10:14:25
问题 How can I convert a 2D array of ints into a grayscale png. right now I have this: BufferedImage theImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); for(int y = 0; y<100; y++){ for(int x = 0; x<100; x++){ theImage.setRGB(x, y, image[y][x]); } } File outputfile = new File("saved.bmp"); ImageIO.write(theImage, "png", outputfile); but the image comes out blue. how can I make it a grayscale. image[][] contains ints ranging from 0-256. 回答1: The image comes out blue because setRGB is

How to use ColorQuantizerDescriptor?

丶灬走出姿态 提交于 2019-12-22 18:45:15
问题 Following the idea of @PhiLho's answer to How to convert a BufferedImage to 8 bit?, I want to use ColorQuantizerDescriptor to convert a BufferedImage , imageType TYPE_INT_RGB, but RenderedOp#getColorModel() is throwing the following exception: java.lang.IllegalArgumentException: The specified ColorModel is incompatible with the image SampleModel. at javax.media.jai.PlanarImage.setImageLayout(PlanarImage.java:541) at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878) at javax

ImageIO support for raw images (jrawio)

妖精的绣舞 提交于 2019-12-22 14:01:31
问题 I was looking for raw image support and found this library (jrawio-1.6.1) which extends imageio to add raw support. It seems to work but awfully slow. I've seen snails that were faster. My code processes Jpegs in seconds and it takes minutes to process a not that much bigger .cr2 file or .nef. I could be wrong but I think it even slowed down the tiff processing. The last tiff file was very big so that could have been the problem too. Another issue I have with this library is that development

ImageIO hangs when referred inside an OSGI Application Mac OS X - Java 1.7

﹥>﹥吖頭↗ 提交于 2019-12-22 10:36:11
问题 I am using Java 1.7 on Mac OS X 10.7.5 . It hangs the moment execution touches any ImageIO API. import javax.imageio.ImageIO; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; public class ImageMain implements IApplication { @Override public Object start(IApplicationContext context) throws Exception { ImageIO.getCacheDirectory(); return IApplication.EXIT_OK; } @Override public void stop() { // TODO Auto-generated method stub } } jstack output :

How to read a image url in google appengine using java

此生再无相见时 提交于 2019-12-22 10:12:00
问题 The ImageIO is not in the whitelist of GAE. How to read a image(JPG,PNG) from url as ImageBuffer without using ImageIO? 回答1: You could read the url stream and create a bytearray using the IOUtils from apache commons. URL url = new URL(this.url); InputStream input = url.openStream(); byteArray = IOUtils.toByteArray(input) Note: toByteArray method buffers the input internally, so there is no need to use a BufferedInputStream . EDIT: BufferedImage is listed as not supported on AppEngine; that

Creating a jpeg file with metadata

假如想象 提交于 2019-12-22 00:19:41
问题 I have a Java application that creates a BufferedImage and saves it to disk as a JPEG. I'd really like to add a caption to the image. To prevent the image from getting crowded out by text on the image itself, it'd be great if I could write the caption to the JPEG's metadata. I've been searching all over the place for a solution, but haven't found anything satisfactory. Sanselan comes up a lot, but I haven't figured out how to use it properly. I found examples that modify existing metadata,

Why Java ImageIO flattens JPEG colors

冷暖自知 提交于 2019-12-21 04:02:14
问题 When I read certain JPG files, colors are flattened. Here is a simple example that reads a jpg and just writes the same image to another file. import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; public class JPegReadTest { public static void main(String[] args) { if (args.length == 2) { try { BufferedImage src = ImageIO.read(new File(args[0])); ImageIO.write(src, "jpg", new File(args[1])); } catch (Exception e) { e.printStackTrace(); } } else { System.err

Fastest way to read/write Images from a File into a BufferedImage?

与世无争的帅哥 提交于 2019-12-20 20:37:53
问题 What is the fastest way to read Images from a File into a BufferedImage in Java/Grails? What is the fastest way to write Images from a BufferedImage into a File in Java/Grails? my variant (read): byte [] imageByteArray = new File(basePath+imageSource).readBytes() InputStream inStream = new ByteArrayInputStream(imageByteArray) BufferedImage bufferedImage = ImageIO.read(inStream) my variant (write): BufferedImage bufferedImage = // some image def fullPath = // image page + file name byte []

Why doesn't ImageIO preserve JPEG data when repeatedly loading and saving?

百般思念 提交于 2019-12-20 04:54:15
问题 Originally I wanted to try whether it is possible to reconstruct redacted data from a JPEG image, given that it is a lossy image format and the pixel values spread into the neighbor pixels. To test whether saving and loading JPEG images is reliable, I wrote the following program that repeatedly saves and loads a JPEG image until it reaches an image that has been seen before. Here is the code: package de.roland_illig.jpg import java.awt.image.BufferedImage import java.io.ByteArrayInputStream