Creating a scaleUp main method in a new class
So I'm trying to create a class with a method called ScaleUp which basically scales a .jpg file by a certain amount. So far I have:
Code :
import java.util.*;
public class ScaleUp
{
public static void main(String[] args) {
/* HERE FROM PREVIOUS ATTEMPT:*/
Scanner sc = new Scanner(System.in);
System.out.print("File: ");
String fileShortName = sc.next();
String fileName = "/C:/Users/Umar/Desktop/Comp Sci/Dr. Java Add Ons/mediasources/" +
fileShortName + ".jpg";
System.out.print("Scale: ");
int numTimes = sc.nextInt();
Picture pictObj = new Picture(fileName);
}
public static Picture scaleUp(int numTimes)
{
String fileName = FileChooser.pickAFile();
Picture origPic = new Picture(fileName);
Picture targetPicture =
new Picture(origPic.getWidth() * numTimes,
origPic.getHeight() * numTimes);
Pixel sourcePixel = null;
Pixel targetPixel = null;
int targetX = 0;
int targetY = 0;
for (int sourceX = 0;
sourceX < origPic.getWidth();
sourceX++)
{
for (int sourceY=0;
sourceY < origPic.getHeight();
sourceY++)
{
sourcePixel = origPic.getPixel(sourceX,sourceY);
for (int indexY = 0; indexY < numTimes; indexY++)
{
for (int indexX = 0; indexX < numTimes; indexX++)
{
targetX = sourceX * numTimes + indexX;
targetY = sourceY * numTimes + indexY;
targetPixel = targetPicture.getPixel(targetX,
targetY);
targetPixel.setColor(sourcePixel.getColor());
}
}
}
}
return targetPicture;
}
}
However, when I run the program I can use scanner to input information it accepts the info but no picture file is shown. Can someone please show me how I can get the program to actually spit out the picture that the method is invoked on?
Re: Creating a scaleUp main method in a new class
First get your terminology straight. You don't scale a file. You can scale an image. It's not relevant to the scaling what type of file the image was read from.
Your code uses Picture and Pixel classes which are not part of the standard JDK and which we know nothing about. You need to seek help wherever you got the classes from.
db