1. java 保存图片

ImageIO.write(BufferedImage, "JPG", File);

================================

传入Component保存图像的方法,你试试看还有没有变色。

public void cutScreen(Component com) {
Rectangle rect = com.getBounds();
BufferedImage bi = (BufferedImage) com.createImage(rect.width,
rect.height);
Graphics g = bi.getGraphics();
com.paint(g);
g.dispose();
JFileChooser jfc = new JFileChooser();
jfc.setFileFilter(new FileFilter() {
public boolean accept(File f) {
return f.isDirectory()
|| f.getName().toLowerCase().endsWith(".jpg");
}
public String getDescription() {
return "*.jpg";
}
});
int type = jfc.showSaveDialog(null);
if (type == 0) {
File file = jfc.getSelectedFile();
name = file.getName().toLowerCase();
if (!name.endsWith("jpg")) {
String path = file.getAbsolutePath();
file = new File(path + ".jpg");
for (int i = 0; file.exists(); i++) {
file = new File(path + "(" + i + ").jpg");
}
}
try {
if (!file.exists()) {
file.createNewFile();
}
ImageIO.write(bi, "JPG", file);
} catch (IOException e1) {
e1.printStackTrace();
}
}

}

2. java怎么在控制台输出一张jpg的图片

输出图片的base64编码

//imgFile是图片的路版径
publicstaticvoidgetImageStr(StringimgFile){
InputStreaminputStream=null;
byte[]data=null;
try{
inputStream=newFileInputStream(imgFile);
data=newbyte[inputStream.available()];
inputStream.read(data);
inputStream.close();
}catch(IOExceptione){
e.printStackTrace();
}//加密权
BASE64Encoderencoder=newBASE64Encoder();
System.out.println(encoder.encode(data));
}

3. java图片输出

等着拿分.......
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
* @author alanwei
*
*/
public class Test {

public static BufferedImage createImage(int width, int height, String s) {
Font font = new Font("Serif", Font.BOLD, 10);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D)bi.getGraphics();
g2.setBackground(Color.WHITE);
g2.clearRect(0, 0, width, height);
g2.setPaint(Color.RED);

g2.drawString(s, 0, 5 + height / 2);

return bi;
}

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedImage image = createImage(100, 20, "123456789");

File file = new File("image.jpg");
if (!file.exists()) {
file.createNewFile();
}

if (image != null) {
ImageIO.write(image, "jpg", file);
}
}
}

4. java如何输出jpeg图片

不可能直接输出。。你要专门用一个servlet把这个装图片的byte[] out.print()然后再去<img>标签里引用这个地址

5. java如何导出多个图片到excel

给你个方法,你新建一个EXECL在不同的sheet中随便写点什么东西,然后另存为*.html文件,用浏览器打开,查看源文件,照着上面改一下,就可以了。

6. JAVA图片输出

等着拿分.......
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
* @ alanwei
*
*/
public class Test {

public static BufferedImage createImage(int width, int height, String s) {
Font font = new Font("Serif", Font.BOLD, 10);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D)bi.getGraphics();
g2.setBackground(Color.WHITE);
g2.clearRect(0, 0, width, height);
g2.setPaint(Color.RED);

g2.drawString(s, 0, 5 + height / 2);

return bi;
}

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedImage image = createImage(100, 20, "123456789");

File file = new File("image.jpg");
if (!file.exists()) {
file.createNewFile();
}

if (image != null) {
ImageIO.write(image, "jpg", file);
}
}
}

7. 请问下java中导出图片怎么做

package com.xolt;
import java.io.FileOutputStream;
import java.io.File;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.awt.image.BufferedImage;
import javax.imageio.*;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;;

public class TestPOI {

public static void main(String[] args) {
FileOutputStream fileOut = null;
BufferedImage bufferImg =null;
BufferedImage bufferImg1 = null;
try{

//先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
ByteArrayOutputStream byteArrayOut1 = new ByteArrayOutputStream();
bufferImg = ImageIO.read(new File("C:/Documents and Settings/dingqi/Desktop/clip_image002.jpg"));
bufferImg1 = ImageIO.read(new File("C:/Documents and Settings/dingqi/Desktop/clip_image002.jpg"));
ImageIO.write(bufferImg,"jpg",byteArrayOut);
ImageIO.write(bufferImg1,"jpg",byteArrayOut1);

//创建一个工作薄
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("poi picT");
//HSSFRow row = sheet1.createRow(2);
HSSFPatriarch patriarch = sheet1.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0,0,512,255,(short) 1,1,(short)10,20);
HSSFClientAnchor anchor1 = new HSSFClientAnchor(0,0,512,255,(short) 2,30,(short)10,60);
anchor1.setAnchorType(2);
//插入图片
patriarch.createPicture(anchor , wb.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
patriarch.createPicture(anchor1 , wb.addPicture(byteArrayOut1.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));

fileOut = new FileOutputStream("c:/workbook.xls");
//写入excel文件
wb.write(fileOut);
fileOut.close();

}catch(IOException io){
io.printStackTrace();
System.out.println("io erorr : "+ io.getMessage());
} finally
{
if (fileOut != null)
{

try {
fileOut.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}

poi中图片到到excel的方法 你需要准备poi包 试试看看

8. java中输出图片的代码

final ImageView iv=(ImageView)findViewById(R.id.iv);
回 Button bt=(Button)findViewById(R.id.bt);
bt.setOnClickListener(new View.OnClickListener(){

@答Override
public void onClick(View p1)
{
// TODO: Implement this method
if(iv.getDrawable()!=null)
iv.setImageResource(R.id.photo);
else iv.setImageResource(0);
}
});

9. java导出图片到XLS中,图片无法显示

if(imgTpye.endsWith(".JPG")) 图片都是小写的jpg 是不是调用.equalsIgnoreCase(".jpg")

10. JAVA 输出图片代码

假如只在当前页面显示的话直接用 img src
在HTML(或者jsp)的body 里添加
<img src="test/1.jpg" />,
以上述例子说明,你现在所编辑的页面是index.jsp,那么test(文件夹)是跟此页面在同一目录中的,1.jpg是需要显示的图片,位置在test文件夹下。
总的意思是:文件夹与页面并列,图片在文件夹下。