Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d625315610ceaa32fb3c3f7359787485848eb376 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 *  Copyright (c) 2012 Mia-Software.
 *  
 *  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:
 *  	Gregoire Dupe (Mia-Software) - Bug 361794 - [Restructuring] New customization meta-model
 *  	Nicolas Bros (Mia-Software) - Bug 374941 - To be able to customize overlay icons on EClass
 */
package org.eclipse.emf.facet.custom.ui.internal.custompt;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import org.eclipse.emf.facet.custom.metamodel.custompt.IImage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;

public class ImageWrapper implements IImage {

	private static final long serialVersionUID = -2538802017710069448L;
	private final Image wrappedImage;

	public ImageWrapper(final Image image) {
		this.wrappedImage = image;
	}

	public InputStream getInputStream() {
		// note: this is an inefficient way to get an inputStream from the wrapped Image
		final ByteArrayOutputStream stream = new ByteArrayOutputStream();
		final ImageLoader loader = new ImageLoader();
		loader.data = new ImageData[] { this.wrappedImage.getImageData() };
		loader.save(stream, SWT.IMAGE_PNG);
		final byte[] byteArray = stream.toByteArray();
		return new ByteArrayInputStream(byteArray);
	}

	public Image getImage() {
		return this.wrappedImage;
	}

}

Back to the top