當前位置:首頁 » 編程語言 » 生成縮略圖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;
}

熱點內容
昂科威選擇哪個配置 發布:2025-05-11 09:25:50 瀏覽:34
怎麼解決安卓視頻全屏卡頓 發布:2025-05-11 09:14:55 瀏覽:725
匯編從編譯到執行 發布:2025-05-11 09:09:04 瀏覽:257
安卓系統低版本如何升級 發布:2025-05-11 09:04:44 瀏覽:251
認證類型加密演算法 發布:2025-05-11 08:58:35 瀏覽:561
android停靠 發布:2025-05-11 08:42:23 瀏覽:645
超時代加密 發布:2025-05-11 08:41:29 瀏覽:780
為什麼還要輸入支取密碼 發布:2025-05-11 08:32:24 瀏覽:362
資料庫課程設計案例 發布:2025-05-11 08:15:33 瀏覽:51
為什麼安卓不能通過藍牙傳東西 發布:2025-05-11 08:15:27 瀏覽:717