本文整理汇总了Java中java.awt.image.BufferedImage类的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage类的具体用法?Java BufferedImage怎么用?Java BufferedImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BufferedImage类属于java.awt.image包,在下文中一共展示了BufferedImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUnitImage
import java.awt.image.BufferedImage; //导入依赖的package包/类
public static BufferedImage getUnitImage(UnitType unitType, String roleId,
boolean nativeEthnicity,
Dimension size) {
// units that can only be native don't need the .native key part
if (unitType.hasAbility(Ability.BORN_IN_INDIAN_SETTLEMENT)) {
nativeEthnicity = false;
}
// try to get an image matching the key
String roleQual = (Role.isDefaultRoleId(roleId)) ? ""
: "." + Role.getRoleSuffix(roleId);
String key = "image.unit." + unitType.getId() + roleQual
+ ((nativeEthnicity) ? ".native" : "");
if (!ResourceManager.hasImageResource(key) && nativeEthnicity) {
key = "image.unit." + unitType.getId() + roleQual;
}
BufferedImage image = ResourceManager.getImage(key, size);
return image;
}
示例2: getAntialiasedColors
import java.awt.image.BufferedImage; //导入依赖的package包/类
private static HashSet getAntialiasedColors(Object aaHint, int lcdContrast) {
JLabel label = new JLabel("ABCD");
label.setSize(label.getPreferredSize());
label.putClientProperty(KEY_TEXT_ANTIALIASING, aaHint);
label.putClientProperty(KEY_TEXT_LCD_CONTRAST, lcdContrast);
int w = label.getWidth();
int h = label.getHeight();
BufferedImage buffImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImage.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, w, h);
label.paint(g);
g.dispose();
HashSet<Color> colors = new HashSet<>();
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
Color color = new Color(buffImage.getRGB(i, j));
colors.add(color);
}
}
return colors;
}
示例3: checkBI
import java.awt.image.BufferedImage; //导入依赖的package包/类
private static void checkBI(BufferedImage bi, int accepted[]) {
for (int x = 0; x < bi.getWidth(); x++) {
for (int y = 0; y < bi.getHeight(); y++) {
int pix = bi.getRGB(x, y);
boolean found = false;
for (int acc : accepted) {
if (pix == acc) {
found = true;
break;
}
}
if (!found) {
try {
String name = "OnScreenRenderingResizeTest.png";
ImageIO.write(bi, "png", new File(name));
System.out.println("Screen shot file: " + name);
} catch (IOException ex) {}
throw new
RuntimeException("Test failed at " + x + "-" + y +
" rgb=0x" + Integer.toHexString(pix));
}
}
}
}
示例4: createDataBP
import java.awt.image.BufferedImage; //导入依赖的package包/类
public static SurfaceData createDataBP(BufferedImage bImg,
SurfaceType sType) {
BytePackedRaster bpRaster =
(BytePackedRaster)bImg.getRaster();
BufImgSurfaceData bisd =
new BufImgSurfaceData(bpRaster.getDataBuffer(), bImg, sType);
ColorModel cm = bImg.getColorModel();
IndexColorModel icm = ((cm instanceof IndexColorModel)
? (IndexColorModel) cm
: null);
bisd.initRaster(bpRaster.getDataStorage(),
bpRaster.getDataBitOffset() / 8,
bpRaster.getDataBitOffset() & 7,
bpRaster.getWidth(),
bpRaster.getHeight(),
0,
bpRaster.getScanlineStride(),
icm);
return bisd;
}
示例5: loadImage
import java.awt.image.BufferedImage; //导入依赖的package包/类
public static final Image loadImage(final String aFileName)
{
Debug.log(aFileName);
String name = aFileName.substring(aFileName.lastIndexOf('/') + 1);
String path = sanitizeFilePath(aFileName);
//.if DESKTOP
BufferedImage data = null;
try{data=ImageIO.read(Resources.class.getResource(path));}
catch (IOException ex) {Logger.getLogger(Resources.class.getName()).log(Level.SEVERE, null, ex);}
//.elseif ANDROID
//|android.graphics.Bitmap data = null;
//|Debug.log("Resources.loadImage*********************************");
//|Debug.log(path);
//|InputStream dataStream = Mobile.loadAsset(path);
//|data = BitmapFactory.decodeStream(dataStream);
//|Debug.log(data.getByteCount());
//.endif
return new Image(name,data);
}
示例6: GIFFrame
import java.awt.image.BufferedImage; //导入依赖的package包/类
public GIFFrame(BufferedImage frame, int leftPosition, int topPosition, int delay, int disposalMethod, int userInputFlag, int transparencyFlag, int transparentColor) {
if(frame == null) throw new IllegalArgumentException("Null input image");
if(disposalMethod < DISPOSAL_UNSPECIFIED || disposalMethod > DISPOSAL_TO_BE_DEFINED)
throw new IllegalArgumentException("Invalid disposal method: " + disposalMethod);
if(userInputFlag < USER_INPUT_NONE || userInputFlag > USER_INPUT_EXPECTED)
throw new IllegalArgumentException("Invalid user input flag: " + userInputFlag);
if(transparencyFlag < TRANSPARENCY_INDEX_NONE || transparencyFlag > TRANSPARENCY_INDEX_SET)
throw new IllegalArgumentException("Invalid transparency flag: " + transparencyFlag);
if(leftPosition < 0 || topPosition < 0)
throw new IllegalArgumentException("Negative coordinates for frame top-left position");
if(delay < 0) delay = 0;
this.frame = frame;
this.leftPosition = leftPosition;
this.topPosition = topPosition;
this.delay = delay;
this.disposalMethod = disposalMethod;
this.userInputFlag = userInputFlag;
this.transparencyFlag = transparencyFlag;
this.frameWidth = frame.getWidth();
this.frameHeight = frame.getHeight();
this.transparentColor = transparentColor;
}
示例7: saveCompress
import java.awt.image.BufferedImage; //导入依赖的package包/类
/**
* @param is
* @param deistPath
* @param newWidth
* @param newHeight
* @return int
* @Title: saveCompress
* @Description: 压缩图片,统一压缩成JPG格式,返回压缩后的大小(字节)
*/
public static int saveCompress(InputStream is, String deistPath,
int newWidth, int newHeight) {
try {
BufferedImage srcImage = ImageIO.read(is);
BufferedImage destImage = resize(srcImage, newWidth, newHeight);
File deistFile = new File(deistPath);
String fileName = deistFile.getName();
String formatName = fileName
.substring(fileName.lastIndexOf('.') + 1);
ImageIO.write(destImage, formatName, deistFile);
return (int) deistFile.length();
} catch (Exception e) {
return -1;
}
}
示例8: testDisabledStateOfJMenu
import java.awt.image.BufferedImage; //导入依赖的package包/类
private void testDisabledStateOfJMenu() {
// Test disabled JMenu state
Rectangle rect = disabledMenu.getBounds();
BufferedImage image = new BufferedImage(rect.width, rect.height,
BufferedImage.TYPE_INT_ARGB);
disabledMenu.paint(image.getGraphics());
int y = image.getHeight() / 2;
for (int x = 0; x < image.getWidth(); x++) {
Color c = new Color(image.getRGB(x, y));
if (c.equals(Color.BLUE)) {
dispose();
throw new RuntimeException("JMenu Disabled"
+ " State not Valid.");
}
}
}
示例9: testDrawWithNullInfo
import java.awt.image.BufferedImage; //导入依赖的package包/类
/**
* Draws the chart with a null info object to make sure that no exceptions are thrown (a
* problem that was occurring at one point).
*/
public void testDrawWithNullInfo() {
boolean success = false;
try {
BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
g2.dispose();
success = true;
}
catch (Exception e) {
success = false;
}
assertTrue(success);
}
示例10: compressAndSave
import java.awt.image.BufferedImage; //导入依赖的package包/类
/**
*
* @param bi
* @param nw
* @param nh
* @param tarFile
* @return boolean
* @Title: compressAndSave
* @Description: 压缩处理
*/
public static boolean compressAndSave(BufferedImage bi, int nw, int nh,
File tarFile) {
try {
BufferedImage destImage = resize(bi, nw, nh);
// 输出文件
String fileName = tarFile.getName();
String formatName = fileName
.substring(fileName.lastIndexOf('.') + 1);
ImageIO.write(destImage, formatName, tarFile);
return true;
} catch (Exception e) {
log.error(ExceptionMessage.IO_EXCEPTION.getExceptionMsg());
return false;
}
}
示例11: Transform
import java.awt.image.BufferedImage; //导入依赖的package包/类
@Override
public synchronized void Transform(SurfaceData src, SurfaceData dst,
Composite comp, Region clip,
AffineTransform at, int hint, int srcx,
int srcy, int dstx, int dsty, int width,
int height){
Blit convertsrc = Blit.getFromCache(src.getSurfaceType(),
CompositeType.SrcNoEa,
SurfaceType.IntArgbPre);
// use cached intermediate surface, if available
final SurfaceData cachedSrc = srcTmp != null ? srcTmp.get() : null;
// convert source to IntArgbPre
src = convertFrom(convertsrc, src, srcx, srcy, width, height, cachedSrc,
BufferedImage.TYPE_INT_ARGB_PRE);
// transform IntArgbPre intermediate surface to D3D surface
performop.Transform(src, dst, comp, clip, at, hint, 0, 0, dstx, dsty,
width, height);
if (src != cachedSrc) {
// cache the intermediate surface
srcTmp = new WeakReference<>(src);
}
}
示例12: saveImage
import java.awt.image.BufferedImage; //导入依赖的package包/类
private static long saveImage(final BufferedImage image,
final ImageWriter writer,
final ImageWriteParam writerParams,
final String mode,
final String suffix) throws IOException
{
final File imgFile = new File("WriterCompressionTest-"
+ mode + '.' + suffix);
System.out.println("Writing file: " + imgFile.getAbsolutePath());
final ImageOutputStream imgOutStream
= ImageIO.createImageOutputStream(new FileOutputStream(imgFile));
try {
writer.setOutput(imgOutStream);
writer.write(null, new IIOImage(image, null, null), writerParams);
} finally {
imgOutStream.close();
}
return imgFile.length();
}
示例13: processFontData
import java.awt.image.BufferedImage; //导入依赖的package包/类
/**
* Processes a font sprite sheet and character data into a usable HashMap of
* character sprites.
*
* @param spriteSheet
* The sprite sheet.
*
* @param characterData
* The character data.
*
* @return
* The HashMap of character sprites.
*
* @throws NullPointerException
* If the sprite sheet or character data is null.
*/
private static HashMap<Character, BufferedImage> processFontData(final @NonNull BufferedImage spriteSheet, final @NonNull List<String> characterData) {
final HashMap<Character, BufferedImage> hashMap = new HashMap<>(characterData.size());
for (final String string : characterData) {
if (string.isEmpty() == false) {
final Scanner scanner = new Scanner(string);
final char character = (char) scanner.nextInt();
final int x = scanner.nextInt();
final int y = scanner.nextInt();
final int width = scanner.nextInt();
final int height = scanner.nextInt();
final BufferedImage image = spriteSheet.getSubimage(x, y, width, height);
hashMap.put(character, image);
}
}
return hashMap;
}
示例14: processThumbnailUpdate
import java.awt.image.BufferedImage; //导入依赖的package包/类
public void processThumbnailUpdate(BufferedImage theThumbnail,
int minX,
int minY,
int width,
int height,
int periodX,
int periodY,
int[] bands) {
super.processThumbnailUpdate(theThumbnail,
minX,
minY,
width,
height,
periodX,
periodY,
bands);
}
示例15: main
import java.awt.image.BufferedImage; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
if (args.length > 0) {
format = args[0];
}
writer = ImageIO.getImageWritersByFormatName(format).next();
file_suffix =writer.getOriginatingProvider().getFileSuffixes()[0];
BufferedImage src = createTestImage();
EncodeSubImageTest m1 = new EncodeSubImageTest(src);
m1.doTest("test_src");
BufferedImage sub = src.getSubimage(subImageOffset, subImageOffset,
src.getWidth() - 2 * subImageOffset,
src.getHeight() - 2 * subImageOffset);
EncodeSubImageTest m2 = new EncodeSubImageTest(sub);
m2.doTest("test_sub");
}