Results 1 to 3 of 3
- 03-02-2010, 09:29 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
- 03-02-2010, 06:01 PM #2
Here are the steps:
1) Load your 660X650 image into a BufferedImage
2) Create your new smaller image as a compatible BufferedImage in order to retain the same color and image settings
3) Get the Graphics object of the new image
4) Scale graphics object in order to shrink the image
5) Draw the old image to the new image
Here is a rough untested code:
Java Code:int newWidth = 100; int newHeight = 150; //image is your 660x650 BuferedImage Graphics2D g2d = (Graphics2D)image.getGraphics(); BufferedImage newImage = g2d.getDeviceConfiguration().createCompatibleImage( newWidth , newHeight, java.awt.Transparency.OPAQUE); g2d = (Graphics2D)newImage.getGraphics(); //i didn't test this g2d.scale(newWidth/660.0, newHeight/650.0); g2d.drawImage(image, 0, 0, null);My Hobby Project: LegacyClone
- 03-03-2010, 07:30 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 2
- Rep Power
- 0
Thanks mrmatt1111
but the problem not solved, it shows me blank frame.
here is the code
But when i redraw the image with new drawImage and new width and height it works, but image getting is not clear.Java Code://My resetImage class class resetImage extends JFrame { scanPixel sp = new scanPixel(); //Getting BufferedImage 640 x 600 BufferedImage resetimage = sp.getBufferedImage(); //reset into new width and height int newWidth = 400; int newHeight = 450; public resetImage() { setSize(newWidth,newHeight); setVisible(true); } public void paint(Graphics g) { //your code Image img = (Image)resetimage; //Graphics2D g2d = (Graphics2D)g; Graphics2D g2d = (Graphics2D)resetimage.getGraphics(); BufferedImage newImage = g2d.getDeviceConfiguration().createCompatibleImage( newWidth , newHeight, java.awt.Transparency.OPAQUE); g2d = (Graphics2D)newImage.getGraphics(); //i didn't test this g2d.scale(newWidth/sp.width, newHeight/sp.height); //g2d.translate(x,y); //you might need to move it to make it fit g2d.drawImage(newImage, 0, 0, null); } }
thanks :)
Similar Threads
-
how to resize an image
By marodia in forum AWT / SwingReplies: 2Last Post: 08-21-2009, 04:10 AM -
[SOLVED] manipulating the pixel values of an image and constructinf a new image from
By sruthi_2009 in forum AWT / SwingReplies: 14Last Post: 04-10-2009, 08:46 AM -
Image Resize
By jithan in forum New To JavaReplies: 4Last Post: 11-07-2008, 09:26 AM -
Retaining DB values as well as Dynamically generated Values.. Help Needed !
By rajivjha in forum Advanced JavaReplies: 0Last Post: 05-22-2008, 10:53 AM -
Accessing boolean Values of another values in one class.
By a_iyer20 in forum Advanced JavaReplies: 4Last Post: 04-15-2008, 01:04 PM


LinkBack URL
About LinkBacks


Bookmarks