java圖片輸出
㈠ java如何輸出jpeg圖片
不可能直接輸出。。你要專門用一個servlet把這個裝圖片的byte[] out.print()然後再去<img>標簽里引用這個地址
㈡ 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);
FontRenderContext context = g2.getFontRenderContext();
Rectangle2D bounds = font.getStringBounds(s, context);
double x = (width - bounds.getWidth()) / 2;
double y = (height - bounds.getHeight()) / 2;
double ascent = -bounds.getY();
double baseY = y + ascent;
g2.drawString(s, (int)x, (int)baseY);
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);
}
}
}
㈢ 請問下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包 試試看看
㈣ JAVA 輸出圖片代碼
假如只在當前頁面顯示的話直接用 img src
在HTML(或者jsp)的body 里添加
<img src="test/1.jpg" />,
以上述例子說明,你現在所編輯的頁面是index.jsp,那麼test(文件夾)是跟此頁面在同一目錄中的,1.jpg是需要顯示的圖片,位置在test文件夾下。
總的意思是:文件夾與頁面並列,圖片在文件夾下。
㈤ 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);
}
}
}
㈥ java輸入輸出流處理圖片怎麼提取相片
這個簡單 你可以先讀 讀完之後在寫出來么
public class BinaryOperation {
public static void main(String args[]){
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("d:/圖片/chenhl.jpg");
byte[] b = new byte[128];
fos = new FileOutputStream("d:/圖片/chenhl 復件.jpg");
while(fis.read(b)!=-1){
fos.write(b);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try{
if(fis!=null) fis.close();
if(fos!=null) fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
㈦ 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);
}
});
㈧ 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));
}
㈨ java輸出圖形
import java.util.Scanner;//導入輸入功能
//Scanner
public class PrintMyNameAndShape//類名
{
public static void main(String[]args
{
Scanner s=new Scanner;//使用輸入函數
System.out.println("-------------------------------");
System.out.println("姓名:xxx");
System.out.println("小組:第n小組");
System.out.println("-------------------------------");
System.out.println("尊敬的用戶,請輸入你需要的行數,謝謝");
int n=s.nextInt();
for(int i=1;i<=n;i++)
{
System.out.print("*");
}
for(int i=1;i<=n;i--)
{
System.out.print("*");
}
}
}
㈩ java輸出圖形
public static void main(String[] args) {
版int n=10; //可以通過調整n值,調整輸出菱形的大小。n=行數權+1
for(int i=1;i<n;i++){
for(int j=1;j<=(i<n/2?n/2-i:i-n/2);j++){
System.out.print(" ");
}
for(int j=1;j<(i<n/2?2*i:2*(n-i));j++){
System.out.print("*");
}
for(int j=1;j<=(i<n/2?n/2-i:i-n/2);j++){
System.out.print(" ");
}
System.out.println();
}
}