Written a c program for image resize with MagickWand and called that c program from java (with the help JNA) and called that c program with multi thread concept
problem : image resize is not working & unable to call the c program parallely
How to call the resize c program parallely
CProgram
Below is the Java Code Which call the C Program (resize operation ) parallely
problem : image resize is not working & unable to call the c program parallely
How to call the resize c program parallely
CProgram
CODE:
#include <stdio.h>#include <stdlib.h>#include <MagickWand/MagickWand.h>void open(void);void resize(char *,char *);void close(void);int main(){ char oldImage[100],newImage[100]; open(); resize(oldImage,newImage); close(); return(0);}void open(){ //Starting Magick Wand Environment MagickWandGenesis();}void close(){ //Terminates the MagickWand environment MagickWandTerminus();}void resize(char *oldImage,char *newImage){ MagickWand *magick_wand; //Allocate the memory to the Magick Wand magick_wand=NewMagickWand(); MagickReadImage(magick_wand,oldImage); // resize the image MagickResizeImage(magick_wand,1000,1000,LanczosFilter); //Write the image then destroy it. MagickWriteImage(magick_wand,newImage); //Deallocates the memory associated with MagickWand DestroyMagickWand(magick_wand);}
CODE:
import java.io.*;import java.util.*;import java.lang.*;import java.io.FileNotFoundException;import java.io.IOException;import com.sun.jna.Library;import com.sun.jna.Native;public class MultiThread extends Thread{public static String image;public static String resized;interface resize extends Library{public void open();public void resize(String oldImage,String newImage);public void close();}public void run(){try{System.out.println("Thread "+Thread.currentThread().getId()+" is running" );resize obj=(resize)Native.loadLibrary("resize",resize.class);obj.resize(image,resized);}catch(Exception e){System.out.println(e);}}public static void processImage(){try{BufferedReader br=new BufferedReader( new FileReader("imagesList.txt") );BufferedReader breader=new BufferedReader( new FileReader("resizeImagesList.txt") );while( (image = br.readLine()) != null && (resized = breader.readLine()) != null ){if(image.length() == 0){break;}MultiThread obj=new MultiThread();obj.start();}}catch(FileNotFoundException e){System.out.println(e);}catch(IOException e){System.out.println(e);}}public static void main(String arg[]){resize obj=(resize)Native.loadLibrary("resize",resize.class);obj.open();processImage();obj.close();}}
Statistics: Posted by ArunKumar — 2020-03-05T00:27:24-07:00