<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Pudgy's World
    posts - 13,  comments - 16,  trackbacks - 0

    ?Rotate Image 45 Degrees

    ?


    /*

    Java?Media?APIs:?Cross-Platform?Imaging,?Media?and?Visualization
    Alejandro?Terrazas
    Sams,?Published?November?2002,?
    ISBN?0672320940
    */


    import?java.awt.Graphics;
    import?java.awt.Graphics2D;
    import?java.awt.Image;
    import?java.awt.Insets;
    import?java.awt.MediaTracker;
    import?java.awt.Toolkit;
    import?java.awt.geom.AffineTransform;
    import?java.awt.geom.Point2D;
    import?java.awt.image.AffineTransformOp;
    import?java.awt.image.BufferedImage;
    import?java.awt.image.BufferedImageOp;

    import?javax.swing.JFrame;

    /**
    ?*?RotateImage45Degrees.java?-?1.?scales?an?image's?dimensions?by?a?factor?of
    ?*?two?2.?rotates?it?45?degrees?around?the?image?center?3.?displays?the
    ?*?processed?image
    ?
    */
    public?class?RotateImage45Degrees?extends?JFrame?{
    ??
    private?Image?inputImage;

    ??
    private?BufferedImage?sourceBI;

    ??
    private?BufferedImage?destinationBI?=?null;

    ??
    private?Insets?frameInsets;

    ??
    private?boolean?sizeSet?=?false;

    ??
    public?RotateImage45Degrees(String?imageFile)?{
    ????addNotify();
    ????frameInsets?
    =?getInsets();
    ????inputImage?
    =?Toolkit.getDefaultToolkit().getImage(imageFile);

    ????MediaTracker?mt?
    =?new?MediaTracker(this);
    ????mt.addImage(inputImage,?
    0);
    ????
    try?{
    ??????mt.waitForID(
    0);
    ????}?
    catch?(InterruptedException?ie)?{
    ????}

    ????sourceBI?
    =?new?BufferedImage(inputImage.getWidth(null),?inputImage
    ????????.getHeight(
    null),?BufferedImage.TYPE_INT_ARGB);

    ????Graphics2D?g?
    =?(Graphics2D)?sourceBI.getGraphics();
    ????g.drawImage(inputImage,?
    0,?0,?null);

    ????AffineTransform?at?
    =?new?AffineTransform();

    ????
    //?scale?image
    ????at.scale(2.0,?2.0);

    ????
    //?rotate?45?degrees?around?image?center
    ????at.rotate(45.0?*?Math.PI?/?180.0,?sourceBI.getWidth()?/?2.0,?sourceBI
    ????????.getHeight()?
    /?2.0);

    ????
    /*
    ?????*?translate?to?make?sure?the?rotation?doesn't?cut?off?any?image?data
    ?????
    */
    ????AffineTransform?translationTransform;
    ????translationTransform?
    =?findTranslation(at,?sourceBI);
    ????at.preConcatenate(translationTransform);

    ????
    //?instantiate?and?apply?affine?transformation?filter
    ????BufferedImageOp?bio;
    ????bio?
    =?new?AffineTransformOp(at,?AffineTransformOp.TYPE_BILINEAR);

    ????destinationBI?
    =?bio.filter(sourceBI,?null);

    ????
    int?frameInsetsHorizontal?=?frameInsets.right?+?frameInsets.left;
    ????
    int?frameInsetsVertical?=?frameInsets.top?+?frameInsets.bottom;
    ????setSize(destinationBI.getWidth()?
    +?frameInsetsHorizontal,?destinationBI
    ????????.getHeight()
    ????????
    +?frameInsetsVertical);
    ????show();
    ??}

    ??
    /*
    ???*?find?proper?translations?to?keep?rotated?image?correctly?displayed
    ???
    */
    ??
    private?AffineTransform?findTranslation(AffineTransform?at,?BufferedImage?bi)?{
    ????Point2D?p2din,?p2dout;

    ????p2din?
    =?new?Point2D.Double(0.0,?0.0);
    ????p2dout?
    =?at.transform(p2din,?null);
    ????
    double?ytrans?=?p2dout.getY();

    ????p2din?
    =?new?Point2D.Double(0,?bi.getHeight());
    ????p2dout?
    =?at.transform(p2din,?null);
    ????
    double?xtrans?=?p2dout.getX();

    ????AffineTransform?tat?
    =?new?AffineTransform();
    ????tat.translate(
    -xtrans,?-ytrans);
    ????
    return?tat;
    ??}

    ??
    public?void?paint(Graphics?g)?{
    ????
    if?(destinationBI?!=?null)
    ??????g.drawImage(destinationBI,?frameInsets.left,?frameInsets.top,?
    this);
    ??}

    ??
    public?static?void?main(String[]?args)?{
    ????
    new?RotateImage45Degrees("fruits.png");
    ??}

    }

    ?

    posted on 2005-09-22 07:23 Pudgy's World 閱讀(451) 評論(0)  編輯  收藏 所屬分類: Computer

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(1)

    隨筆分類(13)

    隨筆檔案(13)

    文章分類(4)

    文章檔案(5)

    相冊

    Developer

    Favorite blogs

    搜索

    •  

    積分與排名

    • 積分 - 22381
    • 排名 - 1627

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲免费综合色在线视频| 成人毛片100免费观看| 久久午夜夜伦鲁鲁片免费无码影视| yy6080亚洲一级理论| 特级av毛片免费观看| 国产一级一片免费播放| 亚洲色偷偷偷综合网| 破了亲妺妺的处免费视频国产| 亚洲精品123区在线观看| 成年女人免费碰碰视频| 亚洲欧美日韩综合俺去了| 啦啦啦高清视频在线观看免费 | 国产综合精品久久亚洲| h视频在线免费观看| 亚洲人色婷婷成人网站在线观看| 国产免费一区二区三区免费视频| 亚洲中文字幕在线第六区| 国产日韩一区二区三免费高清| 亚洲av无码成h人动漫无遮挡| 在线观看的免费网站无遮挡| 亚洲视频一区网站| 午夜免费福利影院| 男人j进女人p免费视频| 亚洲精品二区国产综合野狼| 久久久久国产精品免费看| 亚洲精品在线免费看| 在线不卡免费视频| 一区二区三区免费视频观看| 亚洲成在人天堂在线| 女人张腿给男人桶视频免费版 | 一级成人a免费视频| 国产AV无码专区亚洲AV毛网站 | 成人免费视频国产| 精品国产污污免费网站入口| 亚洲人成在线观看| 爽爽日本在线视频免费| 中国一级特黄高清免费的大片中国一级黄色片 | 午夜dj在线观看免费视频| 麻豆91免费视频| 久久夜色精品国产噜噜亚洲AV| 最新中文字幕电影免费观看|