How to get the element in BufferedImage [ ]?











up vote
0
down vote

favorite












I created a program that display images on JTable, so I used BufferedImage images. I used the following code to store my images in the images. The program has successfully shows the images on JTable.



int indexFile=0;
String fileNames = {"img1.jpg", "img2.jpg","img3.jpg"};
BufferedImage images = new BufferedImage[fileNames.length];
for(int j = 0; j<images.length; j++)
try {
fileNo =fileNames[indexFile];
path = "/myJava/resources/"+fileNo;
URL url = myClass.class.getResource(path);
images[j] = ImageIO.read(url);
indexFile++;
}


I want to get the value of the element in images, so I used the following code:



for(int i = 0; i<images.length; i++) {
System.out.println(images[i]) // I am expecting output like "img1.jpg"
}


My problem is, it gives me the following output instead of (e.g. img1, img2, img3).



BufferedImage@e691ea46: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@cd292449 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 607 height = 509 #numDataElements 3 dataOff[0] = 2


How can I get this output? ---> img1.jpg
Thank you.










share|improve this question
























  • There is no connection between a BufferedImage and the file it was read from. So what you are trying to do, is not directly possible. Is there a reason you can't just print the names from fileNames? Another option is to wrap the filename and the image into a custom class, with a fileName and an image field.. Should be pretty straight forward.
    – haraldK
    Nov 8 at 13:20












  • Actually it's a drag and drop program. I created a JTable with 1 row, 5 columns. Each cells I filled with images from the " bufferedImage images [ ]". The program allows user to 'rearrange' the image by drag and drop. Finally, I want to get the image file name of each cells. e.g. cell 1="img3.jpg", cell 2="img1.jpg"..etc. I tried these code 'table.getModel().getValueAt(row, column)' and 'images[i]'. But both doesn't work.
    – newbie
    Nov 8 at 16:46















up vote
0
down vote

favorite












I created a program that display images on JTable, so I used BufferedImage images. I used the following code to store my images in the images. The program has successfully shows the images on JTable.



int indexFile=0;
String fileNames = {"img1.jpg", "img2.jpg","img3.jpg"};
BufferedImage images = new BufferedImage[fileNames.length];
for(int j = 0; j<images.length; j++)
try {
fileNo =fileNames[indexFile];
path = "/myJava/resources/"+fileNo;
URL url = myClass.class.getResource(path);
images[j] = ImageIO.read(url);
indexFile++;
}


I want to get the value of the element in images, so I used the following code:



for(int i = 0; i<images.length; i++) {
System.out.println(images[i]) // I am expecting output like "img1.jpg"
}


My problem is, it gives me the following output instead of (e.g. img1, img2, img3).



BufferedImage@e691ea46: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@cd292449 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 607 height = 509 #numDataElements 3 dataOff[0] = 2


How can I get this output? ---> img1.jpg
Thank you.










share|improve this question
























  • There is no connection between a BufferedImage and the file it was read from. So what you are trying to do, is not directly possible. Is there a reason you can't just print the names from fileNames? Another option is to wrap the filename and the image into a custom class, with a fileName and an image field.. Should be pretty straight forward.
    – haraldK
    Nov 8 at 13:20












  • Actually it's a drag and drop program. I created a JTable with 1 row, 5 columns. Each cells I filled with images from the " bufferedImage images [ ]". The program allows user to 'rearrange' the image by drag and drop. Finally, I want to get the image file name of each cells. e.g. cell 1="img3.jpg", cell 2="img1.jpg"..etc. I tried these code 'table.getModel().getValueAt(row, column)' and 'images[i]'. But both doesn't work.
    – newbie
    Nov 8 at 16:46













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I created a program that display images on JTable, so I used BufferedImage images. I used the following code to store my images in the images. The program has successfully shows the images on JTable.



int indexFile=0;
String fileNames = {"img1.jpg", "img2.jpg","img3.jpg"};
BufferedImage images = new BufferedImage[fileNames.length];
for(int j = 0; j<images.length; j++)
try {
fileNo =fileNames[indexFile];
path = "/myJava/resources/"+fileNo;
URL url = myClass.class.getResource(path);
images[j] = ImageIO.read(url);
indexFile++;
}


I want to get the value of the element in images, so I used the following code:



for(int i = 0; i<images.length; i++) {
System.out.println(images[i]) // I am expecting output like "img1.jpg"
}


My problem is, it gives me the following output instead of (e.g. img1, img2, img3).



BufferedImage@e691ea46: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@cd292449 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 607 height = 509 #numDataElements 3 dataOff[0] = 2


How can I get this output? ---> img1.jpg
Thank you.










share|improve this question















I created a program that display images on JTable, so I used BufferedImage images. I used the following code to store my images in the images. The program has successfully shows the images on JTable.



int indexFile=0;
String fileNames = {"img1.jpg", "img2.jpg","img3.jpg"};
BufferedImage images = new BufferedImage[fileNames.length];
for(int j = 0; j<images.length; j++)
try {
fileNo =fileNames[indexFile];
path = "/myJava/resources/"+fileNo;
URL url = myClass.class.getResource(path);
images[j] = ImageIO.read(url);
indexFile++;
}


I want to get the value of the element in images, so I used the following code:



for(int i = 0; i<images.length; i++) {
System.out.println(images[i]) // I am expecting output like "img1.jpg"
}


My problem is, it gives me the following output instead of (e.g. img1, img2, img3).



BufferedImage@e691ea46: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@cd292449 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 607 height = 509 #numDataElements 3 dataOff[0] = 2


How can I get this output? ---> img1.jpg
Thank you.







arraylist bufferedimage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 13:21









AS Mackay

1,6813816




1,6813816










asked Nov 8 at 11:31









newbie

11




11












  • There is no connection between a BufferedImage and the file it was read from. So what you are trying to do, is not directly possible. Is there a reason you can't just print the names from fileNames? Another option is to wrap the filename and the image into a custom class, with a fileName and an image field.. Should be pretty straight forward.
    – haraldK
    Nov 8 at 13:20












  • Actually it's a drag and drop program. I created a JTable with 1 row, 5 columns. Each cells I filled with images from the " bufferedImage images [ ]". The program allows user to 'rearrange' the image by drag and drop. Finally, I want to get the image file name of each cells. e.g. cell 1="img3.jpg", cell 2="img1.jpg"..etc. I tried these code 'table.getModel().getValueAt(row, column)' and 'images[i]'. But both doesn't work.
    – newbie
    Nov 8 at 16:46


















  • There is no connection between a BufferedImage and the file it was read from. So what you are trying to do, is not directly possible. Is there a reason you can't just print the names from fileNames? Another option is to wrap the filename and the image into a custom class, with a fileName and an image field.. Should be pretty straight forward.
    – haraldK
    Nov 8 at 13:20












  • Actually it's a drag and drop program. I created a JTable with 1 row, 5 columns. Each cells I filled with images from the " bufferedImage images [ ]". The program allows user to 'rearrange' the image by drag and drop. Finally, I want to get the image file name of each cells. e.g. cell 1="img3.jpg", cell 2="img1.jpg"..etc. I tried these code 'table.getModel().getValueAt(row, column)' and 'images[i]'. But both doesn't work.
    – newbie
    Nov 8 at 16:46
















There is no connection between a BufferedImage and the file it was read from. So what you are trying to do, is not directly possible. Is there a reason you can't just print the names from fileNames? Another option is to wrap the filename and the image into a custom class, with a fileName and an image field.. Should be pretty straight forward.
– haraldK
Nov 8 at 13:20






There is no connection between a BufferedImage and the file it was read from. So what you are trying to do, is not directly possible. Is there a reason you can't just print the names from fileNames? Another option is to wrap the filename and the image into a custom class, with a fileName and an image field.. Should be pretty straight forward.
– haraldK
Nov 8 at 13:20














Actually it's a drag and drop program. I created a JTable with 1 row, 5 columns. Each cells I filled with images from the " bufferedImage images [ ]". The program allows user to 'rearrange' the image by drag and drop. Finally, I want to get the image file name of each cells. e.g. cell 1="img3.jpg", cell 2="img1.jpg"..etc. I tried these code 'table.getModel().getValueAt(row, column)' and 'images[i]'. But both doesn't work.
– newbie
Nov 8 at 16:46




Actually it's a drag and drop program. I created a JTable with 1 row, 5 columns. Each cells I filled with images from the " bufferedImage images [ ]". The program allows user to 'rearrange' the image by drag and drop. Finally, I want to get the image file name of each cells. e.g. cell 1="img3.jpg", cell 2="img1.jpg"..etc. I tried these code 'table.getModel().getValueAt(row, column)' and 'images[i]'. But both doesn't work.
– newbie
Nov 8 at 16:46

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206890%2fhow-to-get-the-element-in-bufferedimage%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206890%2fhow-to-get-the-element-in-bufferedimage%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)