javax.imageio

BufferedImage getRGB vs Raster getSample

自闭症网瘾萝莉.ら 提交于 2019-11-30 14:15:58
问题 I am trying to do some image processing in Java. I used ImageIO library for reading and writing images. I can read the image pixel value in two ways as follows (there might be other methods which do not know). Using BufferedImage's getRGB method: pixel = image.getRGB(x,y); Using Raster's getSample method: WritableRaster raster = image.getRaster(); pixel = raster.getSample(x,y,0); What is the difference in the above two approaches? 回答1: 1: The first approach will always return a pixel in int

ImageIO: <ERROR> JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?

天大地大妈咪最大 提交于 2019-11-30 13:14:41
I get this error by downloading an image by HTTP. I have looked at the answer here but even the valid images don't return YES from the function. Any other ideas? The code to get the image is simple enough. This happens in a background thread. NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]; UIImage *image = [UIImage imageWithData:data]; This is the function from that thread: - (BOOL)isJPEGValid:(NSData *)jpeg { if ([jpeg length] < 4) return NO; const char * bytes = (const char *)[jpeg bytes]; if (bytes[0] != 0xFF || bytes[1] != 0xD8) return NO; if (bytes[[jpeg

Convert Data-URL to BufferedImage

风流意气都作罢 提交于 2019-11-30 13:13:02
问题 I have a Data-URL from an image file and have to pass it through to another function. Along this path from Data-URL to the BufferedImage it needs to be a byteArray. my approach was the following: String dataUrl; byte[] imageData = dataUrl.getBytes(); // pass the byteArray along the path // create BufferedImage from byteArray BufferedImage inputImage = ImageIO.read(new ByteArrayInputStream(imageData)); // If the picture is null, then throw an unsupported image exception. if (inputImage == null

BufferedImage getRGB vs Raster getSample

我与影子孤独终老i 提交于 2019-11-30 10:05:59
I am trying to do some image processing in Java. I used ImageIO library for reading and writing images. I can read the image pixel value in two ways as follows (there might be other methods which do not know). Using BufferedImage's getRGB method: pixel = image.getRGB(x,y); Using Raster's getSample method: WritableRaster raster = image.getRaster(); pixel = raster.getSample(x,y,0); What is the difference in the above two approaches? 1: The first approach will always return a pixel in int ARGB format, and in the sRGB color space. Regardless of the image's internal representation. This means that

Convert Data-URL to BufferedImage

爱⌒轻易说出口 提交于 2019-11-30 06:49:16
I have a Data-URL from an image file and have to pass it through to another function. Along this path from Data-URL to the BufferedImage it needs to be a byteArray. my approach was the following: String dataUrl; byte[] imageData = dataUrl.getBytes(); // pass the byteArray along the path // create BufferedImage from byteArray BufferedImage inputImage = ImageIO.read(new ByteArrayInputStream(imageData)); // If the picture is null, then throw an unsupported image exception. if (inputImage == null) { throw new UnknownImageFormatException(); } The problem is, it always throws the

Pure Java alternative to JAI ImageIO for detecting CMYK images

心不动则不痛 提交于 2019-11-30 03:41:41
first I'd like to explain the situation/requirements that lead to the question: In our web application we can't support CMYK images (JPEG) since IE 8 and below can't display them. Thus we need to detect when someone wants to upload such an image and deny it. Unfortunately, Java's ImageIO won't read those images or would not enable me to get the detected color space. From debugging it seems like JPEGImageReader internally gets the color space code 11 (which would mean JCS_YCCK ) but I can't safely access that information. When querying the reader for the image types I get nothing for CMYK, so I

Increasing screen capture speed when using Java and awt.Robot

我们两清 提交于 2019-11-30 01:51:31
问题 Edit: If anyone also has any other recommendations for increasing performance of screen capture please feel free to share as it might fully address my problem! Hello Fellow Developers, I'm working on some basic screen capture software for myself. As of right now I've got some proof of concept/tinkering code that uses java.awt.Robot to capture the screen as a BufferedImage. Then I do this capture for a specified amount of time and afterwards dump all of the pictures to disk. From my tests I'm

Toolkit.getDefaultToolkit().createImage() vs ImageIO.read()

守給你的承諾、 提交于 2019-11-29 18:59:34
问题 I'm creating a UI using Swing and I want to display an image in a JLabel . The code I use is the following: JLabel label = new JLabel(new ImageIcon(ImageIO.read(new File("img.jpg")))); This works fine if I use png images but when it comes to jpg (only some of them), I get a redish image (a different one than the one I see in Paint.NET). The image I used is this one: img.jpg So I tried (as an alternative): Toolkit.getDefaultToolkit().createImage(new File("img.jpg").getAbsolutePath()); Does

ImageIO: <ERROR> JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?

喜你入骨 提交于 2019-11-29 18:34:38
问题 I get this error by downloading an image by HTTP. I have looked at the answer here but even the valid images don't return YES from the function. Any other ideas? The code to get the image is simple enough. This happens in a background thread. NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]; UIImage *image = [UIImage imageWithData:data]; This is the function from that thread: - (BOOL)isJPEGValid:(NSData *)jpeg { if ([jpeg length] < 4) return NO; const char * bytes

Java ImageIO.write() takes up to 6 seconds

感情迁移 提交于 2019-11-29 17:01:19
I am writing an web application where I need to send an image from servlet to client. Image is generated dynamically and is quite big(+-2MB). It might be jpeg, png, or gif. Now, I am using ImageIO.write() to write the image to output stream, but its veeeery slow. It takes up to 6 seconds till the client see the image. I need to speed it up. Any suggestions? btw. I am aware of Looking for a faster alternative to ImageIO topic. But it didn't help me. Since it's slow with PNG ImageMagick is not a solution and I have tested JAI and it was even worse. Thanks in advance Edit: To show you some code: