bufferedimage

Changing lsb value of image rgb value giving inconsistent value

可紊 提交于 2019-12-31 05:42:22
问题 I am trying to change the lsb value of image pixels such that it matches with the string "abc" but adding 1 or 0 to a pixel with odd value is returning 0. here is the code: public static void main(String[] args) { BufferedImage img = null; try { img = ImageIO.read(new File("a.jpg")); } catch (IOException ex) { } int pixel[] = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth()); String s = "abc"; byte[] b = s.getBytes(); String f = ""; for (int i = 0; i < b.length; i++)

BufferedImage fill rectangle with transparent pixels

白昼怎懂夜的黑 提交于 2019-12-31 05:05:07
问题 I have a BufferedImage and I am trying to fill a rectangle with transparent pixels. The problem is, instead of replacing the original pixels, the transparent pixels just go on top and do nothing. How can I get rid of the original pixel completely? The code works fine for any other opaque colors. public static BufferedImage[] slice(BufferedImage img, int slices) { BufferedImage[] ret = new BufferedImage[slices]; for (int i = 0; i < slices; i++) { ret[i] = copyImage(img); Graphics2D g2d = ret[i

Set Color as int value for use in setRGB(int x, int y, int rgb) method? — Java

安稳与你 提交于 2019-12-31 04:58:13
问题 Any other errors aside, I need a way of converting my Color grayScale into an int. When I plug in the Color, I get an error. setRGB method takes an x, a y, and an rgb int as parameters. How do I change my Color into an int? import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import javax.swing.*; import java.awt.image.*; import javax.imageio.ImageIO; public class Picture{ Container content; BufferedImage image, image2; public Picture(String filename) { File f =

Java BufferedImage JPG compression without writing to file

♀尐吖头ヾ 提交于 2019-12-31 03:33:10
问题 I've seen several examples of making compressed JPG images from Java BufferedImage objects by writing to file, but is it possible to perform JPG compression without writing to file? Perhaps by writing to a ByteArrayOutputStream like this? ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next(); ImageWriteParam jpgWriteParam = jpgWriter.getDefaultWriteParam(); jpgWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpgWriteParam.setCompressionQuality(0.7f);

how can I convert an image to grayscale without losing transparency?

一世执手 提交于 2019-12-30 10:36:49
问题 I am having problems converting a colored image with some transparent pixels to grayscale. I have searched and found related questions on this website but nothing I have been able to use to solve my problem. I have defined a method "convertType" as follows: /*------------------------------ attempts to convert the type of the image argument to the chosen type for example: BufferedImage newImage= ImageUtilities.convertType(oldImage, BufferedImage.TYPE_3BYTE_BGR); 11/28/2013 WARNING-it remains

Getting Greyscale pixel value from RGB colourspace in Java using BufferedImage

倖福魔咒の 提交于 2019-12-30 10:24:09
问题 Anyone know of a simple way of converting the RGBint value returned from <BufferedImage> getRGB(i,j) into a greyscale value? I was going to simply average the RGB values by breaking them up using this; int alpha = (pixel >> 24) & 0xff; int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel) & 0xff; and then average red,green,blue. But i feel like for such a simple operation I must be missing something... After a great answer to a different question, I should clear

Write to 16 bit BufferedImage TYPE_USHORT_GRAY

蹲街弑〆低调 提交于 2019-12-30 07:11:33
问题 I'm trying to write 16 bit grayscale imagedata to a png using BufferedImage.TYPE_USHORT_GRAY. Normally I write to an image like so: BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); then: image.setRGB(x,y,Color.getRGB); to set the pixels, and finally: ImageIO.write(image, "png", new File(path + ".png")); to write to a png image. But now I have this as image: BufferedImage imageGray = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_GRAY); How do I

How to make gradient border of an image using java?

爱⌒轻易说出口 提交于 2019-12-30 04:50:08
问题 How can I make an image border as gradient. I googled a lot, but didn't find correct suggestion. Any one can help me... Any suggestion please... 回答1: This is an interesting one. I first thought that there should be a simple solution, using some Graphics#drawRoundRect call with the appropriate Paint , but it's not sooo simple. However, one solution is implemented in the following example: The image is painted as-it-is into a new image. Then the edges and corners are painted. These consist of

How do I speed up this swing animation?

匆匆过客 提交于 2019-12-29 09:17:28
问题 I am drawing an animation onto a swing JPanel. The 1024x1024 screen is divided up into 2000 pieces which cover the screen exactly (no overlap). each piece is a very small piece of the screen (1/2000'th of it). The animation draws one piece every millisecond by changing the pixels in the buffered image and calling reaint(). So at the entire screen changes every 2 seconds. The animation is run in a java.util.Timer task. The buffered image is not accelerated and is not volatile. I set it's

How to disable java.awt.Graphics.fillRect(int x, int y, int width, int height)'s effect?

半世苍凉 提交于 2019-12-29 09:17:09
问题 It's the original image: I use java.awt.Graphics.fillRect(int x, int y, int width, int height) to add a coloured rectangle on the image. Graphics imageGraphics = image.createGraphics(); Color color = new Color(0,0,0,100); imageGraphics.setColor(color); imageGraphics.fillRect(0, 0, 800, 600); So the image has been inverted and looks like this: After that,I want to clear the black transparent rectangle partly and show the original image. imageGraphics.clearRect(100,100,100,100); But the effect