Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 281914 Details for
Bug 560298
[GTK] SWT-ImageLoader load animated Gif produce wrong index order
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
example program
DesignerDialog.java (text/x-java), 5.94 KB, created by
Sunneo IceCold
on 2020-02-24 22:27:30 EST
(
hide
)
Description:
example program
Filename:
MIME Type:
Creator:
Sunneo IceCold
Created:
2020-02-24 22:27:30 EST
Size:
5.94 KB
patch
obsolete
>package com.insyde.swtdesigner; > >/******************************************************************************* > * Copyright (c) 2000, 2004 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: > * IBM Corporation - initial API and implementation > *******************************************************************************/ >//package org.eclipse.swt.snippets; >/* > * Image example snippet: display an animated GIF > * > * For a list of all SWT example snippets see > * http://www.eclipse.org/swt/snippets/ > */ >import org.eclipse.swt.SWT; >import org.eclipse.swt.SWTException; >import org.eclipse.swt.graphics.Color; >import org.eclipse.swt.graphics.GC; >import org.eclipse.swt.graphics.Image; >import org.eclipse.swt.graphics.ImageData; >import org.eclipse.swt.graphics.ImageLoader; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.FileDialog; >import org.eclipse.swt.widgets.Shell; > >public class DesignerDialog { > static Display display; > > static Shell shell; > > static GC shellGC; > > static Color shellBackground; > > static ImageLoader loader; > > static ImageData[] imageDataArray; > > static Thread animateThread; > > static Image image; > > static final boolean useGIFBackground = false; > > public static void main(String[] args) { > display = new Display(); > shell = new Shell(display); > shell.setSize(800,800); > shell.open(); > shellGC = new GC(shell); > shellBackground = shell.getBackground(); > > FileDialog dialog = new FileDialog(shell); > dialog.setFilterExtensions(new String[] { "*.gif" }); > String fileName = dialog.open(); > if (fileName != null) { > loader = new ImageLoader(); > try { > imageDataArray = loader.load(fileName); > if (imageDataArray.length > 1) { > animateThread = new Thread("Animation") { > public void run() { > /* > * Create an off-screen image to draw on, and fill it with the shell background. > */ > Image offScreenImage = new Image(display, loader.logicalScreenWidth, > loader.logicalScreenHeight); > GC offScreenImageGC = new GC(offScreenImage); > offScreenImageGC.setBackground(shellBackground); > offScreenImageGC.fillRectangle(0, 0, loader.logicalScreenWidth, loader.logicalScreenHeight); > > try { > /* Create the first image and draw it on the off-screen image. */ > int imageDataIndex = 0; > ImageData imageData = imageDataArray[imageDataIndex]; > if (image != null && !image.isDisposed()) > image.dispose(); > image = new Image(display, imageData); > offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, imageData.x, > imageData.y, imageData.width, imageData.height); > > /* > * Now loop through the images, creating and drawing each one on the off-screen > * image before drawing it on the shell. > */ > int repeatCount = loader.repeatCount; > while (loader.repeatCount == 0 || repeatCount > 0) { > switch (imageData.disposalMethod) { > case SWT.DM_FILL_BACKGROUND: > /* Fill with the background color before drawing. */ > Color bgColor = null; > if (useGIFBackground && loader.backgroundPixel != -1) { > bgColor = new Color(display, > imageData.palette.getRGB(loader.backgroundPixel)); > } > offScreenImageGC.setBackground(bgColor != null ? bgColor : shellBackground); > offScreenImageGC.fillRectangle(imageData.x, imageData.y, imageData.width, > imageData.height); > if (bgColor != null) > bgColor.dispose(); > break; > case SWT.DM_FILL_PREVIOUS: > /* Restore the previous image before drawing. */ > offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, > imageData.x, imageData.y, imageData.width, imageData.height); > break; > } > > imageDataIndex = (imageDataIndex + 1) % imageDataArray.length; > imageData = imageDataArray[imageDataIndex]; > image.dispose(); > image = new Image(display, imageData); > offScreenImageGC.drawImage(image, 0, 0, imageData.width, imageData.height, > imageData.x, imageData.y, imageData.width, imageData.height); > > /* Draw the off-screen image to the shell. */ > shellGC.drawImage(offScreenImage, 0, 0); > { > ImageLoader loader = new ImageLoader(); > loader.data = new ImageData[] { imageData }; > loader.save(String.format("/tmp/%d.png", imageDataIndex), SWT.IMAGE_PNG); > } > /* > * Sleep for the specified delay time (adding commonly-used slow-down fudge > * factors). > */ > try { > int ms = imageData.delayTime * 10; > if (ms < 20) > ms += 30; > if (ms < 30) > ms += 10; > Thread.sleep(ms); > } catch (InterruptedException e) { > } > > /* > * If we have just drawn the last image, decrement the repeat count and start > * again. > */ > if (imageDataIndex == imageDataArray.length - 1) > repeatCount--; > } > } catch (SWTException ex) { > System.out.println("There was an error animating the GIF"); > } finally { > if (offScreenImage != null && !offScreenImage.isDisposed()) > offScreenImage.dispose(); > if (offScreenImageGC != null && !offScreenImageGC.isDisposed()) > offScreenImageGC.dispose(); > if (image != null && !image.isDisposed()) > image.dispose(); > } > } > }; > animateThread.setDaemon(true); > animateThread.start(); > } > } catch (SWTException ex) { > System.out.println("There was an error loading the GIF"); > } > } > > while (!shell.isDisposed()) { > if (!display.readAndDispatch()) > display.sleep(); > } > display.dispose(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 560298
: 281914 |
281942
|
281943