当前位置:首页 » 编程语言 » 生成缩略图java

生成缩略图java

发布时间: 2022-05-08 18:48:14

A. javaWeb怎么实现根据内容生成缩略图

packagecom.hoo.util;

importjava.awt.Image;
importjava.awt.image.BufferedImage;
importjava.io.File;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.net.MalformedURLException;
importjava.net.URL;
importjavax.imageio.ImageIO;
importcom.sun.image.codec.jpeg.ImageFormatException;
importcom.sun.image.codec.jpeg.JPEGCodec;
importcom.sun.image.codec.jpeg.JPEGEncodeParam;
importcom.sun.image.codec.jpeg.JPEGImageEncoder;

/**
*<b>function:</b>缩放图片工具类,创建缩略图、伸缩图片比例
*@authorhoojo
*@createDate2012-2-3上午10:08:47
*@fileScaleImageUtils.java
*@packagecom.hoo.util
*@version1.0
*/
{

_SCALE_QUALITY=1f;
_IMAGE_FORMAT=".jpg";//图像文件的格式
_FILE_PATH="C:/temp-";

/**
*<b>function:</b>设置图片压缩质量枚举类;
*Someguidelines:0.75highquality、0.5mediumquality、0.25lowquality
*@authorhoojo
*@createDate2012-2-7上午11:31:45
*@fileScaleImageUtils.java
*@packagecom.hoo.util
*@projectJQueryMobile
*@version1.0
*/
publicenumImageQuality{
max(1.0f),high(0.75f),medium(0.5f),low(0.25f);

privateFloatquality;
publicFloatgetQuality(){
returnthis.quality;
}
ImageQuality(Floatquality){
this.quality=quality;
}
}

privatestaticImageimage;

/**
*<b>function:</b>通过目标对象的大小和标准(指定)大小计算出图片缩小的比例
*@authorhoojo
*@createDate2012-2-6下午04:41:48
*@paramtargetWidth目标的宽度
*@paramtargetHeight目标的高度
*@paramstandardWidth标准(指定)宽度
*@paramstandardHeight标准(指定)高度
*@return最小的合适比例
*/
publicstaticdoublegetScaling(doubletargetWidth,doubletargetHeight,doublestandardWidth,doublestandardHeight){
doublewidthScaling=0d;
doubleheightScaling=0d;
if(targetWidth>standardWidth){
widthScaling=standardWidth/(targetWidth*1.00d);
}else{
widthScaling=1d;
}
if(targetHeight>standardHeight){
heightScaling=standardHeight/(targetHeight*1.00d);
}else{
heightScaling=1d;
}
returnMath.min(widthScaling,heightScaling);
}

B. 如何利用JAVA直接生成Flash(SWF格式)文件的缩略图谢谢了,大神帮忙啊

不知用Java怎么直接生成,只知道用fla格式转换成swf格式,就用Flash8保存为fla格式,再在预览时按Ctrl+Enter键,就可以生成一个SWF格式的文件,希望有用

C. java根据url获取网页缩略图

php">代码如下:

publicstaticBitmap
loadImageFromUrl(Stringurl,intsc){
URLm;
InputStream
i=null;
BufferedInputStreambis=null;
ByteArrayOutputStreamout=null;
byteisBuffer[]=new
byte[1024];
if(url==null)
returnnull;
try{
m=newURL(url);
i=(InputStream)
m.getContent();

bis=newBufferedInputStream(i,1024*4);
out=
newByteArrayOutputStream();
intlen=0;
while
((len=bis.read(isBuffer))!=-1){
out.write(isBuffer,0,
len);
}
out.close();
bis.close();
}catch(MalformedURLExceptione1){
e1.printStackTrace();
returnnull;
}catch
(IOExceptione){
e.printStackTrace();
}
if
(out==null)
returnnull;
byte[]data=
out.toByteArray();
BitmapFactory.Optionsoptions=new
BitmapFactory.Options();
options.inJustDecodeBounds=
true;
BitmapFactory.decodeByteArray(data,0,data.length,
options);
options.inJustDecodeBounds=false;
intbe=
(int)(options.outHeight/(float)sc);
if(be<=0)
{
be=1;
}elseif(be>3){
be=
3;
}
options.inSampleSize=be;
Bitmapbmp=
null;
try{
bmp=BitmapFactory.decodeByteArray(data,
0,data.length,options);//返回缩略图
}catch(OutOfMemoryErrore)
{
//TODO:handleexception
System.gc();
bmp=null;
}
return
bmp;
}

D. Java编程:怎么获得一个视频的缩略图呢

如果本地视频的话,可以通过Runtime类的exec方法调用ffmpeg来实现
ffmpeg是视频转码,截图的程序,我这里有

E. java 如何为swf格式的文件生产缩略图 代码

肯定不好。目前很多顾客想听原唱的DTS的歌曲。就会有人把普通原唱CD去编码做成多声道的DTS的效果的DVD。当然效果是可想而知的。
虽然比特码率都比CD时高出了很多,但只是数据的电脑转换,实际是不会带来多大效果的。 原本双声道的,经过软件处理成5.1声道,可能变得更加不如原来的立体声效果了。如果那么容易的话,所有唱片公司都可以随便转,市面上全是DTS的专辑,而没有立体声的专辑了。

F. 图片怎么样生成缩略图啊 java

您可以用jquery组件有现成的 会直接生成缩略图

G. java上传图片 生成缩略图,如果上传的图片尺寸比较小就压缩处理

//将图按比例缩小。
public static BufferedImage resize(BufferedImage source, int targetW, int targetH) {
// targetW,targetH分别表示目标长和宽
int type = source.getType();
BufferedImage target = null;
double sx = (double) targetW / source.getWidth();
double sy = (double) targetH / source.getHeight();
//这里想实现在targetW,targetH范围内实现等比缩放。如果不需要等比缩放
//则将下面的if else语句注释即可
if(sx>sy)
{
sx = sy;
targetW = (int)(sx * source.getWidth());
}else{
sy = sx;
targetH = (int)(sy * source.getHeight());
}
if (type == BufferedImage.TYPE_CUSTOM) { //handmade
ColorModel cm = source.getColorModel();
WritableRaster raster = cm.(targetW, targetH);
boolean alphaPremultiplied = cm.isAlphaPremultiplied();
target = new BufferedImage(cm, raster, alphaPremultiplied, null);
} else
target = new BufferedImage(targetW, targetH, type);
Graphics2D g = target.createGraphics();
//smoother than exlax:
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY );
g.drawRenderedImage(source, AffineTransform.getScaleInstance(sx, sy));
g.dispose();
return target;
}

public static void saveImageAsJpg (String fromFileStr,String saveToFileStr,int width,int hight)
throws Exception {
BufferedImage srcImage;
// String ex = fromFileStr.substring(fromFileStr.indexOf("."),fromFileStr.length());
String imgType = "JPEG";
if (fromFileStr.toLowerCase().endsWith(".png")) {
imgType = "PNG";
}
// System.out.println(ex);
File saveFile=new File(saveToFileStr);
File fromFile=new File(fromFileStr);
srcImage = ImageIO.read(fromFile);
if(width > 0 || hight > 0)
{
srcImage = resize(srcImage, width, hight);
}
ImageIO.write(srcImage, imgType, saveFile);

}

public static void main (String argv[]) {
try{
//参数1(from),参数2(to),参数3(宽),参数4(高)
saveImageAsJpg("C:\\Documents and Settings\\xugang\\桌面\\tmr-06.jpg",
"C:\\Documents and Settings\\xugang\\桌面\\2.jpg",
120,120);
} catch(Exception e){
e.printStackTrace();
}

}

H. java如何实现把一个大图片压缩到指定大小的图片且长宽比不变

也就是图片压缩,可以不修改任何大小的压缩(速度快),也可等比例修改大小压缩(较慢)
下面这是一段等比例缩小图片的方法。

public String compressPic(String inputDir, String outputDir,
String inputFileName, String outputFileName, int width,
int height, boolean gp,String hzm) {
try {
if (!image.exists()) {
return "";
}
Image img = ImageIO.read(image);
// 判断图片格式是否正确
if (img.getWidth(null) == -1) {
return "no";
} else {
int newWidth; int newHeight;
// 判断是否是等比缩放
if (gp == true) {
// 为等比缩放计算输出的图片宽度及高度
double rate1 = ((double) img.getWidth(null)) / (double) width ;
double rate2 = ((double) img.getHeight(null)) / (double) height ;
// 根据缩放比率大的进行缩放控制
double rate = rate1 > rate2 ? rate1 : rate2;
newWidth = (int) (((double) img.getWidth(null)) / rate);
newHeight = (int) (((double) img.getHeight(null)) / rate);
} else {
newWidth = img.getWidth(null); // 输出的图片宽度
newHeight = img.getHeight(null); // 输出的图片高度
}
BufferedImage tag = new BufferedImage((int) newWidth, (int) newHeight, BufferedImage.TYPE_INT_RGB);

/*
* Image.SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的
* 优先级比速度高 生成的图片质量比较好 但速度慢
*/
Image im = img.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
tag.getGraphics().drawImage(im, 0, 0, null);
FileOutputStream out = new FileOutputStream(outputDir + outputFileName);
//JPEGImageEncoder可适用于其他图片类型的转换
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);
out.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
return "ok";
}

I. JAVA开发微信公众号图文素材缩略图,怎么设置图文缩略图

你好。 如果要把别人的图片水印变成自己的,那么首先就是用PS软件P除掉该图片上的水印,然后将P过的图片加入微信公众平台素材库里。 方法一:点击微信公众平台后台的公众号设置——功能设置里面有个图片水印 然后你就可以选着修改水印或者图片不添...

J. 如何用java为文件生成缩略图

public static boolean scale(String imagepath,String newpath){
// 返回一个 BufferedImage,作为使用从当前已注册 ImageReader 中自动选择的 ImageReader 解码所提供 File 的结果

BufferedImage image=null;
try {
image = ImageIO.read(new File(imagepath));
} catch (IOException e) {
System.out.println("读取图片文件出错!"+e.getMessage());
return false;
}

// Image Itemp = image.getScaledInstance(300, 300, image.SCALE_SMOOTH);
double Ratio = 0.0;

if ((image.getHeight() > 300) ||(image.getWidth() > 300)) {
if (image.getHeight() > image.getWidth())
//图片要缩放的比例
Ratio = 300.0 / image.getHeight();
else
Ratio = 300.0 / image.getWidth();
}
// 根据仿射转换和插值类型构造一个 AffineTransformOp。
AffineTransformOp op = new AffineTransformOp(AffineTransform
.getScaleInstance(Ratio, Ratio), null);
// 转换源 BufferedImage 并将结果存储在目标 BufferedImage 中。
image = op.filter(image,null);
//image.getScaledInstance(300,300,image.SCALE_SMOOTH);

FileOutputStream out=null;
try {
out = new FileOutputStream(newpath);
ImageIO.write((BufferedImage)image,"bmp",out);
out.close();
} catch (Exception e) {
System.out.println("写图片文件出错!!"+e.getMessage());
return false;
}
return true;
}

热点内容
bilibili不能缓存 发布:2024-05-21 03:31:14 浏览:617
解压剃发 发布:2024-05-21 03:16:27 浏览:641
服务器怎么连接到电脑显示屏上 发布:2024-05-21 02:38:21 浏览:286
织梦安装数据库连接失败 发布:2024-05-21 02:37:45 浏览:259
python编程入门经典pdf 发布:2024-05-21 02:31:45 浏览:7
arm编译添加驱动 发布:2024-05-21 02:02:28 浏览:476
安卓设置页面是怎么 发布:2024-05-21 01:32:51 浏览:521
学生成绩管理系统数据库设计 发布:2024-05-21 01:14:41 浏览:43
我的世界什么指令直接出现服务器 发布:2024-05-21 01:10:00 浏览:397
星等算法 发布:2024-05-21 00:53:06 浏览:509