当前位置:首页 > 代码 > 正文

带缩略图的焦点图代码(焦点图大小)

admin 发布:2022-12-19 20:50 143


本篇文章给大家谈谈带缩略图的焦点图代码,以及焦点图大小对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

jsp上传图片并产生缩略图的代码

/**

* 图片缩小算法,方形区域抽样

*/

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.io.FileUtils;

public class ImageUtil {

private int width;

private int height;

private int zoomWidth;

private int zoomHeight;

private File destFile;

private BufferedImage srcBufferImage;

public static void resizeFix(File srcFile, File destFile, int width,

int height) throws IOException {

new ImageUtil(srcFile, destFile, width, height);

}

public static void resizeFix(BufferedImage bufImg, File destFile,

int width, int height) throws IOException {

new ImageUtil(bufImg, destFile, width, height);

}

protected ImageUtil(File srcFile, File destFile, int zoomWidth,

int zoomHeight) throws IOException {

this.destFile = destFile;

this.zoomWidth = zoomWidth;

this.zoomHeight = zoomHeight;

this.srcBufferImage = javax.imageio.ImageIO.read(srcFile);

this.width = this.srcBufferImage.getWidth();

this.height = this.srcBufferImage.getHeight();

if (width = zoomWidth height = zoomHeight) {

FileUtils.copyFile(srcFile, destFile);

} else {

resizeFix();

}

}

protected ImageUtil(BufferedImage srcBufferImage, File destFile,

int zoomWidth, int zoomHeight) throws IOException {

this.destFile = destFile;

this.zoomWidth = zoomWidth;

this.zoomHeight = zoomHeight;

this.srcBufferImage = srcBufferImage;

this.width = this.srcBufferImage.getWidth();

this.height = this.srcBufferImage.getHeight();

resizeFix();

}

/**

* 压缩图片

*

* @throws IOException

*/

protected void resizeFix() throws IOException {

if (width = zoomWidth height = zoomHeight) {

resize(width, height);

} else if ((float) width / height (float) zoomWidth / zoomHeight) {

resize(zoomWidth, Math.round((float) zoomWidth * height / width));

} else {

resize(Math.round((float) zoomHeight * width / height), zoomHeight);

}

}

private void resize(int w, int h) throws IOException {

BufferedImage imgBuf = scaleImage(w, h);

File parent = destFile.getParentFile();

if (!parent.exists()) {

parent.mkdirs();

}

ImageIO.write(imgBuf, "jpeg", destFile);

}

private BufferedImage scaleImage(int outWidth, int outHeight) {

int[] rgbArray = srcBufferImage.getRGB(0, 0, width, height, null, 0,

width);

BufferedImage pbFinalOut = new BufferedImage(outWidth, outHeight,

BufferedImage.TYPE_INT_RGB);

double hScale = ((double) width) / ((double) outWidth);// 宽缩小的倍数

double vScale = ((double) height) / ((double) outHeight);// 高缩小的倍数

int winX0, winY0, winX1, winY1;

int valueRGB = 0;

long R, G, B;

int x, y, i, j;

int n;

for (y = 0; y outHeight; y++) {

winY0 = (int) (y * vScale + 0.5);// 得到原图高的Y坐标

if (winY0 0) {

winY0 = 0;

}

winY1 = (int) (winY0 + vScale + 0.5);

if (winY1 height) {

winY1 = height;

}

for (x = 0; x outWidth; x++) {

winX0 = (int) (x * hScale + 0.5);

if (winX0 0) {

winX0 = 0;

}

winX1 = (int) (winX0 + hScale + 0.5);

if (winX1 width) {

winX1 = width;

}

R = 0;

G = 0;

B = 0;

for (i = winX0; i winX1; i++) {

for (j = winY0; j winY1; j++) {

valueRGB = rgbArray[width * j + i];

R += getRedValue(valueRGB);

G += getGreenValue(valueRGB);

B += getBlueValue(valueRGB);

}

}

n = (winX1 - winX0) * (winY1 - winY0);

R = (int) (((double) R) / n + 0.5);

G = (int) (((double) G) / n + 0.5);

B = (int) (((double) B) / n + 0.5);

valueRGB = comRGB(clip((int) R), clip((int) G), clip((int) B));

pbFinalOut.setRGB(x, y, valueRGB);

}

}

return pbFinalOut;

}

private int clip(int x) {

if (x 0)

return 0;

if (x 255)

return 255;

return x;

}

private int getRedValue(int rgbValue) {

int temp = rgbValue 0x00ff0000;

return temp 16;

}

private int getGreenValue(int rgbValue) {

int temp = rgbValue 0x0000ff00;

return temp 8;

}

private int getBlueValue(int rgbValue) {

return rgbValue 0x000000ff;

}

private int comRGB(int redValue, int greenValue, int blueValue) {

return (redValue 16) + (greenValue 8) + blueValue;

}

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

long start = System.currentTimeMillis();

ImageUtil.resizeFix(new File("d:/04.jpg"), new File("d:/big-n.jpg"),

400, 400);

long end = System.currentTimeMillis();

System.out.println("success:" + (end - start));

}

}

依赖commons-io.jar

注:要多图。焦点图、缩略图切换,求此插件、或者代码(图片属性不显示在图中),谢谢!

试试这个图片切换

有12345数字一起切换

鼠标点一下数字会变换到另一张图片,不点就会自动换

里面有教程和源码

帝国cms 增加焦点图(幻灯片)缩略图功能

这个都是用js效果做出来的,你可以到网上搜下这些效果代码。有很多

带缩略图多屏轮播的jQuery左右滚动banner焦点图代码,到了第十一张小图片就不自动滚下去了?

肯定的 你要那种连续滚动的 要在小图前后各家一张图片才可以 最前面加最后一张最后面加最前面 然后判断

关于带缩略图的焦点图代码和焦点图大小的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/23604.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载