0

I need an information: I have to do a project for my university's stage. My program allow me to discover an image with circular movement. I have a lot of images that should be collect in a unique "long" image, with black edges. Is it possible?

I searched in the other topic but they are only for iOs or html. My application is an application in java that will be use on the pc.

Sorry for the bad english

Thank's, Elia.

an example of the result

AxelH
  • 14,325
  • 2
  • 25
  • 55
  • Could you explain yourself better, please? I don't understand what do you mean by saying "circular movement". – joninx May 05 '17 at 09:32
  • You tagged your question javascript and java. Those are two differents languages, care to explain which one you want to use? – Turtle May 05 '17 at 09:34
  • Possible duplicate of [How to combine multiple PNGs into one big PNG file?](http://stackoverflow.com/questions/3922276/how-to-combine-multiple-pngs-into-one-big-png-file) – AxelH May 05 '17 at 09:34
  • Or have a black image and keep appending it to every image. – Manish Kumar Sharma May 05 '17 at 09:37
  • @pulp_fiction yes, but the image would need to be strech to match the height. I used this solution but don't really like it. – AxelH May 05 '17 at 09:43
  • @AxelH : Hmm..would it make any difference for a black image. I mean, appending seems to me a computationally cheap solution. – Manish Kumar Sharma May 05 '17 at 09:46
  • @pulp_fiction Well, you would need to update the image to fit the batch of image you are using to match. Don't use an black image of 1024px height if you append images of 256px, you would need to crop the result. at one point. But if you use the `Graphics.fillRect`, you can specify the height directly, and it is simpler to use and quicker probably. Just see the answer. – AxelH May 05 '17 at 09:49
  • @russellhoff I can do a circle with everything and there is a webcam that recognize the movement. – Elia Fabbris May 05 '17 at 10:03
  • @Nathan sorry, it should be java – Elia Fabbris May 05 '17 at 10:12
  • @AxelH the prototype that I did with my tutor were built like this: black edge-image-black edge-image-black edge. But I did it with paint and it were so frustrating – Elia Fabbris May 05 '17 at 10:12
  • @EliaFabbris Did you check the answer, you just need to generate the first black-edge to match you need ;) – AxelH May 05 '17 at 10:14
  • @AxelH If I understand: I have to create only the black-edge before every image and that can be work? – Elia Fabbris May 05 '17 at 10:24
  • You first create the left edge, than loop to create the image and the next black edge. At the end, you will have the correct pattern. The answer is not complete, you need to fill the blank... – AxelH May 05 '17 at 10:30
  • @AxelH Ok, so I understand it well ;) Thank you very much, really gentle :) Best regards, Elia – Elia Fabbris May 05 '17 at 10:38
  • @EliaFabbris see the update I have done. I have a working solution if needed but I will let you find the solution first, it is not complex and since this is your intership, it will be granted ;) comment the answer for more information – AxelH May 05 '17 at 10:50

1 Answers1

1

Using the dogbane's answer,

You could adapt the code easily to do what you want.

Using Graphics.fillRect to create a rectangle. Just need to set the color to black but you will need to manage the height and width in code.

g.setColor(Color.BLACK);

//Black rectangle on the left edge
g.fillRect(x, y, rectWidth, rectHeight);
x += rectSize;

for(String image : images){
    BufferedImage bi = ImageIO.read(new File(image));
    g.drawImage(bi, x, y, null);
    x += bi.getWidth();
    //Black rectangle on the right
    g.fillRect(x, y, rectWidth, rectHeight);
    x += rectSize;
}

You will see an rectWidth, rectHeight to generate the black square. You have two solutions here,

  1. set it yourself (a parameter that you give from the batch)
  2. iterate on the image first to get the biggest height of this batch (carefull on the perfs)

Note :

  1. to improve this, you might want to center the image if those have some different sizes ... this will requires somt update to add a black square up above and below. But it's a nice exercice ;)
  2. The default background is black, so you don't need to create the filled rectangle for a black one (default byte are 0 so black #000000)
  3. Stangely, a Windows XP tell me the PNG is not valid but on a Seven it works fine, might need to investigate this.

UPDATE :

Since we need the result image height and width on the beginning (didn't though about it), we answer some question

  1. It is easy to update the background color to don't bother with it later (paint the full image at the beginning
  2. We are force to iterate the image first to do the sum of there width
  3. We can get the maximum height in the same time
Community
  • 1
  • 1
AxelH
  • 14,325
  • 2
  • 25
  • 55