真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java保存畫布圖片代碼,java怎么導(dǎo)入圖片的代碼

java 保存圖片

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

我們提供的服務(wù)有:成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、三沙ssl等。為1000+企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的三沙網(wǎng)站制作公司

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

傳入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();

}

}

}

java swing 畫圖怎么保存?求詳細(xì)代碼

package test;

import javax.swing.*;

import javax.imageio.ImageIO;

import java.awt.*;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

public class TestJLabel2Image {

public static void main(String ds[]) {

final JFrame f = new JFrame();

JPanel panel = new JPanel(new BorderLayout());

JLabel label = new JLabel() {

public void paintComponent(Graphics g) {

g.setColor(Color.red);

g.fillOval(0, 0, this.getWidth(), this.getHeight());

g.dispose();

}

};

panel.setPreferredSize(new Dimension(555, 555));

panel.add(label, BorderLayout.CENTER);

f.getContentPane().add(panel);

f.pack();

BufferedImage image = createImage(panel);

f.dispose();

try {

ImageIO.write(image, "png", new File("d:/test.png"));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static BufferedImage createImage(JPanel panel) {

int totalWidth = panel.getPreferredSize().width;

int totalHeight = panel.getPreferredSize().height;

BufferedImage panelImage = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB);

Graphics2D g2D = (Graphics2D) panelImage.createGraphics();

g2D.setColor(Color.WHITE);

g2D.fillRect(0, 0, totalWidth, totalHeight);

g2D.translate(0, 0);

panel.paint(g2D);

g2D.dispose();

return panelImage;

}

}

java中畫圖其數(shù)據(jù)怎么讀出和保存比如畫幾個圓要代碼啊

下面是我寫的一個小東西,繪制了若干圖形:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import java.awt.geom.*;

import java.util.ArrayList;

import javax.swing.border.*;

public class DrawingLeftPanel extends JFrame{

private int DX=100;

private int DY=200;

Point point;

DrawingLeftPanel(){

setBackground(Color.GRAY);

setSize(300,700);

setLayout(new GridLayout(1,1));

JPanel panel=new JPanel0();

JScrollPane scrollpane=new JScrollPane(panel);

scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

this.getContentPane().add(scrollpane);

setVisible(true);

}

public static void main(String args[]){

new DrawingLeftPanel();

}

class JPanel0 extends JPanel {

public void paintComponent(Graphics g)

{ int w=getSize().width;

int h=getSize().height;

Shape shape1,shape2,shape3,shape4,shape5,shape6,shape7,shape8,shape9;

int[] xpoints=new int[4];

int[] ypoints=new int[4];

xpoints[0]=DX;

ypoints[0]=DY;

xpoints[1]=DX-50;

ypoints[1]=DY+25;

xpoints[2]=DX;

ypoints[2]=DY+50;

xpoints[3]=DX+50;

ypoints[3]=DY+25;

//畫圖父類的構(gòu)造函數(shù)

//System.out.println("adfafd");

super.paintComponent(g);

Graphics2D g2=(Graphics2D)g;

//g2.setColor(Color.BLACK);

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,

RenderingHints.VALUE_ANTIALIAS_ON);

g2.setStroke(new BasicStroke(1.0f));

g2.setColor(Color.LIGHT_GRAY);

Shape e=new Ellipse2D.Double(75,50,50,50);

g2.fill(e);

g2.setColor(Color.BLACK);

g2.draw(e);//畫出圓形 概念

e=new Rectangle2D.Double(50,125,100,50);

g2.setColor(Color.LIGHT_GRAY);

g2.fill(e);

g2.setColor(Color.BLACK);

g2.draw(e);//畫出矩形 原理規(guī)則

e=new Polygon(xpoints,ypoints,4);

g2.setColor(Color.LIGHT_GRAY);

g2.fill(e);

g2.setColor(Color.BLACK);

g2.draw(e);//畫出四邊形 態(tài)度價值觀念

shape1=new Ellipse2D.Double(150,275,50,50);

shape2=new Rectangle2D.Double(75,275,100,50);

shape3=new Ellipse2D.Double(50, 275, 50, 50);

Area area1=new Area(shape1);

Area area2=new Area(shape2);

Area area3=new Area(shape3);

area2.subtract(area1);

area3.add(area2);

g2.setColor(Color.LIGHT_GRAY);

g2.fill(area3);

g2.setColor(Color.BLACK);

g2.draw(area3);//畫出事實范例

shape4=new Ellipse2D.Double(150,350,50,50);

shape5=new Rectangle2D.Double(75,350,100,50);

shape6=new Ellipse2D.Double(50, 350, 50, 50);

Area area4=new Area(shape4);

Area area5=new Area(shape5);

Area area6=new Area(shape6);

area5.add(area4);

area5.add(area6);

g2.setColor(Color.LIGHT_GRAY);

g2.fill(area5);

g2.setColor(Color.BLACK);

g2.draw(area5);//畫出過程

shape7=new Ellipse2D.Double(150,425,50,50);

shape8=new Rectangle2D.Double(75,425,100,50);

shape9=new Ellipse2D.Double(50, 425, 50, 50);

Area area7=new Area(shape7);

Area area8=new Area(shape8);

Area area9=new Area(shape9);

area8.subtract(area7);

area8.add(area9);

g2.setColor(Color.LIGHT_GRAY);

g2.fill(area8);

area8.add(area7);

g2.setColor(Color.BLACK);

g2.draw(area7);

g2.draw(area8);//畫出事實范例

shape7=new Line2D.Float(75,525,175,525);

g2.draw(shape7);

GeneralPath p = new GeneralPath(GeneralPath.WIND_EVEN_ODD);

p.moveTo(75, 600);

// adds a cubic curve to the path

p.curveTo(100, 650, 150, 550,200,600);

// p.moveTo(w*.2f, h*.6f);

// adds a quad curve to the path

// p.quadTo(w*.5f, h*1.0f, w*.8f, h*.6f);

g2.setColor(Color.lightGray);

g2.fill(p);

g2.setColor(Color.black);

g2.draw(p);

}

}

}

用JAVA怎么 將繪圖保存成圖片?

用ImageIO類提供的靜態(tài)方法write(img,foamt,outStream);

先指定文件:

File f=new File("路徑");

文件不存在就創(chuàng)建

if(!f.exists()){

f.createNewFile();

}

打開文件流

FileOutputStream fos=new FileOutputStream(f);

然后寫入圖片數(shù)據(jù)類型是BufferedImage

ImageIO.write(img,"png",fos);

java寫的畫圖板保存圖片是怎么實現(xiàn)的

首先是得到圖片的保存路徑,

然后截取圖片的路徑。。

然后再用文件的輸入輸出流。。

把文件讀入數(shù)級組中。。

再它其寫到指定的文件夾中。。

這樣就實現(xiàn)了文件的保存……

祝你早日成功!


文章題目:java保存畫布圖片代碼,java怎么導(dǎo)入圖片的代碼
鏈接URL:http://weahome.cn/article/dsgggod.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部