「java代码照片」java编程代码图片

博主:adminadmin 2023-01-23 23:45:12 339

本篇文章给大家谈谈java代码照片,以及java编程代码图片对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

怎么为Java程序添加背景图片代码?

仅仅是给窗口添加背景的话是很简单的,添加上以下语句(自己去添加变量哈):\x0d\x0a\x0d\x0alabel = new JLabel(background); //background为ImageIcon\x0d\x0a// 把标签的大小位置设置为图片刚好填充整个面板 \x0d\x0alabel.setBounds(0, 0, this.getWidth(), this.getHeight());\x0d\x0a//添加图片到frame的第二层(把背景图片添加到分层窗格的最底层作为背景)\x0d\x0athis.getLayeredPane().add(label,new Integer(Integer.MIN_VALUE));\x0d\x0a//把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明\x0d\x0ajPanel=(JPanel)this.getContentPane();\x0d\x0a//设置透明\x0d\x0ajPanel.setOpaque(false);\x0d\x0a\x0d\x0a然后你上面那个JPanel p也设置成透明就可以了

怎么用java代码放大或缩小图片不失真。

放大图像不会导致失真,而缩小图像将不可避免的失真。Java中也同样是这样。但java提供了4个缩放的微调选项。image.SCALE_SMOOTH //平滑优先image.SCALE_FAST//速度优先image.SCALE_AREA_AVERAGING //区域均值image.SCALE_REPLICATE //像素复制型缩放image.SCALE_DEFAULT //默认缩放模式调用方法Image new_img=old_img.getScaledInstance(1024, 768, Image.SCALE_SMOOTH);得到一张缩放后的新图。怎么用java代码放大或缩小图片不失真。

怎么用java代码模拟一张图片

用java代码模拟一张图片可以这样操作:1.创建BufferedImage类

2.根据BufferedImage类得到一个Graphics2D对象

3.根据Graphics2D对象进行逻辑操作

4.处理绘图

5.将绘制好的图片写入到图片

安卓在java代码中怎么添加imageView图片

1、创建imageview对象

2、设置imageview的图片

3、添加到布局中

示例代码

ViewGroup group = (ViewGroup) findViewById(R.id.viewGroup); //获取原来的布局容器

ImageView imageView = new ImageView(this);  //创建imageview

imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));  //image的布局方式

imageView.setImageResource(R.drawable.ic_launcher);  //设置imageview呈现的图片

group.addView(imageView);  //添加到布局容器中,显示图片。

如何用java代码获取 这个网页上的图片

你也没说是要把图片下载下来还是什么的

这里我实现的是将图片下载到电脑

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.net.HttpURLConnection;

import java.net.MalformedURLException;

import java.net.URL;

public class DownLoad {

public static void main(String[] args) {

File dstFile = new File("E:/test/test/test.jpg");

try {

URL url = new URL("");

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

InputStream is = conn.getInputStream();

saveFile(is, dstFile);

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

public static void saveFile(InputStream is,File dstFile){

FileOutputStream fos = null;

File parentFile = dstFile.getParentFile();

if(!parentFile.exists()){

parentFile.mkdirs();

}

try {

fos = new FileOutputStream(dstFile);

byte[] buff = new byte[1024 * 4];

int len;

while((len = is.read(buff)) != -1){

fos.write(buff, 0, len);

}

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}finally{

try{

if(is != null){

is.close();

}

if(fos != null){

fos.close();

}

}catch(IOException e){

e.printStackTrace();

}

}

}

}

java 图片缩放代码

直接给你一个类,直接套用就好了

import java.awt.Graphics2D;

import java.awt.RenderingHints;

import java.awt.geom.AffineTransform;

import java.awt.image.BufferedImage;

import java.awt.image.ColorModel;

import java.awt.image.WritableRaster;

import java.io.File;

import javax.imageio.ImageIO;

public class Resize {

BufferedImage bufImage;

int width;

int height;

public Resize() {

// TODO Auto-generated constructor stub

}

public Resize(String srcPath,int width,int height) {

this.width = width;

this.height = height;

try{

this.bufImage = ImageIO.read(new File(srcPath));

}catch(Exception e){

e.printStackTrace();

}

}

public static BufferedImage rize(BufferedImage srcBufImage,int width,int height){

BufferedImage bufTarget = null;

double sx = (double) width / srcBufImage.getWidth();

double sy = (double) height / srcBufImage.getHeight();

int type = srcBufImage.getType();

if(type == BufferedImage.TYPE_CUSTOM){

ColorModel cm = srcBufImage.getColorModel();

WritableRaster raster = cm.createCompatibleWritableRaster(width,

height);

boolean alphaPremultiplied = cm.isAlphaPremultiplied();

bufTarget = new BufferedImage(cm, raster, alphaPremultiplied, null);

}else

bufTarget = new BufferedImage(width, height, type);

Graphics2D g = bufTarget.createGraphics();

g.setRenderingHint(RenderingHints.KEY_RENDERING,

RenderingHints.VALUE_RENDER_QUALITY);

g.drawRenderedImage(srcBufImage, AffineTransform.getScaleInstance(sx, sy));

g.dispose();

return bufTarget;

}

}

关于java代码照片和java编程代码图片的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。