「抠图java」抠图是什么意思

博主:adminadmin 2022-11-29 02:07:08 41

本篇文章给大家谈谈抠图java,以及抠图是什么意思对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

各位大神java web的问题, 图片中这种统计效果是怎么实现的?

这个图可以用bootstrap实现,也可以用谷歌之类公司提供的地图接口实现,至于统计效果,其实是按地域来算的,不是一整块的。然后不同数值从高到低用不同的颜色来显示就可以了!

您好,我在百度知道上看到了你回答了关于java调用dll的问题,我也遇到类似的一个问题需要向你请教一下

用jni (java native interface),不用改其他的,只用java就行,注意dll放到工程根目录就行了,具体怎么调用,百度一下有很多。或者你直接用jnative,百度搜jnative,很简单的,祝你好运

怎么用java实现抠图功能?

package com.thinkgem.jeesite.modules.file.utils;

import com.drew.imaging.ImageMetadataReader;

import com.drew.imaging.ImageProcessingException;

import com.drew.metadata.Directory;

import com.drew.metadata.Metadata;

import com.drew.metadata.Tag;

import javax.imageio.ImageIO;

import javax.swing.*;

import java.awt.*;

import java.awt.image.BufferedImage;

import java.io.*;

public class ImageUtils {

/**

* 图片去白色的背景,并裁切

*

* @param image 图片

* @param range 范围 1-255 越大 容错越高 去掉的背景越多

* @return 图片

* @throws Exception 异常

*/

public static byte[] transferAlpha(Image image, InputStream in, int range) throws Exception {

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

try {

ImageIcon imageIcon = new ImageIcon(image);

BufferedImage bufferedImage = new BufferedImage(imageIcon

.getIconWidth(), imageIcon.getIconHeight(),

BufferedImage.TYPE_4BYTE_ABGR);

Graphics2D g2D = (Graphics2D) bufferedImage.getGraphics();

g2D.drawImage(imageIcon.getImage(), 0, 0, imageIcon

.getImageObserver());

int alpha = 0;

int minX = bufferedImage.getWidth();

int minY = bufferedImage.getHeight();

int maxX = 0;

int maxY = 0;

for (int j1 = bufferedImage.getMinY(); j1 bufferedImage

.getHeight(); j1++) {

for (int j2 = bufferedImage.getMinX(); j2 bufferedImage

.getWidth(); j2++) {

int rgb = bufferedImage.getRGB(j2, j1);

int R = (rgb 0xff0000) 16;

int G = (rgb 0xff00) 8;

int B = (rgb 0xff);

if (((255 - R) range) ((255 - G) range) ((255 - B) range)) { //去除白色背景;

rgb = ((alpha + 1) 24) | (rgb 0x00ffffff);

} else {

minX = minX = j2 ? minX : j2;

minY = minY = j1 ? minY : j1;

maxX = maxX = j2 ? maxX : j2;

maxY = maxY = j1 ? maxY : j1;

}

bufferedImage.setRGB(j2, j1, rgb);

}

}

int width = maxX - minX;

int height = maxY - minY;

BufferedImage sub = bufferedImage.getSubimage(minX, minY, width, height);

int degree = getDegree(in);

sub = rotateImage(sub,degree);

ImageIO.write(sub, "png", byteArrayOutputStream);

} catch (Exception e) {

e.printStackTrace();

throw e;

}

return byteArrayOutputStream.toByteArray();

}

/**

* 图片旋转

* @param bufferedimage bufferedimage

* @param degree 旋转的角度

* @return BufferedImage

*/

public static BufferedImage rotateImage(final BufferedImage bufferedimage,

final int degree) {

int w = bufferedimage.getWidth();

int h = bufferedimage.getHeight();

Rectangle rect_des = CalcRotatedSize(new Rectangle(new Dimension(

w, h)), degree);

int type = bufferedimage.getColorModel().getTransparency();

BufferedImage img;

Graphics2D graphics2d;

(graphics2d = (img = new BufferedImage(rect_des.width, rect_des.height, type))

.createGraphics()).setRenderingHint(

RenderingHints.KEY_INTERPOLATION,

RenderingHints.VALUE_INTERPOLATION_BILINEAR);

graphics2d.translate((rect_des.width - w) / 2,

(rect_des.height - h) / 2);

graphics2d.rotate(Math.toRadians(degree), w / 2, h / 2);

graphics2d.drawImage(bufferedimage, 0, 0, null);

graphics2d.dispose();

return img;

}

/**

* 计算旋转后图像的大小

* @param src Rectangle

* @param degree 旋转的角度

* @return Rectangle

*/

public static Rectangle CalcRotatedSize(Rectangle src, int degree) {

if (degree = 90) {

if(degree / 90 % 2 == 1){

int temp = src.height;

src.height = src.width;

src.width = temp;

}

degree = degree % 90;

}

double r = Math.sqrt(src.height * src.height + src.width * src.width) / 2;

double len = 2 * Math.sin(Math.toRadians(degree) / 2) * r;

double angel_alpha = (Math.PI - Math.toRadians(degree)) / 2;

double angel_dalta_width = Math.atan((double) src.height / src.width);

double angel_dalta_height = Math.atan((double) src.width / src.height);

int len_dalta_width = (int) (len * Math.cos(Math.PI - angel_alpha

- angel_dalta_width));

int len_dalta_height = (int) (len * Math.cos(Math.PI - angel_alpha

- angel_dalta_height));

int des_width = src.width + len_dalta_width * 2;

int des_height = src.height + len_dalta_height * 2;

return new java.awt.Rectangle(new Dimension(des_width, des_height));

}

/**

* byte[] ------BufferedImage

*

* @param byteImage byteImage

* @return return

* @throws IOException IOException

*/

public static BufferedImage ByteToBufferedImage(byte[] byteImage) throws IOException {

ByteArrayInputStream in = new ByteArrayInputStream(byteImage);

return ImageIO.read(in);

}

/**

* 获取照片信息的旋转角度

* @param inputStream 照片的路径

* @return 角度

*/

public static int getDegree(InputStream inputStream) {

try {

Metadata metadata = ImageMetadataReader.readMetadata(new BufferedInputStream(inputStream),true);

for (Directory directory : metadata.getDirectories()) {

for (Tag tag : directory.getTags()) {

if ("Orientation".equals(tag.getTagName())) {

return turn(getOrientation(tag.getDescription()));

}

}

}

} catch (ImageProcessingException e) {

e.printStackTrace();

return 0;

} catch (IOException e) {

e.printStackTrace();

return 0;

}

return 0;

}

/**

* 获取旋转的角度

* @param orientation orientation

* @return 旋转的角度

*/

public static int turn(int orientation) {

Integer turn = 360;

if (orientation == 0 || orientation == 1) {

turn = 360;

} else if (orientation == 3) {

turn = 180;

} else if (orientation == 6) {

turn = 90;

} else if (orientation == 8) {

turn = 270;

}

return turn;

}

/**

* 根据图片自带的旋转的信息 获取 orientation

* @param orientation orientation

* @return orientation

*/

public static int getOrientation(String orientation) {

int tag = 0;

if ("Top, left side (Horizontal / normal)".equalsIgnoreCase(orientation)) {

tag = 1;

} else if ("Top, right side (Mirror horizontal)".equalsIgnoreCase(orientation)) {

tag = 2;

} else if ("Bottom, right side (Rotate 180)".equalsIgnoreCase(orientation)) {

tag = 3;

} else if ("Bottom, left side (Mirror vertical)".equalsIgnoreCase(orientation)) {

tag = 4;

} else if ("Left side, top (Mirror horizontal and rotate 270 CW)".equalsIgnoreCase(orientation)) {

tag = 5;

} else if ("Right side, top (Rotate 90 CW)".equalsIgnoreCase(orientation)) {

tag = 6;

} else if ("Right side, bottom (Mirror horizontal and rotate 90 CW)".equalsIgnoreCase(orientation)) {

tag = 7;

} else if ("Left side, bottom (Rotate 270 CW)".equalsIgnoreCase(orientation)) {

tag = 8;

}

return tag;

}

}

请问用Java 怎样实现抠图功能。比如图片是一块石头放在一张纸上,怎样

1、用ps打开两张图片。

2、在工具里选择“移动工具”,按住鼠标左键把第二个图片拖动到第一个图片里。由于第二张的像素有点大,所以会把原来的图片覆盖住的,通过鼠标稍微移动一下。

3、按ctrl+t(自由变换快捷键),图片的四周出现了可以调节的横线,按住shift拖动图片的一个角可以进行等比例缩放,这张图太大了,所以等比例缩小一点。调整为合适的大小,放到合适的地方。调整完毕,按enter键确认。

4、在右下角的图层面板里点击第三个按钮(添加矢量蒙板),为第二个图层添加一个蒙板。

5、可以看到在“工具”里,前景色和背景色默认修改为了白色和黑色。

6、然后选择工具里的“渐变”工具。可以看到,上方工具栏出现了渐变的一些设置。因为前景色为白色,背景色为黑色,所以默认是白色到黑色的渐变条。后面分别设置为径向渐变,正常模式,百分之百不透明度,反向不打勾。

7、点击白色到黑色的渐变条,进入渐变编辑器。

8、把左侧下方的白色滑块拖到中间,可以在下方的位置处直接填写百分之50。

9、把鼠标放在左侧的滑动条下方,会出现“点按可添加色标”。

10、点击一下,出现一个新的色块,为白色。把它拖动到最左边,可以直接填写百分之0。

11、选中最左边的白色色块,点击一下下面的颜色后面的白色,弹出“选择色标颜色”的窗口。在里面选择纯黑色。点击“确定”。这样就把白色改成了黑色。渐变色变成了黑-白-黑。点击“确定”。

12、可以看到上面确实变成了黑色-白色-黑色渐变。

13、一只手按住shift键,一只手按住鼠标左键在图片上拉出一条直线(按住shift键是保证水平)。

14、松开手,蒙板就起作用了,这是利用了蒙板状态下,黑色隐藏,白色显示的特点。

15、然后稍加修饰。选择工具里的“矩形选框工具”,选中要裁剪的部分。

16、点击“图像”,选择“裁剪”。

17、图片被裁剪,裁剪完成后按ctrl+d取消选中状态,或者可以点击右键,选择“取消”。

18、、这样就实现了两张图片的合成。利用蒙板和渐变色合成的方式的好处是第二个图片可以保留一部分的背景,有一种融入的感觉。如果采用抠图合并的方法,一般是给人物换背景图,技术要求比较高。

北大青鸟java培训:美工转行学大数据怎么样?

很多人在看到了这个行业的大好前景之后,就萌生了想要转行学这门技术的念头,这其中不乏一些美工人员。

笔者就收到过这么一个提问留言,他说,想知道美工转行学大数据怎么样?既然大家有疑问,那么福建福建电脑培训就详细讲讲,美工转行学大数据怎么样,这个话题,来解答大家心中的疑问。

1:美工又被人们戏称为“抠图仔”,虽然薪资可观,但是加班、单身成了这一职业的代名词,业发展限制性较高,更有观点认为美工是吃青春饭的行业,常常有美工忧虑自己的职业走向,不知道何去何从。

大数据时代来临了,使得美工们看到了曙光,大数据的确具有十分强大的发展潜力。

2:从国家政策到国内各大企业的重视程度,无一不在为大数据时代的腾飞积蓄着力量,大数据给了人们一个更广阔的发展空间,无限的发展可能。

它的应用范围十分广泛,几乎360行,行行都能利用大数据分享到不小的红利。

大数据行业其实更像是一个工具,也可以说是各行各业的一个神器。

3:广泛的行业范畴更为大数据专业人才提供了无限的可能,相比之下,美工的发展空间就会显得局促很多。

经验代表过去,而大数据代表着未来,大数据工程师的发展空间十分广阔,美工人员学大数据,无疑是很明智的选择。

一线城市的大数据工程师,月薪轻松突破15K。

如何用Java 实现抠图?

选中你想抠图的图片,右键,选中编辑选项,进入"画图"程序

2、按住"Ctrl+A",选中图片,"Ctrl+C"复制图片

抠图java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于抠图是什么意思、抠图java的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-29,除非注明,否则均为首码项目网原创文章,转载请注明出处。