Go Back   Armenian Knowledge Base > Technical sections > Webmaster Zone > Web Development

Reply
 
Thread Tools

как работать с JPG в Java ??
Old 11.03.2006, 21:24   #1
Banned
 
Tria's Avatar
 
Join Date: 04 2004
Location: SouthPark
Age: 38
Posts: 188
Rep Power: 0
Default как работать с JPG в Java ??

как работать с JPG (read/write, crop, resize, rotate... ) в Java ??
помогите плиз... хотя бы если знаете где достать соотв библотеку.
это маленкая, но проблематичная часть моей курсовой.

Re: как работать с JPG в Java ??
Old 11.03.2006, 21:33   #2
Banned
 
Forever Child's Avatar
 
Join Date: 10 2001
Location: ...осень колибри
Age: 45
Posts: 7,487
Rep Power: 0
Default Re: как работать с JPG в Java ??

неужели в родных библиотеках не описано?

Re: как работать с JPG в Java ??
Old 12.03.2006, 08:59   #3
Шестой Лесничий
 
Varg's Avatar
 
Join Date: 08 2005
Location: Театр Теней
Age: 44
Posts: 2,657
Rep Power: 4
Default Re: как работать с JPG в Java ??

2ФЦЪ Конечно описано.... искать надо

load:

public static BufferedImage loadBufferedImage(String fileName) {
// Create BufferedImage
BufferedImage bi = null;
try {
// load file from disk
FileInputStream fis = new FileInputStream(fileName);
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(fis);
bi = decoder.decodeAsBufferedImage();
fis.close();
}
catch (Exception e) {}

resizе:


public static BufferedImage scaleToSize(int nMaxWidth, int nMaxHeight, BufferedImage imgSrc)
{
int nHeight = imgSrc.getHeight();
int nWidth = imgSrc.getWidth();
double scaleX = (double)nMaxWidth / (double)nWidth;
double scaleY = (double)nMaxHeight / (double)nHeight;
double fScale = Math.min(scaleX, scaleY);
return scale(fScale, imgSrc);
}

public static BufferedImage scale(double scale, BufferedImage srcImg)
{
if (scale == 1 )
{
return srcImg;
}
AffineTransformOp op = new AffineTransformOp
(AffineTransform.getScaleInstance(scale, scale), null);
return op.filter(srcImg, null);
}

save:


public static void saveImageToDisk(BufferedImage bi, String str) {
if (bi != null && str != null) {

// save image as Jpeg
FileOutputStream out = null;
try {
out = new FileOutputStream(str);
}
catch (java.io.FileNotFoundException fnf) {
System.out.println("File Not Found");
}

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(0.75f, false);

try {
encoder.encode(bi);
out.close();
}
catch (java.io.IOException io) {
System.out.println(io);
}
}
}

Re: как работать с JPG в Java ??
Old 12.03.2006, 11:37   #4
Banned
 
Tria's Avatar
 
Join Date: 04 2004
Location: SouthPark
Age: 38
Posts: 188
Rep Power: 0
Default Re: как работать с JPG в Java ??

bAAAlshoy spasibA vam, ya JPEGCodec pochemut ne naxodil, shya tak poprobuem
Reply




Реклама:
реклама
Buy text link .

All times are GMT. The time now is 15:10.
Top

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.