導航:首頁 > 編程語言 > java輸出圖像

java輸出圖像

發布時間:2023-09-05 11:17:19

1. 如何用java輸出小豬臉圖像

publicclassPig{

publicstaticvoidmain(Stringargs[]){

System.out.println("-------我是小豬-----------");

System.out.println("╭︿︿︿╮");

System.out.println("{/@@/}");

System.out.println("((oo))");

System.out.println("︶︶︶");

System.out.println("天哪,我竟然還做這種東西,真尷尬....");

}

}

下面是運行截圖:

2. 請問下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包 試試看看

3. 用java輸出以下圖形,怎麼做 * ** *** ****

實現思路:就是通過內層循環得到」*「的個數,外層循環控制換行。
for(int i=0;i<4;i++){
for(int j=0;j<=i;j++){
System.out.print("*");
}
System.out.println("");

}
備註:如果不想回換行的話,直接去掉外答層循環即可。

4. 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);
}
});

5. 用java編寫程序輸出如下圖形:

public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = input.next();
int num = Integer.valueOf(str);
for (int i = 1; i <= num; i++) {
for (int j = 1; j <= num - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
System.out.print(i + " ");
}
System.out.println("");
}
}
}

6. 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();
}
}

7. 編寫Java程序,在控制台輸出圖形

偽代碼,供參考:

int k = 6; //定義最大長度
for(int i=1; i<=k; i++) {
for(int j=0; j<i; j++) {System.out.println("*");}
}
for(int i=k-1; i>=1; i--) {
for(int j=0; j<i; j++) {System.out.println("*");}
}

閱讀全文

與java輸出圖像相關的資料

熱點內容
U盤啟動載入資源文件失敗 瀏覽:459
怎樣把ug的pdf文件導入cad 瀏覽:148
c盤文件刪不了怎麼辦 瀏覽:248
win7無線網路禁用 瀏覽:455
如何把電腦文件夾圖片放置在一起 瀏覽:702
如何對訪談法進行數據分析 瀏覽:388
國土三調文件用什麼軟體什麼打開 瀏覽:651
數控銑床編程特點是什麼 瀏覽:119
飛鴿傳輸一次能傳多少文件 瀏覽:488
手機照片許可權怎麼設置密碼 瀏覽:341
es文件瀏覽器怎麼隱藏 瀏覽:649
刪除的文件為什麼恢復 瀏覽:314
血緣詛咒怎麼升級 瀏覽:604
文件分享到微信怎麼操作 瀏覽:393
tmx文件trados 瀏覽:704
大數據與會計選課怎麼選 瀏覽:684
網路的不穩定因素有哪些 瀏覽:950
獵豹瀏覽器javascript 瀏覽:723
哪個列印軟體保存數據時間長 瀏覽:873
ps合並後源文件 瀏覽:74

友情鏈接