I have a png image which contains black and transparency in the black area. I need to draw my other image, and retain the transparency area as is. What are all the possibilities we have in Java using graphic2d this is the PNG i am reffering
Related
I am currently working with a DICOM project in java. I am calculating the dicom values such as depth, off-axis ratio, width and height. I want to create a sample image with the calculated width and height. I should be a gray scale image, with varying densities of gray color in appropriate area. I have created a sample image with imagemagick, using concentric circles. Bit am not getting the exact image. It does not look like an actual dicom image. The variation of gray color does not have a linear behavior. Sample image is attached. Please suggest any other method to create dicom image. The density values are available in a list. depending upon the distance from the center, the gray color also changes according to the density value provided.
Pixel Data or image in DICOM data set is always rectangular and image is described using Rows (0028, 0010) and Columns (0028, 0011) attributes. So the best way to implement this is to draw your circular image on a rectangular background. Fill the background with a color that is not present in your image. Use the Pixel Padding Value (0028,0120) to specify the color used to pad grayscale images (those with a Photometric Interpretation of MONOCHROME1 or MONOCHROME2) to rectangular format.
If you do not have any color to spare (with-in the bit stored), you can add Overlay Plane or Display Shutter to the data set to mask the area that is not part of image.
I need to crop images for a "Photoprint" app of mine. To create appropriate image for printing paper, image will be scaled up, scaled down and cropped by dragging to specific field of image in a frame. Only short edge or long edge of the image could have empty space, two edges shouldn't have empty spaces at the same time. Any of height or width should fit the crop frame. By the way, crop frame should stay the same size. For example; for a 5x7" printing paper, frame will have 504x306px size.
Could you help me, image crop algorithm?
I want to inset a image into a background and save it, both are png files with transparency, below code work fine but new image become black & white only.
BufferedImage BUFFEREDIMAGE1=ImageIO.read(new File(strPATH+"/IMAGE.png"));
BufferedImage BUFFEREDIMAGE2=ImageIO.read(new File(strPATH+"/WATERMARK.png"));
Graphics2D GRAPHICS1=BUFFEREDIMAGE1.createGraphics();
GRAPHICS1.drawImage(BUFFEREDIMAGE2,intLeft,intTop,intWidth,intHeight,null);
GRAPHICS1.dispose();
ImageIO.write(BUFFEREDIMAGE2,"png",new File(strPATH,"SAVED.png"));
The most likely cause is that at some point the colour space of the image is becoming changed. You may be better off explicitly creating a new destination BufferedImage with the RGB or RGBA format and writing both source Images into it. This removes any possible variation in that area.
I have a canvas on which I am adding primitive shapes like square, circles etc. Is it possible to get the content drawn on the canvas in form of a Buffered Image.
I actually aim to access single pixels from the canvas, and couldn't find a better way of doing this?
Try this approach:
1.) Create a bufferedimage the width and height of the canvas
2.) Create a graphics2D object from the new bufferedimage
3.) Use the paint(g2d) or paintall(g2d) method of your canvas object
So you have something like:
BufferedImage myBI = new BufferedImage(myCanvas.getWidth(), myCanvas.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = myBI.createGraphics();
myCanvas.paint(g);
Your canvas should now be painted into the bufferedimage.
The question of whether to draw from a canvas to a bufferedimage or to draw from a bufferedimage to a canvas has to do with speed and with image quality. Drawing to buffered image is faster than drawing to canvas, but that might not matter if you are just doing this for static images. But you may also notice a difference in image quality. I have printed jpanels to buffered image and then to jpg files, and have noticed reduced image quality.
I have drawn any picture, used Graphics 2D. How do I get the colour of a pixel at x, y? getPixelColor don't work, because this method get pixel from screen, not applet viewer coordinates.
Draw the picture to the Graphics of a BufferedImage
Draw the image to the Graphics2D.
To get the color of any pixel, call BufferedImage.getRGB(x,y) or variants (check the docs.).