Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #28062
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news.netfront.net!not-for-mail |
|---|---|
| From | Wanja Gayk <brixomatic@yahoo.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Mirror an image |
| Date | Sun, 13 Apr 2014 15:57:03 +0200 |
| Organization | Netfront http://www.netfront.net/ |
| Lines | 78 |
| Message-ID | <MPG.2db4b6049cca8fca19@202.177.16.121> (permalink) |
| References | <2299213c-18fc-4e55-ab39-22dce863b255@googlegroups.com> <jt2mj9t2uv0jdos76t4otlb8lgfoc1udnn@4ax.com> <MPG.2da540be1aa5795117@202.177.16.121> <lhsj1p$i60$1@dont-email.me> |
| NNTP-Posting-Host | 77.176.13.191 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="us-ascii" |
| Content-Transfer-Encoding | 7bit |
| X-Trace | adenine.netfront.net 1397397395 50299 77.176.13.191 (13 Apr 2014 13:56:35 GMT) |
| X-Complaints-To | news@netfront.net |
| NNTP-Posting-Date | Sun, 13 Apr 2014 13:56:35 +0000 (UTC) |
| User-Agent | MicroPlanet-Gravity/3.0.4 |
| Xref | csiph.com comp.lang.java.programmer:28062 |
Show key headers only | View raw
In article <lhsj1p$i60$1@dont-email.me>, Jeff Higgins
(jeff@invalid.invalid) says...
>
> On 04/06/2014 02:18 PM, Wanja Gayk wrote:
> > Without any test, this would be my first, rough idea:
> > Have fun.
>
> Thanks.
> Here's another, not exactly per my first post
> but the must be 25 ways of doing this task.
>
> package scratch;
>
> import java.awt.Dimension;
> import java.awt.Graphics;
> import java.awt.Graphics2D;
> import java.awt.geom.AffineTransform;
> import java.awt.image.BufferedImage;
> import java.io.File;
> import java.io.IOException;
>
> import javax.imageio.ImageIO;
> import javax.swing.JComponent;
> import javax.swing.JFrame;
> import javax.swing.JScrollPane;
>
> @SuppressWarnings("serial")
> public class Scratch extends JComponent {
>
> private BufferedImage image;
//you don't need to store the width and the height here, just get it
//again in the paint method.
//the less variables/fields you have to track in your mind the code, the
//better you will be able to read it later.
> private int width, height;
>
> public Scratch() {
> try {
> image = ImageIO.read(new File("/path/to/image"));
> width = image.getWidth();
> height = image.getHeight();
> setPreferredSize(new Dimension(width, 2 * height));
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
> @Override
> protected void paintComponent(Graphics g) {
> super.paintComponent(g);
> Graphics2D g2d = (Graphics2D) g;
> AffineTransform restore = g2d.getTransform();
//you should set a clip here, so you don't need to paint the image in
//full height.
> g2d.drawRenderedImage(image, null);
> g2d.translate(0, 2 * height);
> g2d.scale(1, -1);
> g2d.drawRenderedImage(image, null);
> g2d.setTransform(restore);
> }
//note: using g.drawImage(img, x,y,w,h,.. ) you could
//automatically scale the image to the panel size, which may come handy.
Kind regards,
Wanja
--
..Alesi's problem was that the back of the car was jumping up and down
dangerously - and I can assure you from having been teammate to
Jean Alesi and knowing what kind of cars that he can pull up with,
when Jean Alesi says that a car is dangerous - it is. [Jonathan Palmer]
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Mirror an image pgmbento93@gmail.com - 2014-04-01 07:44 -0700
Re: Mirror an image Jeff Higgins <jeff@invalid.invalid> - 2014-04-01 11:09 -0400
Re: Mirror an image Jeff Higgins <jeff@invalid.invalid> - 2014-04-01 11:15 -0400
Re: Mirror an image Roedy Green <see_website@mindprod.com.invalid> - 2014-04-01 11:56 -0700
Re: Mirror an image Wanja Gayk <brixomatic@yahoo.com> - 2014-04-06 20:18 +0200
Re: Mirror an image Jeff Higgins <jeff@invalid.invalid> - 2014-04-06 18:01 -0400
Re: Mirror an image Wanja Gayk <brixomatic@yahoo.com> - 2014-04-13 15:57 +0200
Re: Mirror an image Jeff Higgins <jeff@invalid.invalid> - 2014-04-13 10:21 -0400
csiph-web