Maison > Java > javaDidacticiel > le corps du texte

java 图像的放大与缩小

黄舟
Libérer: 2016-12-30 11:51:04
original
1879 Les gens l'ont consulté

图像的放大,需要补充没有的像素,常用的方法有

1.最临近点插值算法(Nearest Neighbor)

2.双线性插值算法(Bilinear Interpolation)

3.双立方插值算法(Bicubic Interpolation)

等等,详细介绍请看(图像放大算法)
现在给出用最临近点插值方法将图像放大两倍的代码

<span style="font-size:14px;"><span style="font-size:10px;">p<span style="font-family:Courier New;">ublic void Todouble(){
		int[] doubleData = new int[2*w*2*h];
		for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
            	doubleData[2*x + 2*y *2* w] = data[x + y * w];
            }
		}
		
		this.h = 2*h;
		this.w = 2*w;
		for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
            	if(y%2 == 1)
            		doubleData[x + y*w] = doubleData[x + (y-1)*w];
            	if(x%2 == 1)
            		doubleData[x + y*w] = doubleData[x-1 + y*w];
            }
		}
		this.data = doubleData;
		
	}</span></span></span>
Copier après la connexion

效果如下:

721.jpg

722.jpg

缩小就比较简单,缩小就是去掉一些像素点。

缩小的代码:

<span style="font-size:14px;"><span style="font-size:10px;">public void reduce(int a){//a是缩小的<span style="font-family:Times New Roman;">倍数</span>
		int nw = w/a;
		int nh = h/a;
		int[] d = new int[nw*nh];
		
		for (int y = 0; y < nh; y++) {
                  for (int x = 0; x < nw; x++) {
            	   d[x + y*nw] = data[a*x + a*y * w];
                  }
		}
		this.h = nh;
		this.w = nw;
		this.data = d;
	}</span></span>
Copier après la connexion

运行效果如下:

723.jpg

 以上就是java 图像的放大与缩小的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!