我正在导入Jpeg图像并将其添加到JTable
。该顺序很重要,并且由嵌入EXIF元数据中的时间戳确定。
我成功地按升序组织了元数据,但是当尝试将整数形式的标识符添加到每个图像时,我得到的结果是模棱两可的。 JTable
顶部的图像应从1开始并逐渐增加。System.out.println(Arrays.asList(imageList));
产生以下内容。我以粗体突出显示了图像ID。
[[Jpeg {imgId = 0,imgTimestamp = Sun Jan 01 01:37:30 GMT 2012,
imgFilename = bath_pose.jpg,imgLatitude = 50.4195,
imgLongitude = -5.089666666666667},Jpeg {imgId = 0,imgTimestamp =周六
2013年6月14日53:11 BST,imgFilename = anOxfordPhoto.jpg,
imgLatitude = 51.752833333333335,imgLongitude = -1.2536666666666667},
Jpeg {imgId = 2,imgTimestamp = Fri Aug 23 17:29:01 BST 2013,
imgFilename = pizza.jpg,imgLatitude = 10.606833333333332,
imgLongitude = 103.526}]]
我希望看到排序为... imgId = 0 .... imgId = 1 ... imgId = 2 ...具有以下内容:
@Override
protected Object doInBackground() throws Exception {
setMessage("Extracting image metadata.");
for (File file : selectedImages) {
com.drew.metadata.Metadata metadata = ImageMetadataReader.readMetadata(file);
// obtain the Exif directory
ExifSubIFDDirectory directory = metadata.getDirectory(ExifSubIFDDirectory.class);
GpsDirectory gpsDirectory = metadata.getDirectory(GpsDirectory.class);
image = new Jpeg();
image.setImgTimestamp(directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL));
image.setImgFilename(file.getName());
image.setImgLatitude(gpsDirectory.getGeoLocation().getLatitude());
image.setImgLongitude(gpsDirectory.getGeoLocation().getLongitude());
imageList.add(image);
}
Collections.sort(imageList, image);
for (int i = 0; i < imageList.size(); i++) {
image.setImgId(i);
}
System.out.println(Arrays.asList(imageList));
return null;
}
Jpeg对象
@XmlRootElement
public class Jpeg implements Comparator<Jpeg> {
private int imgId;
private Date imgTimestamp;
private String imgFilename;
private Double imgLatitude;
private Double imgLongitude;
public Jpeg() {
}
@XmlAttribute
public void setImgId(int imgId) {
this.imgId = imgId;
}
@XmlElement
public void setImgTimestamp(Date imgTimestamp) {
this.imgTimestamp = imgTimestamp;
}
@XmlElement
public void setImgFilename(String imgFilename) {
this.imgFilename = imgFilename;
}
@XmlElement
public void setImgLatitude(Double imgLatitude) {
this.imgLatitude = imgLatitude;
}
@XmlElement
public void setImgLongitude(Double imgLongitude) {
this.imgLongitude = imgLongitude;
}
public int getImgId() {
return imgId;
}
public Date getImgTimestamp() {
return imgTimestamp;
}
public String getImgFilename() {
return imgFilename;
}
public Double getImgLatitude() {
return imgLatitude;
}
public Double getImgLongitude() {
return imgLongitude;
}
public int compare(Jpeg img, Jpeg img1) {
return img.getImgTimestamp().compareTo(img1.getImgTimestamp());
}
}
有什么想法吗?
最佳答案
for (int i = 0; i < imageList.size(); i++) {
image.setImgId(i);
}
image
是最后加载的图像。您可能的意思是:
for (int i = 0; i < imageList.size(); i++) {
imageList.get(i).setImgId(i);
}