Discord Server Red Security Twitter Donation to Red Security Red Security Youtube Channel Red Security Tumblr Profile
Windscribe
Login or Register to Hide ads and Accessing all features on the forum
Thread Rating:
  • 4 Vote(s) - 2.75 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Project Resizing Mulitple Images at Once [Java]
#1
Big Grin 
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
Reply


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 1,407 03-20-2020, 08:49 PM
Last Post: Mr.Kurd
Question Why Java Strings are immutable in nature? Mr.Kurd 0 356 03-20-2020, 08:47 PM
Last Post: Mr.Kurd
Question What is constructor chaining in Java? Mr.Kurd 0 354 03-20-2020, 08:43 PM
Last Post: Mr.Kurd
Question What is the difference between equals() and == in Java? Mr.Kurd 0 366 03-20-2020, 08:40 PM
Last Post: Mr.Kurd
  What public static void main(String args[]) stand for in Java? Mr.Kurd 0 417 03-20-2020, 08:38 PM
Last Post: Mr.Kurd
Question Why multiple inheritance is not supported in java? Mr.Kurd 0 390 03-20-2020, 08:34 PM
Last Post: Mr.Kurd
  Tutorial Taking Screenshot in Java Mr.Kurd 0 436 03-09-2020, 05:38 PM
Last Post: Mr.Kurd
  10 java skills HeavensReject 1 586 01-12-2020, 05:31 AM
Last Post: Mr.Kurd
Wink Tutorial Downloading video from Youtube using JAVA Mr.Kurd 0 1,263 02-06-2019, 06:33 PM
Last Post: Mr.Kurd
  Tutorial Java and SSH Mr.Kurd 0 1,086 12-16-2018, 08:05 PM
Last Post: Mr.Kurd



Users browsing this thread: 1 Guest(s)