Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35003 > unrolled thread

What do you think of my CropImage class

Started byCecil Westerhof <Cecil@decebal.nl>
First post2016-07-20 09:15 +0200
Last post2016-07-21 20:12 +0200
Articles 20 on this page of 59 — 8 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-20 09:15 +0200
    Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-20 11:12 +0200
    Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-20 10:02 -0700
      Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-20 21:14 +0200
        Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-20 12:50 -0700
          Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 12:11 +0200
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 14:19 +0200
        Re: What do you think of my CropImage class Qu0ll <qu0ll64@gmail.com> - 2016-07-21 05:53 +1000
        Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-20 13:46 -0700
          Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-20 13:59 -0700
            Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-20 15:40 -0700
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 12:27 +0200
              Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 05:17 -0700
                Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 17:43 +0200
                  Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 08:59 -0700
                    Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 19:10 +0200
                      Re: What do you think of my CropImage class Arne Vajhøj <arne@vajhoej.dk> - 2016-07-23 21:47 -0400
                        Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-25 04:51 -0700
                          Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-25 15:01 -0700
                            Re: What do you think of my CropImage class Arne Vajhøj <arne@vajhoej.dk> - 2016-07-25 21:06 -0400
                          Re: What do you think of my CropImage class Arne Vajhøj <arne@vajhoej.dk> - 2016-07-25 21:09 -0400
              Re: What do you think of my CropImage class Nigel Wade <nmw@local.domain> - 2016-07-21 15:44 +0100
                Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 17:46 +0200
          Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 12:25 +0200
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 14:16 +0200
      Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 12:05 +0200
        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 13:23 +0200
        Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-21 07:58 -0700
          Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 11:13 -0400
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 18:12 +0200
          Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 17:49 +0200
    Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 11:58 +0200
      Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 09:35 -0400
        Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 09:03 -0700
          Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 12:39 -0400
        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 18:07 +0200
          Re: What do you think of my CropImage class Nigel Wade <nmw@local.domain> - 2016-07-21 17:23 +0100
          Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 12:56 -0400
        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 19:03 +0200
          Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 10:25 -0700
            Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 14:24 -0400
              Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 11:54 -0700
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 20:25 +0200
              Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 15:37 -0400
                Re: What do you think of my CropImage class Martin Gregorie <martin@address-in-sig.invalid> - 2016-07-21 21:30 +0000
                Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 23:52 +0200
                  Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 20:35 -0400
                    Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-22 04:21 +0200
                      Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 22:44 -0400
                        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-22 10:27 +0200
                          Re: What do you think of my CropImage class Martin Gregorie <martin@address-in-sig.invalid> - 2016-07-22 10:47 +0000
                        Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-22 05:16 -0700
                          Re: What do you think of my CropImage class Nigel Wade <nmw@local.domain> - 2016-07-22 15:10 +0100
                            Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-22 07:47 -0700
                            Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-22 10:21 -0700
      Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-21 08:30 -0700
        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 18:19 +0200
          Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 10:18 -0700
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 20:12 +0200

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#35140

FromArne Vajhøj <arne@vajhoej.dk>
Date2016-07-25 21:09 -0400
Message-ID<nn6d7p$f7v$2@gioia.aioe.org>
In reply to#35134
On 7/25/2016 7:51 AM, Eric Douglas wrote:
> On Saturday, July 23, 2016 at 9:47:57 PM UTC-4, Arne Vajhøj wrote:
>> Business applications usually have web GUI's.
>
> These days it seems there's a lot of hybrids.  Last I checked for
> Java jobs they all wanted someone who knows the web, Java EE and
> similar technologies.

Java EE jobs is a very large portion of Java jobs.

>                 Many different methods to connect the data to
> the web, but the desktop application is still kicking.

Absolutely. But not much in Java (unless we define an
Android app as desktop, which it is not traditionally even
though on a large tablet the difference is subtle).

>                                               Most likely
> the customer service people in house are not using a browser
> interface.

A lot are.

Easier deployment and maintenance.

Arne


[toc] | [prev] | [next] | [standalone]


#35044

FromNigel Wade <nmw@local.domain>
Date2016-07-21 15:44 +0100
Message-ID<dvc5dlF62naU1@mid.individual.net>
In reply to#35035
On 21/07/16 11:27, Cecil Westerhof wrote:
> I want to crop a
> piece of exactly 1080x1080 out of a picture. Something I cannot do
> easily with an image editor.

You can with GIMP.

 From Tools->Transform Tools select Crop.
Open the Tool Options dialog box (Windows->Dockable Dialogs->Tool Options).
Check the Fixed checkbox, and select Size from the dropbox.
Enter 1080x1080 in the entry field.
Click on the save button (green arrow pointing to a "disk"), and choose New tool preset. Give it a suitable name.
Now you can use that preset any time you want to select a fixed size cut area.

When you select on the image display it will allow you to drag around a fixed size rectangle cut box.
Click in the box to cut the area.

[toc] | [prev] | [next] | [standalone]


#35050

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 17:46 +0200
Message-ID<87twfj56zb.fsf@Equus.decebal.nl>
In reply to#35044
On Thursday 21 Jul 2016 16:44 CEST, Nigel Wade wrote:

> On 21/07/16 11:27, Cecil Westerhof wrote:
>> I want to crop a
>> piece of exactly 1080x1080 out of a picture. Something I cannot do
>> easily with an image editor.
>
> You can with GIMP.
>
> From Tools->Transform Tools select Crop. Open the Tool Options
> dialog box (Windows->Dockable Dialogs->Tool Options). Check the
> Fixed checkbox, and select Size from the dropbox. Enter 1080x1080 in
> the entry field. Click on the save button (green arrow pointing to a
> "disk"), and choose New tool preset. Give it a suitable name. Now
> you can use that preset any time you want to select a fixed size cut
> area.
>
> When you select on the image display it will allow you to drag
> around a fixed size rectangle cut box. Click in the box to cut the
> area.

I did not know that. I certainly should look into it. But I do not
mind I started this, because in the long run I want to do have several
different sizes to select. It is at least a way to learn Swing. ;-)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35034

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 12:25 +0200
Message-ID<87mvlb70fl.fsf@Equus.decebal.nl>
In reply to#35022
On Wednesday 20 Jul 2016 22:46 CEST, Knute Johnson wrote:

> On 7/20/2016 12:14, Cecil Westerhof wrote:
>> On Wednesday 20 Jul 2016 19:02 CEST, Knute Johnson wrote:
>>
>>> On 7/20/2016 00:15, Cecil Westerhof wrote:
>>>> I need to crop some images and decide to write a Java program for
>>>> it. At the moment it is very rudimentary, I plan to add some
>>>> functionalities and because I have very little experience with
>>>> GUI comments on how to implement the GUI better are welcome.
>>>>
>>>>
>>>> At the moment it is build with my camera's in mind and cropping
>>>> for InstaGram, but when it is seen as useful I will make it more
>>>> generic.
>>>>
>>>>
>>>> I have a few problems, the most important are: - After loading
>>>> the first or a new image the first click makes the image
>>>> disappear and painted again. Subsequent clicks do not have this
>>>> problem.
>>>
>>> We'd need to see the code
>>
>> That is stupid: I thought I had pasted the link, but I did not.
>> >:-(
>>
>> Here it is:
>> https://github.com/CecilWesterhof/JavaExamples/blob/master/CropImage/CropImage.java
>>
>
> I looked at your code and find it a bit disjointed (but I do have a
> rather linear outlook).  I guess it really depends on what you
> ultimately are trying to do though.

I wrote a better explanation as reply on my original post. If it is
still not clear: do not hesitate to ask.


>  If I were going to write a GUI
> program to crop images today, I would:
> 	1) have a dialog to load an image (you have that) and display it
> along with its current dimensions

Good extension.


> 	2) have a method to scale the displayed image so that you can
> operate on images bigger than your monitor

That is not what I want: I want to see the complete picture.


> 	3) use something along the lines of my CropComponent to visually
> crop the image, showing the dimensions of the crop

I was thinking about that. But it has to be scaled down otherwise it
does not fit. But I probably could display a 540x540 image.

I do not think it is the first thing I will implement, but I certainly
will.


> 	4) display the cropped image and its new dimensions, so it can be
> cropped again

In a way I am doing that. But it would probably be better to display
and only when it is OK to save it.

But you know what they say: make it work, then make it better.


> or get GIMP cause it does everything for free.

That does not work for me. I need to crop exactly 1080x1080. I tried
that but found it easier to just call Image Magick convert again and
again until I had found the right part. My application is not perfect,
but (for me) a lot better.


> You might look at
> GIMP for their interface, it is really quite good. The image is in
> its own dialog and all the tools are in a couple of others for handy
> access. Take a look at the Zoom options under the View menu to see
> what I mean about #2 above.

Well, at the moment I only want to crop a piece out of a picture. ;-)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35040

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 14:16 +0200
Message-ID<87a8hb6v9k.fsf@Equus.decebal.nl>
In reply to#35034
On Thursday 21 Jul 2016 12:25 CEST, Cecil Westerhof wrote:

>> 	1) have a dialog to load an image (you have that) and display it
>> along with its current dimensions
>
> Good extension.

Done.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35033

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 12:05 +0200
Message-ID<87vazz71ct.fsf@Equus.decebal.nl>
In reply to#35010
On Wednesday 20 Jul 2016 19:02 CEST, Knute Johnson wrote:

> On 7/20/2016 00:15, Cecil Westerhof wrote:
>> - The original photo can be rotated. How can I find this out and
>> make the cropped image also rotated?
>
> That's in the image meta data (I have no clue how to find it)

Yes, it is in the image data. I could find it with Image Magick, but I
like this to be pure Java.


>> - How can I add comment to an image?
>
> You want to draw on the image or add meta data?

Add meta data (EXIF).


>> - After saving the cropped image I want to display it also. What
>> would be the best way to do this?
>
> In another window maybe

Already done. Was easier as I thought. ;-)


> Here's a crop component that I wrote years ago, I don't think I ever
> used it for anything but I can't remember.


> subImage = CropComponent.this.bi.getSubimage(x,y,w+1,h+1);

That is a lot better as what I did. I should implement it.


> Runnable r = new Runnable() {
> public void run() {
> try {
> ImageIO.write(subImage,"JPEG",new
> File("crop.jpg"));
> } catch (IOException ioe) {
> ioe.printStackTrace();
> }
> }
> };
> new Thread(r).start();

Why are you doing this in a separate thread?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35036

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 13:23 +0200
Message-ID<87eg6n6xpt.fsf@Equus.decebal.nl>
In reply to#35033
On Thursday 21 Jul 2016 12:05 CEST, Cecil Westerhof wrote:

>> subImage = CropComponent.this.bi.getSubimage(x,y,w+1,h+1);
>
> That is a lot better as what I did. I should implement it.

Did it. And gave credits to you. ;-)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35045

FromKnute Johnson <nospam@rabbitbrush.frazmtn.com>
Date2016-07-21 07:58 -0700
Message-ID<nmqnv4$rj3$1@dont-email.me>
In reply to#35033
On 7/21/2016 03:05, Cecil Westerhof wrote:
>
>> Runnable r = new Runnable() {
>> public void run() {
>> try {
>> ImageIO.write(subImage,"JPEG",new
>> File("crop.jpg"));
>> } catch (IOException ioe) {
>> ioe.printStackTrace();
>> }
>> }
>> };
>> new Thread(r).start();
>
> Why are you doing this in a separate thread?
>

So if you have a large image that takes a second or two to write it 
won't block the Event Dispatch Thread and mess up the mouse movement.

-- 

Knute Johnson

[toc] | [prev] | [next] | [standalone]


#35046

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-07-21 11:13 -0400
Message-ID<nmqoqp$us$1@dont-email.me>
In reply to#35045
On 7/21/2016 10:58 AM, Knute Johnson wrote:
> On 7/21/2016 03:05, Cecil Westerhof wrote:
>>
>>> Runnable r = new Runnable() {
>>> public void run() {
>>> try {
>>> ImageIO.write(subImage,"JPEG",new
>>> File("crop.jpg"));
>>> } catch (IOException ioe) {
>>> ioe.printStackTrace();
>>> }
>>> }
>>> };
>>> new Thread(r).start();
>>
>> Why are you doing this in a separate thread?
>>
>
> So if you have a large image that takes a second or two to write it
> won't block the Event Dispatch Thread and mess up the mouse movement.

     A slightly slicker way to do this is with a SwingWorker, the
advantage being that it can inform the GUI when the save completes.
You could then display a JDialog if there was a problem, or arrange
to display a busy cursor while the save runs and restore the original
cursor afterward, or ...

     SwingWorker is, however, a bit more complex than a "fire and forget"
Thread, so CW might choose to stick with the simpler alternative for
now and revisit the fancier one later on.

http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#35054

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 18:12 +0200
Message-ID<87h9bj55t1.fsf@Equus.decebal.nl>
In reply to#35046
On Thursday 21 Jul 2016 17:13 CEST, Eric Sosman wrote:

> On 7/21/2016 10:58 AM, Knute Johnson wrote:
>> On 7/21/2016 03:05, Cecil Westerhof wrote:
>>>
>>>> Runnable r = new Runnable() {
>>>> public void run() {
>>>> try {
>>>> ImageIO.write(subImage,"JPEG",new
>>>> File("crop.jpg"));
>>>> } catch (IOException ioe) {
>>>> ioe.printStackTrace();
>>>> }
>>>> }
>>>> };
>>>> new Thread(r).start();
>>>
>>> Why are you doing this in a separate thread?
>>>
>>
>> So if you have a large image that takes a second or two to write it
>> won't block the Event Dispatch Thread and mess up the mouse
>> movement.
>
> A slightly slicker way to do this is with a SwingWorker, the
> advantage being that it can inform the GUI when the save completes.
> You could then display a JDialog if there was a problem, or arrange
> to display a busy cursor while the save runs and restore the
> original cursor afterward, or ...
>
> SwingWorker is, however, a bit more complex than a "fire and forget"
> Thread, so CW might choose to stick with the simpler alternative for
> now and revisit the fancier one later on.
>
> http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html

I keep getting homework. :-D

Probably nice to do, but there are a lot of things I have to do that
are a lot more important. So I am probably going to do it, but it
could take a while.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35049

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 17:49 +0200
Message-ID<87poq756ue.fsf@Equus.decebal.nl>
In reply to#35045
On Thursday 21 Jul 2016 16:58 CEST, Knute Johnson wrote:

> On 7/21/2016 03:05, Cecil Westerhof wrote:
>>
>>> Runnable r = new Runnable() {
>>> public void run() {
>>> try {
>>> ImageIO.write(subImage,"JPEG",new
>>> File("crop.jpg"));
>>> } catch (IOException ioe) {
>>> ioe.printStackTrace();
>>> }
>>> }
>>> };
>>> new Thread(r).start();
>>
>> Why are you doing this in a separate thread?
>>
>
> So if you have a large image that takes a second or two to write it
> won't block the Event Dispatch Thread and mess up the mouse
> movement.

I did not experience that, but I was of-course also selecting the
file. I am going to change that anyway: I am going to display it and
add a button to save it, so it is only saved after you have verified
it is OK. ;-)
And then a separate thread probably is a good idea.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35042

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 11:58 +0200
Message-ID<8737n36ucx.fsf@Equus.decebal.nl>
In reply to#35003

[Multipart message — attachments visible in raw view] — view raw

I was not completely clear :'-( so here some more info.

I have no real experience with Swing and had an itch to scratch.
That is why I wrote this program: to get some experience with
Swing and get a little tool to make my live a little easier.

At the moment it is the first try: there is a lot that could be done
much better, but at least this makes live a little easier for me.

The problem is that I like to crop part of a photo to post on
Instagram. For example:
    https://www.instagram.com/p/BIGN8pjACDT/
and:
    https://www.instagram.com/p/BIGNtrpAmnT/

The first is not perfect, because the leg of the frog is cut of, but I
want to have a one on one crop to keep the quality of the picture. (Or
a 2, 3, 4 on 1 crop, but that is for a next step.)

To show what I mean see the picture in the link. Sometimes a picture says
more as a thousand words. ;-)

https://drive.google.com/file/d/0BzW5q7uL-6z0XzNJb0FSRFFxMDA/

Gimp does not work (at least for me), because I have to crop exactly a
piece of 1080x1080. I do not know how to do this with Gimp. Also when it
is not correct I need to draw again, with the program I have just to
move the cursor a little and click again. Would be better when I could
drag the square, but again: this is just my first try.


A rundown of what the program does:

When it starts it asks for a graphic file to be displayed. It displays
this with both the width and height divided by eight because I want to
see the complete picture.

The program displays a square of 135x135 in the upper left corner. When
multiplied by 8 this gives the wanted 1080x1080.

By clicking in the picture the square is moved to select the part of the
picture I want to crop.

By clicking on crop a file is selected to save the selected area and the
saved part is displayed. The displaying of the selected part is done
without re-sizing because I want to see exactly what I did select and it
can almost be displayed on my screens.

If I am satisfied with the cropped image I can click load to start with
the next picture.


What needs to be improved:

- It should be system independent. For me pack did not work, so I put
  things on a hard coded position. This will probably be no problem when
  it is run on another Linux machine, but could wreck havoc on a Windows
  machine.
- I should know if the image is rotated, so I could rotate the cropped
  image also. Maybe this is not really important, because I am thinking
  about putting all pictures in a SQLite database and then the rotation
  will also be stored.
- After loading an image the first click results in flicker. This should
  be solved.
- I want to have the possibility to add comment to the picture. (EXIF)
- It now only works with the primary dimensions of Instagram, but it
  should also work with the other two. After this it should also work
  with the dimensions of the other Social Media and it should be
  possible to add your own custom dimensions. (SQLite to the rescue.)
- Possibility to resize. (Select an area of 2.160x2.160 and crop it to
  1.080x1.080).
- Instead of clicking it should work with dragging the square (or
  rectangle).
- Probably a lot of other things. :-D I am open to suggestions.


On Wednesday 20 Jul 2016 09:15 CEST, Cecil Westerhof wrote:

> I need to crop some images and decide to write a Java program for
> it. At the moment it is very rudimentary, I plan to add some
> functionalities and because I have very little experience with GUI
> comments on how to implement the GUI better are welcome.
>
>
> At the moment it is build with my camera's in mind and cropping for
> InstaGram, but when it is seen as useful I will make it more
> generic.
>
>
> I have a few problems, the most important are: - After loading the
> first or a new image the first click makes the image disappear and
> painted again. Subsequent clicks do not have this problem. - The
> original photo can be rotated. How can I find this out and make the
> cropped image also rotated? - How can I add comment to an image? -
> After saving the cropped image I want to display it also. What would
> be the best way to do this?
>
> Some of the functionalities I want to add (other ideas are welcome):
> - Working with different sets of cropping. - Possibility to resize.
> (Select an area of 2.160x2.160 and crop it to 1.080x1.080). -
> Working with a database.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35043

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-07-21 09:35 -0400
Message-ID<nmqj30$boh$1@dont-email.me>
In reply to#35042
On 7/21/2016 5:58 AM, Cecil Westerhof wrote:
> I was not completely clear :'-( so here some more info.
>
> I have no real experience with Swing and had an itch to scratch.
> That is why I wrote this program: to get some experience with
> Swing and get a little tool to make my live a little easier.
> [...]

     I have not studied your code closely, but one thing jumps out:
You're doing Swingthings on the wrong thread.  Almost all of Swing
is thread-unsafe, and almost all manipulation of Swing objects
must occur on the Event Dispatching Thread, or EDT.  Your code
breaches this requirement:

     - It constructs a pair of JLabels on whatever thread loads and
initializes the class.  (And the JLabels are static, which is so
very odd as to be downright weird.  Have you thought this through?)

     - It constructs a bunch of Swing components on whatever thread
executes main().  Furthermore, it manipulates those components (setting
bounds, etc.), and even makes the JFrame visible -- all while running
on the same wrong thread.

     Don't Do That.  See

http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html

... for a discussion of the issues, and how to deal with them.  (I
rather suspect that the "flicker" you report may have its origins
in, er, wrong-threadedness.)

     A few other random remarks:

     - You mention that "for me pack did not work," which is sort of
weird.  I don't know what you tried before you settled on absolute
positioning, but I wonder: Could your layout troubles have anything
to do with the fact that CropImage extends Panel instead of JPanel?

     - Maybe not, but then: What is the purpose of the DispImage class?
What does it accomplish that couldn't just as well be done in the
containing CropImage class (if the latter were a JPanel)?

     - There's a handy MouseAdapter class that can eliminate some
verbosity in your MouseListener implementation.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#35052

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-07-21 09:03 -0700
Message-ID<102610cd-cf6f-4f48-aeaa-60669d8bf045@googlegroups.com>
In reply to#35043
On Thursday, July 21, 2016 at 9:35:39 AM UTC-4, Eric Sosman wrote:
>      I have not studied your code closely, but one thing jumps out:
> You're doing Swingthings on the wrong thread.  Almost all of Swing
> is thread-unsafe, and almost all manipulation of Swing objects
> must occur on the Event Dispatching Thread, or EDT.  Your code
> breaches this requirement:

Displaying an image needs to be done on the EDT but can you generate the image in a background thread?  Does it come up headless?

[toc] | [prev] | [next] | [standalone]


#35056

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-07-21 12:39 -0400
Message-ID<nmqtse$j2b$1@dont-email.me>
In reply to#35052
On 7/21/2016 12:03 PM, Eric Douglas wrote:
> On Thursday, July 21, 2016 at 9:35:39 AM UTC-4, Eric Sosman wrote:
>>      I have not studied your code closely, but one thing jumps out:
>> You're doing Swingthings on the wrong thread.  Almost all of Swing
>> is thread-unsafe, and almost all manipulation of Swing objects
>> must occur on the Event Dispatching Thread, or EDT.  Your code
>> breaches this requirement:
>
> Displaying an image needs to be done on the EDT but can you generate the image in a background thread?  Does it come up headless?

     The image itself is not a Swing component, and has no necessary
affiliation with the EDT.  Presumably, the image will eventually be
painted onto a Graphics instance associated with a Swing component,
and that painting operation must happen on the EDT.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#35053

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 18:07 +0200
Message-ID<87lh0v560n.fsf@Equus.decebal.nl>
In reply to#35043
On Thursday 21 Jul 2016 15:35 CEST, Eric Sosman wrote:

> On 7/21/2016 5:58 AM, Cecil Westerhof wrote:
>> I was not completely clear :'-( so here some more info.
>>
>> I have no real experience with Swing and had an itch to scratch.
>> That is why I wrote this program: to get some experience with
>> Swing and get a little tool to make my live a little easier.
>> [...]
>
> I have not studied your code closely, but one thing jumps out:
> You're doing Swingthings on the wrong thread.  Almost all of Swing
> is thread-unsafe, and almost all manipulation of Swing objects
> must occur on the Event Dispatching Thread, or EDT.  Your code
> breaches this requirement:
>
> - It constructs a pair of JLabels on whatever thread loads and
> initializes the class.  (And the JLabels are static, which is so
> very odd as to be downright weird.  Have you thought this through?)

Not really no: I just wanted to know if I could solve the problem of
cropping. ;-)

But about the things being static. There is always exactly one, so
what is the problem with things being static? If it is a real no-no I
could change it.


> - It constructs a bunch of Swing components on whatever thread
> executes main(). Furthermore, it manipulates those components
> (setting bounds, etc.), and even makes the JFrame visible -- all
> while running on the same wrong thread.
>
> Don't Do That.  See
>
> http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html

I will look into it. I wanted to learn, now I have to. :-D


> ... for a discussion of the issues, and how to deal with them.  (I
> rather suspect that the "flicker" you report may have its origins
> in, er, wrong-threadedness.)

No, it was that I used a Panel instead of a JPanel. I copied that part
from somewhere of the internet. I found it a little bit strange that a
Panel was used instead of a JPanel, but I thought “What do I know”? I
changed it to JPanel and that problem went away. I had to add:
    super.paintComponent(g);
to the paint function (otherwise the old one stays ‘below’ the new one
and that is a problem when the new picture is smaller as the old one),
but that is a small price to pay. :-D

Next time I should listen to that little voice.


> A few other random remarks:
>
> - You mention that "for me pack did not work," which is sort of
> weird.  I don't know what you tried before you settled on absolute
> positioning, but I wonder: Could your layout troubles have anything
> to do with the fact that CropImage extends Panel instead of JPanel?

I am going to try this out.


> - Maybe not, but then: What is the purpose of the DispImage class?
> What does it accomplish that couldn't just as well be done in the
> containing CropImage class (if the latter were a JPanel)?

I created the DispImage class to display the cropped image. And I am
going to use it to save it also. It is better to verify it before
saving it.


> - There's a handy MouseAdapter class that can eliminate some
> verbosity in your MouseListener implementation.

And something else I have to look into. I am happy to do, because I
found it much to verbose, but I did not know a better way.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35055

FromNigel Wade <nmw@local.domain>
Date2016-07-21 17:23 +0100
Message-ID<dvcb7pF7g4hU1@mid.individual.net>
In reply to#35053
On 21/07/16 17:07, Cecil Westerhof wrote:
>> Don't Do That.  See
>> >
>> >http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html
> I will look into it. I wanted to learn, now I have to.:-D
>
>

I would recommend that you read most of that tutorial. I have it bookmarked and refer to it frequently, there's just too much to remember everything.

Pay particular attention to the sections on Using Swing Components, Laying Out Components Within a Container and Performing Custom Painting.

There's also a good article on custom painting at:
http://www.oracle.com/technetwork/java/painting-140037.html

[toc] | [prev] | [next] | [standalone]


#35058

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-07-21 12:56 -0400
Message-ID<nmqusg$mf5$1@dont-email.me>
In reply to#35053
On 7/21/2016 12:07 PM, Cecil Westerhof wrote:
> On Thursday 21 Jul 2016 15:35 CEST, Eric Sosman wrote:
> [...]
>> - It constructs a pair of JLabels on whatever thread loads and
>> initializes the class.  (And the JLabels are static, which is so
>> very odd as to be downright weird.  Have you thought this through?)
> [...]
> But about the things being static. There is always exactly one, so
> what is the problem with things being static? If it is a real no-no I
> could change it.

     There's a containment hierarchy of displayed things: You start
with a top-level container (JFrame, JDialog, ...) that contains lower-
level sub-components (JPanels, JTrees, ...) that in turn contain
still lower-level components (JButtons, more JPanels, ...).  That
is, components are nested in a tree.

     It follows that a given component can appear at only one spot
in the tree: It is contained in exactly one container, or is a
top-level component that is not contained at all.  This way, the
contained component can have (for example) *a* position relative
to its container, instead of a whole Map of "I'm *here* in this
container, *there* in that container, ..."  (Swing might have
required a container to maintain a list of contained objects *and*
their positions and sizes, but it didn't; positions and sizes and
so on are attributes of the contained objects.)

     To maintain tree-ness, when you add a component to a container
Swing automatically removes it from any container it already belonged
to.  So, if you have a static JLabel and you add it to one CropImage
instance, it cannot simultaneously appear in another CropImage: It
can be in one or the other (or neither), but not in both.  Since
you're probably anticipating only one CropImage instance this may
not seem a big deal, may not even *be* a big deal (were it not for
the EDT issue), but it's certainly weird.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#35059

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 19:03 +0200
Message-ID<878twu6i0l.fsf@Equus.decebal.nl>
In reply to#35043
On Thursday 21 Jul 2016 15:35 CEST, Eric Sosman wrote:

> - You mention that "for me pack did not work," which is sort of
> weird.  I don't know what you tried before you settled on absolute
> positioning, but I wonder: Could your layout troubles have anything
> to do with the fact that CropImage extends Panel instead of JPanel?

I pushed a version where I use a flag USE_PACK to show the problem.
(And it also uses invokeLater.)
When you compile the program as is it shows only a very small part of
the image.
When making the window greater at first only the picture is shown.
When making it bigger at a certain point crop size comes from under
the picture.
When keeping to make the window bigger crop size moves to a lower
position.
The other parts do not even show up. So I suppose they are buried
beneath the picture.
When setting USE_PACK to false the absolute positioning is set back.

If anybody could tell me what I am wrong …

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#35062

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-07-21 10:25 -0700
Message-ID<e5b9e305-d209-436d-9885-925ae416aada@googlegroups.com>
In reply to#35059
On Thursday, July 21, 2016 at 1:14:08 PM UTC-4, Cecil Westerhof wrote:
>

I never or rarely use pack, though many examples on the web do.  It automatically sets the size and location of your controls based on their size values, the layout, and the other controls on the same pane.  In our application that's irrelevant since we use non-resizeable windows and fixed locations and widths.  The pack values have to do with one of the sizes (each control has getSize(), getPreferredSize(), getMinimumSize(), getMaximumSize()) and whether the control is visible.

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.lang.java.programmer


csiph-web