bufferedimage

BufferedImage not displaying (all black) but Image can be displayed

一个人想着一个人 提交于 2019-12-23 10:26:32
问题 I'm new to Java graphics (computer graphics in general) and Stack Overflow, so please help me out and help me phrase my problem better. At the moment, I'm trying to display a BufferedImage alongside the original image in a Java GUI. This is my code: Image oriImage = robot.getQwerkController().getVideoStreamService().getFrame(); //load the original image Graphics2D hi = bufferedImage.createGraphics(); hi.drawImage(oriImage, 0,0, null); //draw the original image into the BufferedImage hi

Java: drawing scaled objects (buffered image and vector graphics)

和自甴很熟 提交于 2019-12-23 04:57:23
问题 I would like to draw scaled objects containing raster as well as vector data. Currently, I am drawing into a scaled Graphics2D object protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); //Get transformation, apply scale and shifts at = g2d.getTransform(); at.translate(x, y); at.scale(zoom, zoom); //Transform Graphics2D object g2d.setTransform(at); //Draw buffered image into the transformed object g2d.drawImage(img, 0, 0, this); //Draw

convert color image to grayscale

荒凉一梦 提交于 2019-12-23 03:30:35
问题 I want to convert a color image to grayscale.First I getting the data of color image and change this data but when I want to create a gary image from this data I have a error like this... getData() maethod: public double[] getData(BufferedImage a){ double[] data2=new double[h*w]; int red=0,green=0,blue=0; int counter=0; for(int w1=0;w1<w;w1++){ for(int h1=0;h1<h;h1++){ int rgb=a.getRGB(w1,h1); red=(rgb)>> 16; green=(rgb)>>8; blue=(rgb); data2[counter]=(red+green+blue)/3; counter++; } } return

Copy the contents of a JPanel onto a BufferedImage

蓝咒 提交于 2019-12-23 02:17:20
问题 On the first time through, I insert BufferedImage s from a list onto my JPanel from my extended class: @Override protected void paintComponent(Graphics g){ super.paintComponent(g); if (controlWhichImage == 1){ for (BufferedImage eachImage : docList){ g.drawImage(eachImage, 0,inty,imageWidth,imageHeight,null); intx += eachImage.getWidth(); inty += eachImage.getHeight() * zoomAdd; } if (intx >= this.getWidth() || inty >= this.getHeight()){ inty = 0; } The next time I want to copy the contents

Convert buffered image to the 2D byte array with the same data

陌路散爱 提交于 2019-12-22 12:12:07
问题 I have written one application for image processing in Java. I have processed the image which is the buffered image and now I want to return the byte[] for that processed image that is I should get the byte array of binarized image. Here is my code: public static byte[][] binarizeImage(BufferedImage bfImage){ int red; int newPixel; int h ; int w ; int threshold = otsuTreshold(bfImage); // this function returns the threshold value 199 BufferedImage binarized = new BufferedImage(bfImage

How to get a BufferedImage from a Component in java?

丶灬走出姿态 提交于 2019-12-22 05:31:25
问题 I know how to get a BufferedImage from JComponent, but how to get a BufferedImage from a Component in java ? The emphasis here is an object of the "Component" type rather than JComponent. I tried the following method, but it return an all black image, what's wrong with it ? public static BufferedImage Get_Component_Image(Component myComponent,Rectangle region) throws IOException { BufferedImage img = new BufferedImage(myComponent.getWidth(), myComponent.getHeight(), BufferedImage.TYPE_INT_RGB

java Buffered Image : Detecting black pixels

两盒软妹~` 提交于 2019-12-22 04:17:11
问题 I have this simple code to go through a 24bit color windows bmp file BufferedImage mapa = BMPDecoder.read(new File("maps/map.bmp")); final int xmin = mapa.getMinX(); final int ymin = mapa.getMinY(); final int ymax = ymin + mapa.getHeight(); final int xmax = xmin + mapa.getWidth(); for (int i = xmin;i<xmax;i++) { for (int j = ymin;j<ymax;j++) { int pixel = mapa.getRGB(i, j); if (pixel == 0) { System.out.println("black at "+i+","+j); } } } However, when testing on a completely black image, I

How to convert a BufferedImage to 8 bit?

社会主义新天地 提交于 2019-12-22 04:01:36
问题 I was looking at the ImageConverter class, trying to figure out how to convert a BufferedImage to 8-bit color, but I have no idea how I would do this. I was also searching around the internet and I could find no simple answer, they were all talking about 8 bit grayscale images. I simply want to convert the colors of an image to 8 bit... nothing else, no resizing no nothing. Does anyone mind telling me how to do this. 回答1: This code snippet from the article "Transparent gifs in Java" at G-Man

Java HTTP Post Applet server - Internally generated Image

夙愿已清 提交于 2019-12-22 01:31:19
问题 I have a BufferedImage created using J2D in an applet. I want to upload this BufferedImage using HTTP Post @ http://localhost:3001/upload/file. EDIT: I have a ROR server handling the serverside of things, I am looking for the Java code for the client. All the examples I can find involve uploading Files. Anybody know how to upload a BufferedImage? Cheers, slotishtype 回答1: OK, So here is the code that creates the bufferedimage, encodes it as a Base64 string and then using the apache commons

Convert OpenCV Mat object to BufferedImage

允我心安 提交于 2019-12-21 12:43:09
问题 I am trying to create a helper function using OpenCV Java API that would process an input image and return the output byte array. The input image is a jpg file saved in the computer. The input and output image are displayed in the Java UI using Swing. System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // Load image from file Mat rgba = Highgui.imread(filePath); Imgproc.cvtColor(rgba, rgba, Imgproc.COLOR_RGB2GRAY, 0); // Convert back to byte[] and return byte[] return_buff = new byte[(int) (rgba