Discord Server Red Security Twitter Donation to Red Security Red Security Youtube Channel Red Security Tumblr Profile
Login or Register to Hide ads and Accessing all features on the forum

Project 

Resizing Mulitple Images at Once [Java]

0 Replies, 1972 Views

In The Name OF Allah
Al-Salam Alekum

A script for resizing images in Java:

PHP Code:
import java.awt.image.*;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/*
 * @author LOL
 *
 */
public class ImageTest {

    private static final int IMG_WIDTH 42;
    private static final int IMG_HEIGHT 42;
    
    public 
static void main(String [] args){
        
    try
{
            File folder = new File("Location of the folder");
            File[] listOfFiles folder.listFiles();

            for (int i 0listOfFiles.lengthi++) {
                if (listOfFiles[i].isFile()) {
        
                    BufferedImage img 
ImageIO.read(listOfFiles[i]);
                    int type img.getType() == 0BufferedImage.TYPE_INT_ARGB img.getType();
                    BufferedImage resizeImagePng resizeImage(imgtype);
                    ImageIO.write(resizeImagePng"png", new File("c:\\image\\" listOfFiles[i].getName()));
                    
                
}
            }
        }catch(IOException e){
        System.out.println(e.getMessage());
    }
    
        
        
        
    
}
    
    
private static BufferedImage resizeImage(BufferedImage originalImageint type){
    BufferedImage resizedImage = new BufferedImage(IMG_WIDTHIMG_HEIGHTtype);
    Graphics2D g resizedImage.createGraphics();
    g.drawImage(originalImage00IMG_WIDTHIMG_HEIGHTnull);
    g.dispose();
        
    return resizedImage
;
    }
    
    
private static BufferedImage resizeImageWithHint(BufferedImage originalImageint type){
        
    BufferedImage resizedImage 
= new BufferedImage(IMG_WIDTHIMG_HEIGHTtype);
    Graphics2D g resizedImage.createGraphics();
    g.drawImage(originalImage00IMG_WIDTHIMG_HEIGHTnull);
    g.dispose();    
    g
.setComposite(AlphaComposite.Src);

    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING,
    RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    
    return resizedImage
;
    }    



Wa Salam Alekum
Rs
* Thankful to Allah *
Kurdy

Possibly Related Threads…
Thread Author Replies Views Last Post
Question What is the difference between ‘throw’ and ‘throws’ in Java Exception Handling? Mr.Kurd 0 5,157 03-20-2020, 08:49 PM
Last Post: Mr.Kurd
Question Why Java Strings are immutable in nature? Mr.Kurd 0 2,593 03-20-2020, 08:47 PM
Last Post: Mr.Kurd
Question What is constructor chaining in Java? Mr.Kurd 0 2,549 03-20-2020, 08:43 PM
Last Post: Mr.Kurd
Question What is the difference between equals() and == in Java? Mr.Kurd 0 2,575 03-20-2020, 08:40 PM
Last Post: Mr.Kurd
  What public static void main(String args[]) stand for in Java? Mr.Kurd 0 2,623 03-20-2020, 08:38 PM
Last Post: Mr.Kurd
Question Why multiple inheritance is not supported in java? Mr.Kurd 0 2,565 03-20-2020, 08:34 PM
Last Post: Mr.Kurd
  Tutorial Taking Screenshot in Java Mr.Kurd 0 2,654 03-09-2020, 05:38 PM
Last Post: Mr.Kurd
  10 java skills HeavensReject 1 3,355 01-12-2020, 05:31 AM
Last Post: Mr.Kurd
Wink Tutorial Downloading video from Youtube using JAVA Mr.Kurd 0 5,289 02-06-2019, 06:33 PM
Last Post: Mr.Kurd
  Tutorial Java and SSH Mr.Kurd 0 3,373 12-16-2018, 08:05 PM
Last Post: Mr.Kurd



Users browsing this thread: 2 Guest(s)