<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FSWT_2D_Graphics%2FPNG_GIF</id>
		<title>Java Tutorial/SWT 2D Graphics/PNG GIF - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FSWT_2D_Graphics%2FPNG_GIF"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/SWT_2D_Graphics/PNG_GIF&amp;action=history"/>
		<updated>2026-04-21T20:14:12Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/SWT_2D_Graphics/PNG_GIF&amp;diff=2799&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/SWT_2D_Graphics/PNG_GIF&amp;diff=2799&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:26Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:44, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/SWT_2D_Graphics/PNG_GIF&amp;diff=2800&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/SWT_2D_Graphics/PNG_GIF&amp;diff=2800&amp;oldid=prev"/>
				<updated>2010-05-31T15:18:11Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Display an animated GIF ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*******************************************************************************&lt;br /&gt;
 * Copyright (c) 2000, 2004 IBM Corporation and others.&lt;br /&gt;
 * All rights reserved. This program and the accompanying materials&lt;br /&gt;
 * are made available under the terms of the Eclipse Public License v1.0&lt;br /&gt;
 * which accompanies this distribution, and is available at&lt;br /&gt;
 * http://www.eclipse.org/legal/epl-v10.html&lt;br /&gt;
 *&lt;br /&gt;
 * Contributors:&lt;br /&gt;
 *     IBM Corporation - initial API and implementation&lt;br /&gt;
 *******************************************************************************/&lt;br /&gt;
//package org.eclipse.swt.snippets;&lt;br /&gt;
/*&lt;br /&gt;
 * Image example snippet: display an animated GIF&lt;br /&gt;
 *&lt;br /&gt;
 * For a list of all SWT example snippets see&lt;br /&gt;
 * http://www.eclipse.org/swt/snippets/&lt;br /&gt;
 */&lt;br /&gt;
import org.eclipse.swt.SWT;&lt;br /&gt;
import org.eclipse.swt.SWTException;&lt;br /&gt;
import org.eclipse.swt.graphics.Color;&lt;br /&gt;
import org.eclipse.swt.graphics.GC;&lt;br /&gt;
import org.eclipse.swt.graphics.Image;&lt;br /&gt;
import org.eclipse.swt.graphics.ImageData;&lt;br /&gt;
import org.eclipse.swt.graphics.ImageLoader;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.FileDialog;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
public class AnimatedGIFDisplay {&lt;br /&gt;
  static Display display;&lt;br /&gt;
  static Shell shell;&lt;br /&gt;
  static GC shellGC;&lt;br /&gt;
  static Color shellBackground;&lt;br /&gt;
  static ImageLoader loader;&lt;br /&gt;
  static ImageData[] imageDataArray;&lt;br /&gt;
  static Thread animateThread;&lt;br /&gt;
  static Image image;&lt;br /&gt;
  static final boolean useGIFBackground = false;&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    display = new Display();&lt;br /&gt;
    shell = new Shell(display);&lt;br /&gt;
    shell.setSize(300, 300);&lt;br /&gt;
    shell.open();&lt;br /&gt;
    shellGC = new GC(shell);&lt;br /&gt;
    shellBackground = shell.getBackground();&lt;br /&gt;
    FileDialog dialog = new FileDialog(shell);&lt;br /&gt;
    dialog.setFilterExtensions(new String[] { &amp;quot;*.gif&amp;quot; });&lt;br /&gt;
    String fileName = dialog.open();&lt;br /&gt;
    if (fileName != null) {&lt;br /&gt;
      loader = new ImageLoader();&lt;br /&gt;
      try {&lt;br /&gt;
        imageDataArray = loader.load(fileName);&lt;br /&gt;
        if (imageDataArray.length &amp;gt; 1) {&lt;br /&gt;
          animateThread = new Thread(&amp;quot;Animation&amp;quot;) {&lt;br /&gt;
            public void run() {&lt;br /&gt;
              /*&lt;br /&gt;
               * Create an off-screen image to draw on, and fill it with the&lt;br /&gt;
               * shell background.&lt;br /&gt;
               */&lt;br /&gt;
              Image offScreenImage = new Image(display, loader.logicalScreenWidth,&lt;br /&gt;
                  loader.logicalScreenHeight);&lt;br /&gt;
              GC offScreenImageGC = new GC(offScreenImage);&lt;br /&gt;
              offScreenImageGC.setBackground(shellBackground);&lt;br /&gt;
              offScreenImageGC.fillRectangle(0, 0, loader.logicalScreenWidth,&lt;br /&gt;
                  loader.logicalScreenHeight);&lt;br /&gt;
              try {&lt;br /&gt;
                /* Create the first image and draw it on the off-screen image. */&lt;br /&gt;
                int imageDataIndex = 0;&lt;br /&gt;
                ImageData imageData = imageDataArray[imageDataIndex];&lt;br /&gt;
                if (image != null &amp;amp;&amp;amp; !image.isDisposed())&lt;br /&gt;
                  image.dispose();&lt;br /&gt;
                image = new Image(display, imageData);&lt;br /&gt;
                offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height,&lt;br /&gt;
                    imageData.x, imageData.y, imageData.width, imageData.height);&lt;br /&gt;
                /*&lt;br /&gt;
                 * Now loop through the images, creating and drawing each one on&lt;br /&gt;
                 * the off-screen image before drawing it on the shell.&lt;br /&gt;
                 */&lt;br /&gt;
                int repeatCount = loader.repeatCount;&lt;br /&gt;
                while (loader.repeatCount == 0 || repeatCount &amp;gt; 0) {&lt;br /&gt;
                  switch (imageData.disposalMethod) {&lt;br /&gt;
                  case SWT.DM_FILL_BACKGROUND:&lt;br /&gt;
                    /* Fill with the background color before drawing. */&lt;br /&gt;
                    Color bgColor = null;&lt;br /&gt;
                    if (useGIFBackground &amp;amp;&amp;amp; loader.backgroundPixel != -1) {&lt;br /&gt;
                      bgColor = new Color(display, imageData.palette.getRGB(loader.backgroundPixel));&lt;br /&gt;
                    }&lt;br /&gt;
                    offScreenImageGC.setBackground(bgColor != null ? bgColor : shellBackground);&lt;br /&gt;
                    offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width,&lt;br /&gt;
                        imageData.height);&lt;br /&gt;
                    if (bgColor != null)&lt;br /&gt;
                      bgColor.dispose();&lt;br /&gt;
                    break;&lt;br /&gt;
                  case SWT.DM_FILL_PREVIOUS:&lt;br /&gt;
                    /* Restore the previous image before drawing. */&lt;br /&gt;
                    offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height,&lt;br /&gt;
                        imageData.x, imageData.y, imageData.width, imageData.height);&lt;br /&gt;
                    break;&lt;br /&gt;
                  }&lt;br /&gt;
                  imageDataIndex = (imageDataIndex + 1) % imageDataArray.length;&lt;br /&gt;
                  imageData = imageDataArray[imageDataIndex];&lt;br /&gt;
                  image.dispose();&lt;br /&gt;
                  image = new Image(display, imageData);&lt;br /&gt;
                  offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height,&lt;br /&gt;
                      imageData.x, imageData.y, imageData.width, imageData.height);&lt;br /&gt;
                  /* Draw the off-screen image to the shell. */&lt;br /&gt;
                  shellGC.drawImage(offScreenImage, 0, 0);&lt;br /&gt;
                  /*&lt;br /&gt;
                   * Sleep for the specified delay time (adding commonly-used&lt;br /&gt;
                   * slow-down fudge factors).&lt;br /&gt;
                   */&lt;br /&gt;
                  try {&lt;br /&gt;
                    int ms = imageData.delayTime * 10;&lt;br /&gt;
                    if (ms &amp;lt; 20)&lt;br /&gt;
                      ms += 30;&lt;br /&gt;
                    if (ms &amp;lt; 30)&lt;br /&gt;
                      ms += 10;&lt;br /&gt;
                    Thread.sleep(ms);&lt;br /&gt;
                  } catch (InterruptedException e) {&lt;br /&gt;
                  }&lt;br /&gt;
                  /*&lt;br /&gt;
                   * If we have just drawn the last image, decrement the repeat&lt;br /&gt;
                   * count and start again.&lt;br /&gt;
                   */&lt;br /&gt;
                  if (imageDataIndex == imageDataArray.length - 1)&lt;br /&gt;
                    repeatCount--;&lt;br /&gt;
                }&lt;br /&gt;
              } catch (SWTException ex) {&lt;br /&gt;
                System.out.println(&amp;quot;There was an error animating the GIF&amp;quot;);&lt;br /&gt;
              } finally {&lt;br /&gt;
                if (offScreenImage != null &amp;amp;&amp;amp; !offScreenImage.isDisposed())&lt;br /&gt;
                  offScreenImage.dispose();&lt;br /&gt;
                if (offScreenImageGC != null &amp;amp;&amp;amp; !offScreenImageGC.isDisposed())&lt;br /&gt;
                  offScreenImageGC.dispose();&lt;br /&gt;
                if (image != null &amp;amp;&amp;amp; !image.isDisposed())&lt;br /&gt;
                  image.dispose();&lt;br /&gt;
              }&lt;br /&gt;
            }&lt;br /&gt;
          };&lt;br /&gt;
          animateThread.setDaemon(true);&lt;br /&gt;
          animateThread.start();&lt;br /&gt;
        }&lt;br /&gt;
      } catch (SWTException ex) {&lt;br /&gt;
        System.out.println(&amp;quot;There was an error loading the GIF&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    while (!shell.isDisposed()) {&lt;br /&gt;
      if (!display.readAndDispatch())&lt;br /&gt;
        display.sleep();&lt;br /&gt;
    }&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Write an animated GIF to a file ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*******************************************************************************&lt;br /&gt;
 * Copyright (c) 2000, 2005 IBM Corporation and others.&lt;br /&gt;
 * All rights reserved. This program and the accompanying materials&lt;br /&gt;
 * are made available under the terms of the Eclipse Public License v1.0&lt;br /&gt;
 * which accompanies this distribution, and is available at&lt;br /&gt;
 * http://www.eclipse.org/legal/epl-v10.html&lt;br /&gt;
 *&lt;br /&gt;
 * Contributors:&lt;br /&gt;
 *     IBM Corporation - initial API and implementation&lt;br /&gt;
 *******************************************************************************/&lt;br /&gt;
//package org.eclipse.swt.snippets;&lt;br /&gt;
/*&lt;br /&gt;
 * Write an animated GIF to a file.&lt;br /&gt;
 * &lt;br /&gt;
 * For a list of all SWT example snippets see&lt;br /&gt;
 * http://www.eclipse.org/swt/snippets/&lt;br /&gt;
 */&lt;br /&gt;
import org.eclipse.swt.SWT;&lt;br /&gt;
import org.eclipse.swt.graphics.Color;&lt;br /&gt;
import org.eclipse.swt.graphics.Font;&lt;br /&gt;
import org.eclipse.swt.graphics.GC;&lt;br /&gt;
import org.eclipse.swt.graphics.Image;&lt;br /&gt;
import org.eclipse.swt.graphics.ImageData;&lt;br /&gt;
import org.eclipse.swt.graphics.ImageLoader;&lt;br /&gt;
import org.eclipse.swt.graphics.PaletteData;&lt;br /&gt;
import org.eclipse.swt.graphics.RGB;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
public class AnimatedGIFWriteFile {&lt;br /&gt;
  static Display display;&lt;br /&gt;
  static Color white, red, green, blue;&lt;br /&gt;
  static PaletteData palette;&lt;br /&gt;
  static Font font;&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    display = new Display();&lt;br /&gt;
    RGB whiteRGB = new RGB(0xff, 0xff, 0xff);&lt;br /&gt;
    RGB redRGB = new RGB(0xff, 0, 0);&lt;br /&gt;
    RGB greenRGB = new RGB(0, 0xff, 0);&lt;br /&gt;
    RGB blueRGB = new RGB(0, 0, 0xff);&lt;br /&gt;
    palette = new PaletteData(new RGB[] { whiteRGB, // 0&lt;br /&gt;
        redRGB, // 1&lt;br /&gt;
        greenRGB, // 2&lt;br /&gt;
        blueRGB }); // 3&lt;br /&gt;
    white = new Color(display, whiteRGB);&lt;br /&gt;
    red = new Color(display, redRGB);&lt;br /&gt;
    green = new Color(display, greenRGB);&lt;br /&gt;
    blue = new Color(display, blueRGB);&lt;br /&gt;
    font = new Font(display, &amp;quot;Comic Sans MS&amp;quot;, 24, SWT.BOLD);&lt;br /&gt;
    ImageData[] data = new ImageData[4];&lt;br /&gt;
    data[0] = newFrame(&amp;quot;&amp;quot;, white, false, 0, 0, 101, 55, SWT.DM_FILL_NONE, 40);&lt;br /&gt;
    data[1] = newFrame(&amp;quot;S&amp;quot;, red, true, 0, 0, 30, 55, SWT.DM_FILL_NONE, 40);&lt;br /&gt;
    data[2] = newFrame(&amp;quot;W&amp;quot;, green, true, 28, 0, 39, 55, SWT.DM_FILL_NONE, 40);&lt;br /&gt;
    data[3] = newFrame(&amp;quot;T&amp;quot;, blue, true, 69, 0, 32, 55, SWT.DM_FILL_BACKGROUND, 200);&lt;br /&gt;
    ImageLoader loader = new ImageLoader();&lt;br /&gt;
    loader.data = data;&lt;br /&gt;
    loader.backgroundPixel = 0;&lt;br /&gt;
    loader.logicalScreenHeight = data[0].height;&lt;br /&gt;
    loader.logicalScreenWidth = data[0].width;&lt;br /&gt;
    loader.repeatCount = 0; // run forever&lt;br /&gt;
    loader.save(&amp;quot;swt.gif&amp;quot;, SWT.IMAGE_GIF);&lt;br /&gt;
    white.dispose();&lt;br /&gt;
    red.dispose();&lt;br /&gt;
    green.dispose();&lt;br /&gt;
    blue.dispose();&lt;br /&gt;
    font.dispose();&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
  private static ImageData newFrame(String letter, Color color, boolean transparent, int x, int y,&lt;br /&gt;
      int width, int height, int disposalMethod, int delayTime) {&lt;br /&gt;
    ImageData temp = new ImageData(width, height, 2, palette); // 4-color&lt;br /&gt;
                                                                // palette has&lt;br /&gt;
                                                                // depth 2&lt;br /&gt;
    Image image = new Image(display, temp);&lt;br /&gt;
    GC gc = new GC(image);&lt;br /&gt;
    gc.setBackground(white);&lt;br /&gt;
    gc.fillRectangle(0, 0, width, height);&lt;br /&gt;
    gc.setForeground(color);&lt;br /&gt;
    gc.setFont(font);&lt;br /&gt;
    gc.drawString(letter, 5, 5);&lt;br /&gt;
    gc.dispose();&lt;br /&gt;
    ImageData frame = image.getImageData();&lt;br /&gt;
    if (transparent)&lt;br /&gt;
      frame.transparentPixel = 0; // white&lt;br /&gt;
    image.dispose();&lt;br /&gt;
    frame.x = x;&lt;br /&gt;
    frame.y = y;&lt;br /&gt;
    frame.disposalMethod = disposalMethod;&lt;br /&gt;
    frame.delayTime = delayTime;&lt;br /&gt;
    return frame;&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Write an Image to a PNG file ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*******************************************************************************&lt;br /&gt;
 * Copyright (c) 2000, 2006 IBM Corporation and others.&lt;br /&gt;
 * All rights reserved. This program and the accompanying materials&lt;br /&gt;
 * are made available under the terms of the Eclipse Public License v1.0&lt;br /&gt;
 * which accompanies this distribution, and is available at&lt;br /&gt;
 * http://www.eclipse.org/legal/epl-v10.html&lt;br /&gt;
 *&lt;br /&gt;
 * Contributors:&lt;br /&gt;
 *     IBM Corporation - initial API and implementation&lt;br /&gt;
 *******************************************************************************/&lt;br /&gt;
//package org.eclipse.swt.snippets;&lt;br /&gt;
/*&lt;br /&gt;
 * Write an Image to a PNG file.&lt;br /&gt;
 * &lt;br /&gt;
 * For a list of all SWT example snippets see&lt;br /&gt;
 * http://www.eclipse.org/swt/snippets/&lt;br /&gt;
 */&lt;br /&gt;
import org.eclipse.swt.*;&lt;br /&gt;
import org.eclipse.swt.graphics.*;&lt;br /&gt;
import org.eclipse.swt.widgets.*;&lt;br /&gt;
public class PNGFileWriteImage {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Display display = new Display();&lt;br /&gt;
    Font font = new Font(display, &amp;quot;Comic Sans MS&amp;quot;, 24, SWT.BOLD);&lt;br /&gt;
    Image image = new Image(display, 87, 48);&lt;br /&gt;
    GC gc = new GC(image);&lt;br /&gt;
    gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));&lt;br /&gt;
    gc.fillRectangle(image.getBounds());&lt;br /&gt;
    gc.setFont(font);&lt;br /&gt;
    gc.setForeground(display.getSystemColor(SWT.COLOR_RED));&lt;br /&gt;
    gc.drawString(&amp;quot;S&amp;quot;, 3, 0);&lt;br /&gt;
    gc.setForeground(display.getSystemColor(SWT.COLOR_GREEN));&lt;br /&gt;
    gc.drawString(&amp;quot;W&amp;quot;, 25, 0);&lt;br /&gt;
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));&lt;br /&gt;
    gc.drawString(&amp;quot;T&amp;quot;, 62, 0);&lt;br /&gt;
    gc.dispose();&lt;br /&gt;
    ImageLoader loader = new ImageLoader();&lt;br /&gt;
    loader.data = new ImageData[] {image.getImageData()};&lt;br /&gt;
    loader.save(&amp;quot;swt.png&amp;quot;, SWT.IMAGE_PNG);&lt;br /&gt;
    image.dispose();&lt;br /&gt;
    font.dispose();&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>