forked from nus-cs2103-AY1718S1/addressbook-level4-old
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from tshradheya/CollateV1.4
Collate v1.4
- Loading branch information
Showing
4 changed files
with
3,570 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# tshradheya-unused | ||
###### \java\seedu\address\commons\events\storage\ReadAndStoreImage.java | ||
``` java | ||
package seedu.address.commons.events.storage; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_IMAGE; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import javax.imageio.ImageIO; | ||
|
||
import seedu.address.logic.commands.DisplayPictureCommand; | ||
import seedu.address.logic.parser.exceptions.ImageException; | ||
|
||
/** | ||
* To read image from specified path and store in @file resources/pictures | ||
*/ | ||
public class ReadAndStoreImage { | ||
|
||
/** | ||
* @param path | ||
* @return uniquePath new path in directory | ||
*/ | ||
public String execute(String path, int newPath) throws IOException { | ||
|
||
File fileToRead = null; | ||
BufferedImage image = null; | ||
|
||
File fileToWrite = null; | ||
|
||
String uniquePath = null; | ||
|
||
try { | ||
fileToRead = new File(path); | ||
image = new BufferedImage(963, 640, BufferedImage.TYPE_INT_ARGB); | ||
image = ImageIO.read(fileToRead); | ||
|
||
uniquePath = Integer.toString(newPath); | ||
|
||
fileToWrite = new File("src\\main\\resources\\pictures\\" + uniquePath + ".jpg"); | ||
ImageIO.write(image, "jpg", fileToWrite); | ||
|
||
|
||
} catch (IOException e) { | ||
throw new ImageException(String.format(MESSAGE_INVALID_IMAGE, | ||
DisplayPictureCommand.MESSAGE_IMAGE_PATH_FAIL)); | ||
} | ||
|
||
return uniquePath; | ||
|
||
} | ||
|
||
|
||
} | ||
``` |
Oops, something went wrong.