How to scaling images in java applet, JAVA Programming

Assignment Help:

How to Scaling Images in java applet?

You can scale an image within a particular rectangle using this version of the drawImage() method:

public boolean drawImage(Image img, int x, int y, int width,
int height, ImageObserver io)

width and height specify the size of the rectangle to scale the image into. All other arguments are the similar as before. If the scale is not in proportion to the size of the image, it can end up looking quite squashed.

To prevent disproportionate scaling use the image's getHeight() and getWidth() methods to denotes the actual size. Then scale appropriately. For examples this is how you would draw an Image scaled through one quarter in each dimension:

g.drawImage(img, 0, 0, img.getWidth(this)/4, img.getHeight(this)/4, this);

This program reads a GIF file in the same directory as the HTML file and displays it at a particular magnification. The name of the GIF file and the magnification factor are specified through PARAMs.
import java.awt.*;
import java.applet.*;

public class MagnifyImage extends Applet {

private Image image;
private int scaleFactor;

public void init() {
String filename = this.getParameter("imagefile");
this.image = this.getImage(this.getDocumentBase(), filename);
this.scaleFactor = Integer.parseInt(this.getParameter("scalefactor"));
}

public void paint (Graphics g) {
int width = this.image.getWidth(this);
int height = this.image.getHeight(this);
scaledWidth = width * this.scaleFactor;
scaledHeight = height * this.scaleFactor;
g.drawImage(this.image, 0, 0, scaledWidth, scaledHeight, this);
}

}
This applet is straightforward. The init() method reads two PARAMs, one the name of the image file, the other the magnification factor. The paint() method computes the scale and then draws the image. 


Related Discussions:- How to scaling images in java applet

Algorithm, #question)i) devising ii) validating and iii) tes...

#question)i) devising ii) validating and iii) testing of algorithms...

What is jms, Java Message Service: An interface executed by most J2EE conta...

Java Message Service: An interface executed by most J2EE containers to give point-to-point queueing and topic (publish/subscribe) behavior. JMS is frequently used by EJB's that req

Explain jsp technology?, Java Server Page is a standard Java extension that...

Java Server Page is a standard Java extension that is described on top of the servlet Extensions. The goal of JSP is the simplified formation and management of dynamic Web pages. J

What is preferred organizational structure for organization, What is the pr...

What is the preferred organizational structure for the organization? Preferred Organizational Structure for organization is hierarchal. Where there is various departments inter

File handling operation, Write a program called Drivers that displays infor...

Write a program called Drivers that displays information about Formula 1 drivers and their teams.     The program starts by prompting (asking) the user for the name of an input tex

Assingment, hi i want to get my assingment done

hi i want to get my assingment done

What is the use of message object, Message is a light weight message having...

Message is a light weight message having only header and properties and no payload. Therefore if the If the receivers are to be notified about an event, and no data requires to be

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd