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文件夾下。
總的意思是:文件夾與頁面並列,圖片在文件夾下。