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.
arraylist bufferedimage
add a comment |
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.
arraylist bufferedimage
There is no connection between aBufferedImage
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 fromfileNames
? Another option is to wrap the filename and the image into a custom class, with afileName
and animage
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
add a comment |
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.
arraylist bufferedimage
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
arraylist bufferedimage
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 aBufferedImage
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 fromfileNames
? Another option is to wrap the filename and the image into a custom class, with afileName
and animage
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
add a comment |
There is no connection between aBufferedImage
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 fromfileNames
? Another option is to wrap the filename and the image into a custom class, with afileName
and animage
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 fromfileNames
? Another option is to wrap the filename and the image into a custom class, with afileName
and animage
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