Armenian Knowledge Base  

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

Reply
 
LinkBack Thread Tools
Old 11.03.2006, 21:24   #1
Banned
 
Tria's Avatar
 
Join Date: 04 2004
Location: SouthPark
Age: 30
Posts: 188
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default как работать с JPG в Java ??

как работать с JPG (read/write, crop, resize, rotate... ) в Java ??
помогите плиз... хотя бы если знаете где достать соотв библотеку.
это маленкая, но проблематичная часть моей курсовой.
Reply With Quote
Old 11.03.2006, 21:33   #2
Banned
 
Forever Child's Avatar
 
Join Date: 10 2001
Location: ...осень колибри
Age: 37
Posts: 7,487
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: как работать с JPG в Java ??

неужели в родных библиотеках не описано?
Reply With Quote
Old 12.03.2006, 08:59   #3
Шестой Лесничий
 
Varg's Avatar
 
Join Date: 08 2005
Location: Театр Теней
Age: 36
Posts: 2,657
Downloads: 1
Uploads: 0
Reputation: 65 | 3
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);
}
}
}
Reply With Quote
Old 12.03.2006, 11:37   #4
Banned
 
Tria's Avatar
 
Join Date: 04 2004
Location: SouthPark
Age: 30
Posts: 188
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: как работать с JPG в Java ??

bAAAlshoy spasibA vam, ya JPEGCodec pochemut ne naxodil, shya tak poprobuem
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 11:45.


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