资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java的图片复制的代码 java的图片复制的代码是什么

java 代码实现复制粘粘功能,详细细节如图,我自己写了一段代码,搞了半天没搞好。

如果是JTable.等java图形界面的组件,那么获取数据,赋值都比较简单.

成都创新互联凭借专业的设计团队扎实的技术支持、优质高效的服务意识和丰厚的资源优势,提供专业的网站策划、做网站、成都网站建设、网站优化、软件开发、网站改版等服务,在成都10多年的网站建设设计经验,为成都成百上千中小型企业策划设计了网站。

但是看图片,是要写一个Excel的辅助功能, 这对java来说还是有点麻烦了.

最优建议:

Excel的功能. 那么最佳的建议,是使用vba 语言进行扩展.(微软出品,简单,方便,代码量极少) .

其次的建议:

C/C++ 键盘钩子 , 当读取到按键F9时 ,模拟键盘的复制粘贴等操作.

不推荐java , 但java也能勉强凑合解决这个问题:

因为java 很难获取系统底层的按键, Robot也很有局限, 比如窗口失去焦点的时候,读取不到F9按键.   所以java需要调用JNI c语言 比较繁琐. 比较简单的是调用JNA了,但代码量也不少.

当然了如果非要用java写,也可以,我手写了一个简单的JNA+Robot配合

效果图

java怎样复制图片

图片本质上还是文件,所以就像复制文件一样就可以了。下面是一个演示程序:

public class CopyImage

{

public static void main(String[] args) throws Exception

{

FileInputStream fi=new FileInputStream("image.jpg");

BufferedInputStream in=new BufferedInputStream(fi);

FileOutputStream fo=new FileOutputStream("cimage.jpg");

BufferedOutputStream out=new BufferedOutputStream(fo);

byte[] buf=new byte[4096];

int len=in.read(buf);

while(len!=-1)

{

out.write(buf, 0, len);

len=in.read(buf);

}

out.close();

fo.close();

in.close();

fi.close();

}

}

运行程序是改一改图片的路径,另外在实际代码中最后不要想上面的代码直接抛出这样的异常。

用Java编写一个程序,将一个图像文件复制到指定的文件夹中

这是我们公司基类里的一个方法希望对你有帮助。。/**

* 复制单个文件

* @param oldPath String 原文件路径 如:c:/fqf.txt

* @param newPath String 复制后路径 如:f:/fqf.txt

* @return boolean

*/

public void copyFile(String oldPath, String newPath) {

try {

int bytesum = 0;

int byteread = 0;

File oldfile = new File(oldPath);

if (oldfile.exists()) { //文件存在时

InputStream inStream = new FileInputStream(oldPath); //读入原文件

FileOutputStream fs = new FileOutputStream(newPath);

byte[] buffer = new byte[1444];

int length;

while ( (byteread = inStream.read(buffer)) != -1) {

bytesum += byteread; //字节数 文件大小

// System.out.println(bytesum);

fs.write(buffer, 0, byteread);

}

inStream.close();

}

}

catch (Exception e) {

System.out.println("复制单个文件操作出错");

e.printStackTrace(); } }

java如何复制文件(包括图片等其他格式的文件)

import java.io.*;

public class Main {

public static void main(String[] args) throws Exception {

copy("D:\\test.jpg", "D:\\ttt.jpg");

}

public static void copy(String src, String dest) throws IOException {

byte[] buffer = new byte[1024];

FileInputStream in = null;

FileOutputStream out = null;

try {

in = new FileInputStream(src);

out = new FileOutputStream(dest);

int c;

while((c = in.read(buffer)) = 0) {

out.write(buffer, 0, c);

}

} finally {

if (in != null) {

try {

in.close();

} catch (Exception err) {

// Ignore the exception.

}

}

if (out != null) {

try {

out.close();

} catch (Exception err) {

//Ignore the exception.

}

}

}

}

}

java 编程,复制图片到另一文件夹下,如何提高效率

直接用文件流打开一个文件,在通过楼下说的缓冲流将文件直接写到另外一个文件就可以了

//处理JPEG的

public static String getFixedBoundIcon(String filePath) throws Exception {

//返回地址

String result = "";

//输出流

FileOutputStream out = null;

try {

File f = new File(filePath);

if (!f.isFile()) {

throw new Exception(f + " 不是图片文件!");

}

//图象文件

if (f != null f.exists()) {

//这里的ImageIO属于java工厂类,在工厂类class里面,调用的System.gc(),频繁调用会造成dump,需要考虑优化

BufferedImage image = ImageIO.read(f); // 读入文件

if (image != null) {

BufferedImage tag =

new BufferedImage(116, 165, BufferedImage.TYPE_INT_RGB);

//绘制缩小后的图

tag.getGraphics().drawImage(image, 0, 0, 116, 165, null);

//文件地址部分

int lastLength = filePath.lastIndexOf(".");

String subFilePath = filePath.substring(0, lastLength);

String fileType = filePath.substring(lastLength);

//背景

result = subFilePath + "_116_165" + fileType;

out = new FileOutputStream(result);

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

JPEGEncodeParam param =

encoder.getDefaultJPEGEncodeParam(tag);

param.setQuality(0.95f, true); //95%图像

//像素尺寸单位.像素/英寸

param.setDensityUnit(1);

//水平分辨率

param.setXDensity(300);

//垂直分辨率

param.setYDensity(300);

encoder.setJPEGEncodeParam(param);

encoder.encode(tag);

tag = null;

}

}

f = null;

} catch (Exception ex) {

ex.printStackTrace();

} finally {

out.close();

out = null;

}

return result;

}

还要try起来捕获异常哟


本文题目:java的图片复制的代码 java的图片复制的代码是什么
当前路径:http://cdkjz.cn/article/hggdhi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220