Perl to Java conversion or Image Modification?

Discussion in 'Programming' started by js1023a, Jun 19, 2009.

  1. #1
    Hey guys, could you please help me convert this to java?

    use Image::Magick;
     
    my @x_coords = qw(0 100 200);
    my @y_coords = qw(0 90);
    my $source_image = Image::Magick->new();
    $source_image->Read("source_image.gif");
     
    for (my $x = 0; $x < @x_coords; $x++)
    {
        my $x_at_right = $x == $#x_coords
                         ? $source_image->Get('columns')
                         : $x_coords[$x + 1];
        for (my $y = 0; $y < @y_coords; $y++)
        {
            my $y_at_bottom = $y == $#y_coords
                              ? $source_image->Get('height')
                              : $y_coords[$y + 1];
     
            my $x_coord = $x_coords[$x];
            my $y_coord = $y_coords[$y];
            my $width   = $x_at_right  - $x_coord;
            my $height  = $y_at_bottom - $y_coord;
     
            my $sub_image = $source_image->Clone();
            $sub_image->Crop(x      => $x_coords[$x],
                             y      => $y_coords[$y],
                             width  => $width,
                             height => $height);
     
            my $section_fname = "sections-x$x-y$y.gif";
            $sub_image->Write($section_fname);
        }
    }
    Code (markup):

    Or create something to do this:

    I need to divide up a BufferedImage (or just a regular Image) in java into multiple images based on my discretion. I can provide the coordinates to divide them at, but how do you suggest I divide up the Image? (The images will be of different sizes, but all will fit together (no part of the image will be left out).

    For example (the image could be divided up like this):
    Thank you!
     
    js1023a, Jun 19, 2009 IP
  2. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #2
    *nix or Windows platform? Also, which version of the JDK and have you tried to convert it?
     
    Social.Network, Jun 19, 2009 IP
  3. JavaPF

    JavaPF Member

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    JavaPF, Jun 24, 2009 IP