Java - Java Programing -Java Web Hosting

Blog About Java Programing and Java Technologies

Java 2D Graphics compositing rule A compositing rule

Filed under: Java 2D Graphics — webmaster @ 7:42 am

Java 2D Graphics Let’s walk through the pipeline. It can be described in five steps, where the first step depends heavily on which primitive is being rendered. 1. Determine the shape to be rendered. This is different for each of the rendering operations. For shapes that will be filled, the shape is simply transformed using the Graphics2D’s current transformation. For shapes whose outlines are drawn using draw(), the current stroke is used to turn the outline into a shape. Then the stroked outline is transformed, just like any other filled shape. Text is displayed by translating characters to shapes using the current font. The resulting shapes are transformed, just like any other filled shape. For images, the outline of the image is transformed using the current transformation. As you can see, the rendering engine knows only how to fill shapes and draw images. Although drawing shape outlines and drawing text appear to be distinct operations, they are really special cases of filling shapes. 2. Rasterize the shape. Rasterizing is the process of converting an ideal shape to a set of pixel coverage values. I’ll explain more about this later. In the case of images, it’s the outline of the image that is rasterized. Rendering hints are used to control the behavior of the rasterization. 3. Clip the results using the current clipping shape. 4. Determine the colors to be used. For a filled shape, use the current paint object to determine what colors should be used to fill the shape. For an image, the colors are taken from the image itself. 5. Combine the colors with the existing drawing using the current compositing rule. 2.3 All About Alpha Rendering is an approximation. When you ask to have an ideal shape filled, the rendering engine figures out how the pixels of an output device should be colored to best approximate the shape. For example, suppose the rendering engine is asked to fill a shape with some color. There’s a fast way to do it, and then there’s a good way to do it. 2.3.1 Aliasing and Antialiasing The fast method is to color the pixels whose centers fall within the shape. Using this algorithm, pixels are either fully colored or left unchanged. Figure 2.3 shows an example of this technique with a single letter shown on some device with very large pixels. The ideal outline of the shape is also shown. The filled shape exhibits unattractive jaggies, or ragged edges. Images produced using this algorithm are said to be aliased. Figure 2.3. Aliased rendering page 21

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Blog About Java Programing and Java Technologies

Java 2D Graphics compositing rule A compositing rule

Filed under: Java 2D Graphics — webmaster @ 7:42 am

Java 2D Graphics compositing rule A compositing rule is used to determine how the colors of a primitive should be combined with existing colors on the Graphics2D’s drawing surface. clipping shape All rendering operations are limited to the interior of the clipping shape. No pixels outside of this shape will be modified. By default, the clipping shape is null, which means that the drawing is limited only by the drawing surface. rendering hints There are different techniques that can be used to render graphics primitives. Rendering hints tell a Graphics2D which techniques you want to use. The current paint and stroke elements apply only to shapes; these are covered in Chapter 4. I’ll talk about fonts and text in Chapter 6. The remaining four parts of Graphics2D’s state are discussed in Chapter 5. Graphics primitives pass through the rendering engine in a series of operations, called the rendering pipeline.[1] Figure 2.2 shows how the Graphics2D’s seven elements of internal state are used in the rendering pipeline. The figure shows Graphics2D’s four basic operations: [1] The actual implementation of the rendering engine may combine or compress different parts of the pipeline. Conceptually, however, it’s useful to think of a series of distinct operations. You can fill a shape by passing it to the fill() method. In the 2D API, shapes are represented by implementations of the java.awt.Shape interface. You can draw the outline of a shape by calling draw(). Text is rendered by calling one of Graphics2D’s drawString() methods. You can draw an image by passing a java.awt.Image to one of the drawImage() methods. Figure 2.2. Rendering, in detail page 20

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Blog About Java Programing and Java Technologies

Java 2D Graphics } To run this example,

Filed under: Java 2D Graphics — webmaster @ 12:17 am

Java 2D Graphics engine performs this work; in the 2D API, the Graphics2D class is the rendering engine. Figure 2.1 shows this process at a high level. The 2D rendering engine takes care of the details of underlying devices and can accurately reproduce the geometry and color of a drawing, regardless of the device that displays it. Figure 2.1. Rendering, the short story Apart from being a rendering engine, an instance of Graphics2D also represents a drawing surface, which is simply some collection of pixels, each of which holds a color. It might be the inside of a window or a page in a printer, or even an offscreen image. Each time you draw something new, the new element is added to the existing drawing represented by the Graphics2D. 2.2 The Rendering Pipeline Graphics2D uses its internal state to decide exactly how graphics primitives are converted to pixel colors. For example, part of Graphics2D’s internal state is a java.awt.Paint object, which describes the colors that should be used to fill shapes. Whenever you ask Graphics2D to fill a shape, it uses its current Paint to fill the shape. Graphics2D ’s internal state is comprised of seven elements: paint The current paint determines what colors will be used to fill a shape. This also affects shape outlines and text, since stroked outlines and character shapes are both filled. stroke Graphics2D uses the current stroke for shapes that are passed to its draw() method. The stroke determines how the outline of the shape is drawn. The resulting shape (the stroked outline) is then filled. font Text is rendered by creating a shape that represents the characters to be drawn. The current font determines what shapes are created for a given set of characters. The resulting shape is then filled. transformation All primitives are geometrically transformed before they are rendered. This means that they may be moved, rotated, and stretched. Graphics2D’s transformation converts primitives from User Space to Device Space. By default, Graphics2D creates a transformation that maps 72 User coordinates to one inch on the output device. page 19

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

Blog About Java Programing and Java Technologies

Java 2D Graphics } To run this example,

Filed under: Java 2D Graphics — webmaster @ 12:17 am

Java 2D Graphics } To run this example, do the following: C:> java ShowOff You can change the image used, the string that is displayed, and the point at which the string background changes from red to blue. In the following command, the image Daphne & Luke.jpg will be used. The string displayed will be “DaphneLuke,” with the background color transition occurring between “Daphne” and “Luke.” C:> java ShowOff “Daphne & Luke.jpg” DaphneLuke 6 How does it work? Internally, the ShowOff example is divided into eight pieces: 1. The main() method handles setting up a frame window to contain a ShowOff, which is a Component subclass. 2. ShowOff’s constructor loads the image file, creates a font that will be used later, and sets the size of the component to match the size of the image. Image loading will be covered in Chapter 9. Fonts are explained in Chapter 6. 3. The paint() method draws the picture you see in Figure 1.1. It does this using three helper methods: drawBackground(), drawImageMosaic(), and drawText(). 4. The drawBackground() method draws circles of different colors across the area of the component. Chapter 3 contains information on creating shapes, and Chapter 4 describes different ways they can be drawn. 5. The drawImageMosaic() method divides up the image into square tiles and draws each tile with a calculated amount of transparency. See Chapter 5 for a description of transparency and compositing rules. 6. The drawText() method takes care of drawing the text (”Java2D” by default). Most of this process involves measuring the text so that it is correctly positioned. The text is drawn twice, once on the bottom of the component, and once, rotated, going up the right side of the component. (Rotation and other transformations are covered in Chapter 5.) This method uses two helper methods, drawString() and drawBoxedString(). 7. The drawString() method splits up the text into two pieces. The first piece is drawn on top of a color gradient running from white to red. The second piece is drawn on top of a color gradient running from blue to white. 8. The drawBoxedString() method handles drawing a string and a background rectangle with a color gradient. Color gradients are described in Chapter 4, while text is covered in Chapter 6. Chapter 2. The Big Picture The Graphics2D class is the cornerstone of Java 2D. But what is it, exactly? And how does it work? In this chapter, I’ll lay the groundwork for the rest of the book by covering the fundamental topics of the 2D API. I’ll talk about the Graphics2D class, compositing, and coordinate spaces. 2.1 Graphics2D Rendering is the process of taking a collection of shapes, text, and images and figuring out what colors the pixels should be on a screen or printer. Shapes, text, and images are called graphics primitives ; screens and printers are called output devices. If I wanted to be pompous, I’d tell you that rendering is the process of displaying graphics primitives on output devices. A rendering page 18

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

Blog About Java Programing and Java Technologies

Java 2D Graphics public ShowOff(String filename, String message,

Filed under: Java 2D Graphics — webmaster @ 6:05 pm

Java 2D Graphics int h = Math.min(side, height - y); BufferedImage tile = mImage.getSubimage(x, y, w, h); g2.drawImage(tile, x, y, null); } } // Reset the composite. g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); } protected void drawText(Graphics2D g2) { // Find the bounds of the entire string. FontRenderContext frc = g2.getFontRenderContext(); mLayout = new TextLayout(mMessage, mFont, frc); // Find the dimensions of this component. int width = getSize().width; int height = getSize().height; // Place the first full string, horizontally centered, // at the bottom of the component. Rectangle2D bounds = mLayout.getBounds(); double x = (width - bounds.getWidth()) / 2; double y = height - bounds.getHeight(); drawString(g2, x, y, 0); // Now draw a second version, anchored to the right side // of the component and rotated by -PI / 2. drawString(g2, width - bounds.getHeight(), y, -Math.PI / 2); } protected void drawString(Graphics2D g2, double x, double y, double theta) { // Transform to the requested location. g2.translate(x, y); // Rotate by the requested angle. g2.rotate(theta); // Draw the first part of the string. String first = mMessage.substring(0, mSplit); float width = drawBoxedString(g2, first, Color.white, Color.red, 0); // Draw the second part of the string. String second = mMessage.substring(mSplit); drawBoxedString(g2, second, Color.blue, Color.white, width); // Undo the transformations. g2.rotate(-theta); g2.translate(-x, -y); } protected float drawBoxedString(Graphics2D g2, String s, Color c1, Color c2, double x) { // Calculate the width of the string. FontRenderContext frc = g2.getFontRenderContext(); TextLayout subLayout = new TextLayout(s, mFont, frc); float advance = subLayout.getAdvance(); // Fill the background rectangle with a gradient. GradientPaint gradient = new GradientPaint((float)x, 0, c1, (float)(x + advance), 0, c2); g2.setPaint(gradient); Rectangle2D bounds = mLayout.getBounds(); Rectangle2D back = new Rectangle2D.Double(x, 0, advance, bounds.getHeight()); g2.fill(back); // Draw the string over the gradient rectangle. g2.setPaint(Color.white); g2.setFont(mFont); g2.drawString(s, (float)x, (float)-bounds.getY()); return advance; } page 17

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Blog About Java Programing and Java Technologies

Java 2D Graphics public ShowOff(String filename, String message,

Filed under: Java 2D Graphics — webmaster @ 6:05 pm

Java 2D Graphics public ShowOff(String filename, String message, int split) throws IOException, ImageFormatException { // Get the specified image. InputStream in = getClass().getResourceAsStream(filename); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in); mImage = decoder.decodeAsBufferedImage(); in.close(); // Create a font. mFont = new Font(”Serif”, Font.PLAIN, 116); // Save the message and split. mMessage = message; mSplit = split; // Set our size to match the image’s size. setSize((int)mImage.getWidth(), (int)mImage.getHeight()); } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D)g; // Turn on antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); drawBackground(g2); drawImageMosaic(g2); drawText(g2); } protected void drawBackground(Graphics2D g2) { // Draw circles of different colors. int side = 45; int width = getSize().width; int height = getSize().height; Color[] colors = { Color.yellow, Color.cyan, Color.orange, Color.pink, Color.magenta, Color.lightGray }; for (int y = 0; y < height; y += side) { for (int x = 0; x < width; x += side) { Ellipse2D ellipse = new Ellipse2D.Float(x, y, side, side); int index = (x + y) / side % colors.length; g2.setPaint(colors[index]); g2.fill(ellipse); } } } protected void drawImageMosaic(Graphics2D g2) { // Break the image up into tiles. Draw each// tile with its own transparency, allowing// the background to show through to varying// degrees. int side = 36; int width = mImage.getWidth(); int height = mImage.getHeight(); for (int y = 0; y < height; y += side) { for (int x = 0; x < width; x += side) { // Calculate an appropriate transparency value. float xBias = (float)x / (float)width; float yBias = (float)y / (float)height; float alpha = 1.0f - Math.abs(xBias - yBias); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, alpha)); // Draw the subimage. int w = Math.min(side, width - x); page 16

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Blog About Java Programing and Java Technologies

Java 2D Graphics 1.6.2 JPEG JPEG stands for

Filed under: Java 2D Graphics — webmaster @ 10:29 am

Java 2D Graphics Then the example draws an image. The image is broken into small pieces, and each piece is drawn partially transparent, allowing the circles to show through. The image is Raphael’s self-portrait, taken from the Virtual Uffizi at http://www.arca.net/uffizi/. Finally, the example draws some text on a color-gradient-filled background. Then the text is drawn a second time, rotated 90 . The results are shown in Figure 15.1. This is a less than 200 lines of code (with lots of comments). It’s a small subset of what can be accomplished with the 2D API. Note that this example depends on the ApplicationFrame class presented earlier in this chapter. If you haven’t entered and compiled ApplicationFrame, do it now.[3] [3] Like all the other examples in this book, ShowOff is available online. See the Preface for details. import java.awt.*; import java.awt.event.*; import java.awt.font.*; import java.awt.geom.*; import java.awt.image.BufferedImage; import java.io.*; import java.util.Random; import com.sun.image.codec.jpeg.*; public class ShowOffextends Component { public static void main(String[] args) { try { // The image is loaded either from this // default filename or the first command- // line argument. // The second command-line argument specifies // what string will be displayed. The third // specifies at what point in the string the // background color will change. String filename = “Raphael.jpg”; String message = “Java2D”; int split = 4; if (args.length > 0) filename = args[0]; if (args.length > 1) message = args[1]; if (args.length > 2) split = Integer.parseInt(args[2]); ApplicationFrame f = new ApplicationFrame(”ShowOff v1.0″); f.setLayout(new BorderLayout()); ShowOff showOff = new ShowOff(filename, message, split); f.add(showOff, BorderLayout.CENTER); f.setSize(f.getPreferredSize()); f.center(); f.setResizable(false); f.setVisible(true); } catch (Exception e) { System.out.println(e); System.exit(0); } } private BufferedImage mImage; private Font mFont; private String mMessage; private int mSplit; private TextLayout mLayout; page 15

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Blog About Java Programing and Java Technologies

Java 2D Graphics 1.6.2 JPEG JPEG stands for

Filed under: Java 2D Graphics — webmaster @ 10:29 am

Java 2D Graphics 1.6.2 JPEG JPEG stands for Joint Photographic Experts Group. Unlike some other file formats, it was designed specifically for photographic images. JPEG images support more colors than GIF images, up to 24 bits per pixel. JPEG images are compressed before being stored using a lossy compression algorithm. This means that when the image is loaded and displayed, it will not be exactly the same as the original image. The 2D API includes support for reading and writing JPEG files in the com.sun.image.codec.jpeg package, which is covered in Chapter 9. 1.6.3 Utilities There are many utilities that convert images between different file formats. Here are five freeware or shareware solutions: GNU Image Manipulation Program (GIMP) (Unix, freeware) Much of the functionality of Adobe Photoshop is included in this freeware application. See http://www.gimp.org/. ImageMagick (Unix, freeware) This free application lets you convert from one file format to another, change the size of an image, and perform other basic manipulations. See http://www.imagemagick.com. xv (Unix, shareware) This shareware application performs a variety of image manipulation functions. The full source code is available. See http://www.trilon.com/xv/xv.html. GraphicConverter (MacOS, shareware) This versatile tool handles most common graphics file formats with a clean interface and lots of useful features. See http://www.lemkesoft.de/us_index.html. LView Pro (Windows, shareware) This is a Windows program, similar to GraphicConverter for the Mac. It handles a variety of file formats and offers some editing features. See http://www.lview.com/. If you’re more serious about images and image processing, you should get a real tool like Adobe’s Photoshop (http://www.adobe.com/) or Live Picture from the company of the same name (http://www.mgisoft.com/index_flash.asp). 1.7 Hello, 2D! This chapter ends with a bang an example that demonstrates the power of the 2D API. You probably won’t understand much of the code at this point, but rest assured that it all will become clear as you work through the rest of the book. In general terms, this is what the example does: The example draws a background of colored circles. page 14

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Blog About Java Programing and Java Technologies

Java 2D Graphics It works exactly the same

Filed under: Java 2D Graphics — webmaster @ 4:25 am

Java 2D Graphics public ApplicationFrame(String title) { super(title); createUI(); } protected void createUI() { setSize(500, 400); center(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); System.exit(0); } }); } public void center() { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = getSize(); int x = (screenSize.width - frameSize.width) / 2; int y = (screenSize.height - frameSize.height) / 2; setLocation(x, y); } } Remember that the programming examples in this book are available online. See the Preface for details. 1.6 File Formats There are many, many ways to store graphics information in a file. In this section I’ll briefly describe two formats, GIF and JPEG. These formats are common currencies of the Internet any web browser that shows images knows how to show GIF and JPEG images. Similarly, the JDK can load and display GIF or JPEG images. For more detailed information on these formats, or on other popular graphics file formats, see the Encyclopedia of Graphics File Formats , by James D. Murray and William vanRyper (O’Reilly). 1.6.1 GIF GIF stands for Graphics Interchange Format. GIF images can have 2 to 256 colors and are compressed before being stored. The compression algorithm is lossless, which means that the original picture will be restored verbatim when the image is decompressed and displayed. There are actually two common flavors of this format, GIF87a and GIF89a. GIF89a offers the option of designating one of the image colors as transparent. Applications that know how to show GIF89a images correctly will allow the background to show through the transparent areas of the image. You’ve probably seen these “transparent GIFs” in web pages. GIF89a also supports simple animations, which you’ve probably seen in web pages. These are called animated GIFs ; they’ve been supported in Java since JDK 1.1. For more information on animated GIFs, see GIF Animation Studio by Richard Koman (published by Songline Studios, Inc.). page 13

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Blog About Java Programing and Java Technologies

Java 2D Graphics It works exactly the same

Filed under: Java 2D Graphics — webmaster @ 4:25 am

Java 2D Graphics It works exactly the same way in Java 2, except that it’s a Graphics2D that is passed to paint(). To take advantage of all the spiffy 2D features, you’ll have to perform a cast in your paint() method, like this: public void paint(Graphics g) { Graphics2D g2 = (Graphics2D)g; // Now we can do cool 2D stuff. } Note that your component may not necessarily be drawn on the screen. The Graphics2D that gets passed to paint() might actually represent a printer or any other output device. Swing components work almost the same way. Strictly speaking, however, you should implement the paintComponent() method instead of paint(). Swing uses the paint() method to draw child components. Swing’s implementation of paint() calls paintComponent() to draw the component itself. You may be able to get away with implementing paint() instead of paintComponent(), but then don’t be surprised if the component is not drawn correctly. 1.5.2 Drawing on Images You can use a Graphics or Graphics2D to draw on images, as well. If you have an Image that you have created yourself, you can get a corresponding Graphics2D by calling createGraphics(), as follows: public void drawOnImage(Image i) { Graphics g = i.getGraphics(); // Now draw on the image using g. } This works only for any Image you’ve created yourself, not for an Image loaded from a file. If you have a BufferedImage (Java 2D’s new image class), you can obtain a Graphics2D as follows: public void drawOnBufferedImage(BufferedImage bi) { Graphics2D g2 = bi.createGraphics(); // Now draw on the image using g2. } I’ll talk more about these techniques in Chapter 9. 1.5.3 ApplicationFrame Many of the examples in this book assume that you have a Graphics2D object to work with. This section contains a simple test window that makes it easy to use a Graphics2D. The window, ApplicationFrame, appears centered on your screen and goes away when you close it. You can test Graphics2D features easily by subclassing ApplicationFrame and overriding the paint() method. import java.awt.*; import java.awt.event.*; public class ApplicationFrameextends Frame { public ApplicationFrame() { this(”ApplicationFrame v1.0″); } page 12

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

« Previous PageNext Page »

Powered by Java Web Hosting

Windows 7 Требует Драйвер Dvd Драйвера Для Веб Камеры Lenovo руководство по массажу скачать Asrock N68 S Драйвера Скачать руководство по эксплуатации уаз патриот Asus A8j Драйвера руководство по ремонту ваз 21120 руководство по ремонту daf Acer Aspire 5315 Драйвера Скачать понятие и характеристика стилей руководства Sb Audigy Драйвер востание под руководством степана разина Logitech Quickcam V Um14 Драйвер Lenovo 3000 G430 Скачать Драйвера Cmi8738 Pci Sx Драйвер Скачать Драйвера Asus T101mt руководство по эксплуатации киа церато Defender Km 2080b Драйвер руководство по ремонту тойота авенсис Скачать Драйвер Hp Photosmart C6283 руководство по эксплуатации nokia 8800 Dv Драйвера Ethernet 10 100 Драйвер Драйвера Asus F5rseries педагогическое руководство коллективом руководство пользователя тойота приус Genius Colorpage Hr6x Slim Драйвер Драйвер Lg K1 руководство по эксплуатации ваз2121 Sony Ericsson Z520 Драйвера руководство по эксплуатации ваз 2170 руководство astra h Samsung R525 Драйвера Xp Avertv 203 Драйвер Скачать руководство пользователя видеорегистратор требования к руководству по качеству Epson Epl 6200l Драйвер руководство по качеству строительной организации citroen c3 руководство по ремонту Драйвер Acer Для Сетевого Адаптера руководство toyota windom руководство по ремонту калина калина Скачать Драйвер Epson Stylus Cx4100 Logitech C300 Драйвера руководство по эксплуатации ваз 21074 Toshiba Satellite P10 Драйвера руководство по эксплуатации нокиа n8 руководство по ремонту bmw e34 Canon 4300 Драйвер спин практическое руководство Canyon Cnp Wcam320 Драйвера Скачать руководство по ремонту ford explorer Emachines G630g Драйвера руководство mazda 323 f Epson Stylus C86 Драйвера формы руководства руководство по эксплуатации опель антара Видео Драйвер Geforce руководство по эксплуатации mazda premacy wingroad руководство по эксплуатации скачать Драйвер Ep 8kmm3i руководство по ремонту funcargo скачать openoffice calc руководство