JAVA Graphics2D 制图 透明色

时间:2022-04-15 11:05:01
package com.dcc.dao;

import java.awt.Graphics2D;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.annotation.Resource;
import javax.imageio.ImageIO;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.pool.DruidDataSource;

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations="classpath:applicationContext.xml")
public class DaoTest_App {
	@Resource
	private ObtDao obtDao;
	
	
	
	public void test(){
		System.out.println(this.toString()+"测试读取Oracle数据库,共查询数据:"+obtDao.selectObtBaseInfo().size());

	}
	
	
	
	public void testJDBC(){
		DruidDataSource source = new com.alibaba.druid.pool.DruidDataSource();
		StatFilter sta = new com.alibaba.druid.filter.stat.StatFilter();
		//source.
	}
	
	@Test
	public void createMyMap(){
		int imageWidth=1000,imageHeight=800;
		BufferedImage image = new BufferedImage(imageWidth,imageHeight,BufferedImage.TYPE_INT_RGB);
		Graphics2D g2d = image.createGraphics();
		image = g2d.getDeviceConfiguration().createCompatibleImage(imageWidth, imageHeight, Transparency.TRANSLUCENT);
		String url = "F:"+File.separator+"test.png";
		File file = new File(url);
		if(!file.exists()){
			file.mkdirs();
		}
		try {
			ImageIO.write(image, "png", file);
			System.out.println(url);
			g2d.dispose();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}