激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Java實現圖片拼接

Java實現圖片拼接

2021-05-24 12:18Abel-Luan Java教程

這篇文章主要為大家詳細介紹了Java實現圖片拼接的相關代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java實現圖片拼接的具體代碼,供大家參考,具體內容如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 * 拼接圖片(注:圖片需長寬一致)
 * @param files  img1 ,img2
 * @param type  1:橫向拼接 2:縱向拼接
 * @param targetfile 合成新的圖片地址
 */
public static void mergeimage(string[] files, int type, string targetfile) {
 int len = files.length;
 if (len < 1) {
  throw new runtimeexception("圖片數量小于1");
 }
 file[] src = new file[len];
 bufferedimage[] images = new bufferedimage[len];
 int[][] imagearrays = new int[len][];
 for (int i = 0; i < len; i++) {
  try {
   src[i] = new file(files[i]);
   images[i] = imageio.read(src[i]);
  } catch (exception e) {
   throw new runtimeexception(e);
  }
  int width = images[i].getwidth();
  int height = images[i].getheight();
  imagearrays[i] = new int[width * height];
  imagearrays[i] = images[i].getrgb(0, 0, width, height, imagearrays[i], 0, width);
 }
 int newheight = 0;
 int newwidth = 0;
 for (int i = 0; i < images.length; i++) {
  // 橫向
  if (type == 1) {
   newheight = newheight > images[i].getheight() ? newheight : images[i].getheight();
   newwidth += images[i].getwidth();
  } else if (type == 2) {// 縱向
   newwidth = newwidth > images[i].getwidth() ? newwidth : images[i].getwidth();
   newheight += images[i].getheight();
  }
 }
 if (type == 1 && newwidth < 1) {
  return;
 }
 if (type == 2 && newheight < 1) {
  return;
 }
 // 生成新圖片
 try {
  bufferedimage imagenew = new bufferedimage(newwidth, newheight, bufferedimage.type_int_rgb);
  int height_i = 0;
  int width_i = 0;
  for (int i = 0; i < images.length; i++) {
   if (type == 1) {
    imagenew.setrgb(width_i, 0, images[i].getwidth(), newheight, imagearrays[i], 0,
      images[i].getwidth());
    width_i += images[i].getwidth();
   } else if (type == 2) {
    imagenew.setrgb(0, height_i, newwidth, images[i].getheight(), imagearrays[i], 0, newwidth);
    height_i += images[i].getheight();
   }
  }
  //輸出想要的圖片
  imageio.write(imagenew, targetfile.split("\\.")[1], new file(targetfile));
 } catch (exception e) {
  throw new runtimeexception(e);
 }
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/qq_38114563/article/details/81408417

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 插插操| 久久久视频免费观看 | 99re色 | 护士hd欧美free性xxxx | 亚洲视频精选 | 成人一级毛片 | 中文字幕在线免费 | 国产一区二区精品免费 | 日本综合久久 | 亚洲va久久久噜噜噜久久男同 | 国产亚洲区 | 国产免费网站视频 | 免看黄大片aa | 成人福利视频网站 | 深夜激情视频 | 国产毛毛片一区二区三区四区 | 无遮挡一级毛片视频 | chinese军人gay呻吟 | av在线免费观看网址 | 国产一级毛片高清 | 色啪综合 | 欧美特级黄色 | 欧洲亚洲激情 | 羞羞电影网 | 成人黄色网战 | 国产精品1区2区 | 成人午夜免费看 | 曰韩黄色片 | 亚洲国产色婷婷 | 中文在线观看免费视频 | 欧美激情猛片xxxⅹ大3 | 一级黄色片武则天 | 成人羞羞在线观看网站 | 日本高清在线免费 | 成熟女人特级毛片www免费 | aa国产视频一区二区 | 激情大乳女做爰办公室韩国 | 午夜精品福利影院 | 成人偷拍片视频在线观看 | 91麻豆蜜桃一区二区三区 | 亚州欧美视频 |