當前位置:首頁 » 編程語言 » java圖片

java圖片

發布時間: 2022-01-15 19:02:03

java添加圖片

JAVA是非常靈活的語言,你自己稍動一下手指就能編個控制項的。
class ImageBox extends JLabel ...

⑵ JAVA 圖片

double[] myList=new List()[0];
double max=myList[0];
myList未定義

⑶ 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 畫圖片

如果image是在同一個包下的話,可以直接在路勁上寫你的image的名字。比如包名叫com..chaojunjie 那麼下面有個Test.java,在裡面再加一張圖片test.image,那麼久直接Toolkit.getDeafaultToolkit.getImage('test.image')就可以了。當然這樣寫不是做好的。最好單獨和src同目錄下建個包叫images然後把拓片單獨放裡面。
然後獲得相對路徑Toolkit.getDeafaultToolkit.getImage(this.getClass.getFile('裡面寫你的包名+圖片名'))

⑸ java 載入圖片的幾種方式

第一種方法:

Image bg; //或者是BufferedImage bg;

Pool2(){

try{

String file="圖片的路徑";

bg =ImageIO.read(new File(file));

}catch(Exception e){

e.printStackTrace();

}

}

第二種方法:這種方法用BufferedReader就不行

Image background;

Pool2(){

try{

String file="文件的路徑";

background=Toolkit.getDefaultToolkit().getImage(file);

}catch(Exception e){

e.printStackTrace();

}

}

另外我們有時喜歡把圖片放在工程的src目錄下這樣訪問這些圖片時就要用下面的方法。以src下的image文件下的01.jpg為例

Image image=null;

image = ImageIO.read(getClass().getResourceAsStream("/image/01.jpg"));

⑹ java載入圖片

InputStream in = CommonLoggerFactory.class
.getResourceAsStream("/e/djtu/smartcow/icons/0.jpg");
byte[] kao = new byte[1024*1000];
int size = 0;
int length = 0;
try {
while ((length = in.read(kao, 0, 1024*1000)) != -1) {
size += length;
}
// Close the input stream and return bytes
in.close();

OutputStream output = response.getOutputStream();
output.write(kao, 0, size);
output.close();

} catch (IOException e) {
e.printStackTrace();
}

CommonLoggerFactory日誌生成類

⑺ 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 圖片語句

使用jsp小腳本
<%
for(int i=0;i<num;i++){
%>

<img src="" >//在雙引號中可以寫路徑也可以在for之前把圖片路徑存放在一個數組中,然後在雙引號內寫<%=數組[下標] %>
<%
}
%>
例如你可以這樣寫:
<%
String [] parth=new String[];//定義數組,用來存放圖片路徑,本代碼中的圖片路徑為上一級文件夾的image文件夾中.
for(int i=0;i<parth.length;i++){
%>
<img src="<%=parth[i] %>">
<%} %>
也可把數組內容寫為:String [] parth=new String[];
這樣的話要在使用時這樣寫:<img src="../image/<%=parth[i] %>">

兩中路徑的寫法是一樣的.以後有什麼可以交流的可以給我郵件. 加我好友

⑼ java生成jpg圖片 並且實現文字和圖片混排

response.setHeader("Cache-Control","no-cache");
String str="";
String sum="";
for(int i=0;i<4;i++){
Random random=new Random();
int j=Math.round(random.nextFloat()*35);
char x=str.charAt(j);
sum+=x+"";
}
request.getSession().setAttribute("Code",sum);
BufferedImage bufferedImage=new BufferedImage(50,20,BufferedImage.TYPE_3BYTE_BGR);
Graphics2D graphics2D=(Graphics2D)bufferedImage.getGraphics();
graphics2D.setColor(Color.blue);
graphics2D.fill3DRect(0,0,50,20,false);
graphics2D.setColor(Color.YELLOW);
graphics2D.drawString(sum,10,12);
response.setContentType("image/jpeg");
ServletOutputStream output;
try {
output = response.getOutputStream();
JPEGImageEncoder encoder= JPEGCodec.createJPEGEncoder(output);
encoder.encode(bufferedImage);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

⑽ 用java怎麼讀取圖片

思路:使用 java.awt.Image包下的Image可以接收圖片。讀取則使用ImageIO對象。

代碼如下:

/**
* 讀取圖片,首先導入以下的包
*/
import java.awt.Image;
import javax.imageio.ImageIO;
import java.io.*;

/**
* 用Image對象來接收圖片
* 路徑根據實際情況修改
*/
Image image = ImageIO.read(new File("c:\\1.png"));
System.out.println(image.getSource());

熱點內容
大話西遊2華山論劍什麼時候開的伺服器 發布:2024-09-21 08:00:15 瀏覽:530
編程馬鞍數 發布:2024-09-21 07:48:32 瀏覽:725
新建文件夾dos命令 發布:2024-09-21 07:44:13 瀏覽:131
舞蹈解壓介紹 發布:2024-09-21 07:40:04 瀏覽:972
qq如何顯示密碼 發布:2024-09-21 07:22:26 瀏覽:565
安卓導航如何調大mlc音量 發布:2024-09-21 06:59:21 瀏覽:34
洛奇解壓中發生錯誤 發布:2024-09-21 06:53:30 瀏覽:293
解壓球是什麼 發布:2024-09-21 06:53:29 瀏覽:539
linux重啟nginx 發布:2024-09-21 06:45:27 瀏覽:786
編譯環境英語 發布:2024-09-21 06:19:59 瀏覽:865