![]() Just do: Image newImage yourImage.getScaledInstance(newWidth, newHeight, Image. JPanel mainPanel new JPanel () //Assume this is the panel you are placing things into. If you have an, resizing it doesnt require any additional libraries. Then, call Image. First, use Image class to load the image you want to resize. Place the JPanel where you would have originally placed the component. The following are the steps to resize an image in Java. ![]() This code example will show an image that is scaled to fit the component size, keeping its aspect ratio, and centered horizontally or vertically in the exceeding space. Create a JPanel specifically for the component. repaint () ADDITION: You told me that you wanted it to be the same size as your form. ![]() drawImage (Image img, int x, int y, int width, int height, ImageObserver observer) Your canvas should get repainted when you re-size your form, but if it doesnt you can force it with. ![]() Another thing to keep in mind: if the image is a CMYK jpeg it might be bigger. Only then will you be able to scale the image. You can do this using a custom component, like this, in the overridden paintComponent, do all the calculation for the new scale and draw the image. As for reducing file size: since the image would already be a JPEG the only things you could do is reduce the quality or the image size. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |