<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

    ?

    ????/**
    ?????*?Constant?to?specify?that?the?bounding?box?should?be?not?be?changed?
    ?????*?for?any?angle?of?rotation?when?creating?the?rotated?image.??This?
    ?????*?means?the?returned?image?will?be?the?same?size?as?the?given?image.??
    ?????*?Of?course,?that?also?means?the?corners?of?the?image?may?be?cut?off.??
    ?????
    */
    ????
    public?static?final?int?NO_BOUNDING_BOX?=?0;
    ?
    ????
    /**
    ?????*?Constant?to?specify?that?the?exact?bounding?box?should?be?used?for?
    ?????*?the?specified?angle?of?rotation?when?creating?the?rotated?image.??
    ?????*?This?is?the?default?option.??When?used,?the?rotated?image?may?be?
    ?????*?larger?then?the?source?image,?but?no?larger?then?needed?to?fit?the?
    ?????*?rotated?image?exactly.??Therefore,?rotating?the?same?image?to?various?
    ?????*?angles?may?result?in?varying?image?sizes.??
    ?????
    */
    ????
    public?static?final?int?EXACT_BOUNDING_BOX?=?1;
    ?
    ????
    /**
    ?????*?Constant?to?specify?that?the?largest?bounding?box?should?be?used?when?
    ?????*?creating?the?rotated?image.??When?used,?the?rotated?image?will?be?
    ?????*?larger?then?the?source?image,?but?all?rotated?images?of?that?same?
    ?????*?source?image?will?be?the?same?size,?regardless?of?the?angle?of?
    ?????*?rotation.??This?may?result?in?significant?"empty?space"?between?the?
    ?????*?edge?of?the?returned?image?and?the?actual?drawn?pixel?areas.??
    ?????
    */
    ????
    public?static?final?int?LARGEST_BOUNDING_BOX?=?2;


    ????
    /**
    ?????*?Rotates?the?specified?image?the?specified?number?of?degrees.??The?
    ?????*?rotation?is?performed?around?the?center?point?of?the?image.??
    ?????*?
    ?????*?
    @param??img?????????the?image?to?rotate
    ?????*?
    @param??degrees?????the?degrees?to?rotate
    ?????*?
    @param??bbm?????????the?bounding?box?mode,?default?is?EXACT_BOUNDING_BOX
    ?????*?
    @param??background??the?background?paint?(texture,?color?or?gradient),?
    ?????*?????????????????????can?be?null
    ?????*?
    @return??the?image
    ?????*?
    @see??#NO_BOUNDING_BOX
    ?????*?
    @see??#EXACT_BOUNDING_BOX
    ?????*?
    @see??#LARGEST_BOUNDING_BOX
    ?????
    */
    ????
    public?static?BufferedImage?rotateDegrees(Image?img,?double?degrees,?int?bbm,?Paint?background)?{
    ????????
    return?rotateRadians(img,?Math.toRadians(degrees),?bbm,?background);
    ????}
    ?
    ????
    /**
    ?????*?Rotates?the?specified?image?the?specified?number?of?radians.??The?
    ?????*?rotation?is?performed?around?the?center?point?of?the?image.??This?
    ?????*?method?is?provided?for?convenience?of?applications?using?radians.??
    ?????*?For?most?people,?degrees?is?simpler?to?use.??
    ?????*?
    ?????*?
    @param??img?????????the?image?to?rotate
    ?????*?
    @param??radians?????the?radians?to?rotate
    ?????*?
    @param??bbm?????????the?bounding?box?mode,?default?is?EXACT_BOUNDING_BOX
    ?????*?
    @param??background??the?background?paint?(texture,?color?or?gradient),?
    ?????*?????????????????????can?be?null
    ?????*?
    @return??the?image
    ?????*?
    @see??#NO_BOUNDING_BOX
    ?????*?
    @see??#EXACT_BOUNDING_BOX
    ?????*?
    @see??#LARGEST_BOUNDING_BOX
    ?????
    */
    ????
    public?static?BufferedImage?rotateRadians(Image?img,?double?radians,?int?bbm,?Paint?background)?{
    ????????
    //?get?the?original?image's?width?and?height
    ????????int?iw?=?img.getWidth(null);
    ????????
    int?ih?=?img.getHeight(null);
    ????????
    //?calculate?the?new?image's?size?based?on?bounding?box?mode
    ????????Dimension?dim;
    ????????
    if(bbm?==?NO_BOUNDING_BOX)?{
    ????????????dim?
    =?new?Dimension(iw,?ih);
    ????????}?
    else?if(bbm?==?LARGEST_BOUNDING_BOX)?{
    ????????????dim?
    =?getLargestBoundingBox(iw,?ih);
    ????????}?
    else?{?//?EXACT_BOUNDING_BOX
    ????????????dim?=?getBoundingBox(iw,?ih,?Math.toDegrees(radians));
    ????????}
    ????????
    //?get?the?new?image's?width?and?height
    ????????int?w?=?dim.width;
    ????????
    int?h?=?dim.height;
    ????????
    //?get?the?location?to?draw?the?original?image?on?the?new?image
    ????????int?x?=?(w/2)-(iw/2);
    ????????
    int?y?=?(h/2)-(ih/2);
    ????????
    //?need?to?copy?the?given?image?to?a?new?BufferedImage?because?
    ????????
    //?it?is,?in?most?cases,?going?to?be?a?larger?image?so?it?
    ????????
    //?needs?to?be?drawn?centered?on?the?larger?image
    ????????BufferedImage?bi?=?new?BufferedImage(w,?h,?BufferedImage.TYPE_INT_ARGB);
    ????????Graphics2D?g2d?
    =?bi.createGraphics();
    ????????
    //?set?some?rendering?hints?for?better?looking?images
    ????????g2d.setRenderingHints(renderingHints);
    ????????
    //?draw?the?background?paint,?if?necessary
    ????????if(background?!=?null)?{
    ????????????g2d.setPaint(background);
    ????????????g2d.fillRect(
    0,?0,?w,?h);
    ????????}
    ????????
    //?if?not?rotating,?just?draw?it?normally,?else?create?a?transform
    ????????if(radians?==?0.0)?{
    ????????????g2d.drawImage(img,?x,?y,?iw,?ih,?
    null);
    ????????}?
    else?{
    ????????????g2d.rotate(radians,?w
    /2,?h/2);
    ????????????g2d.translate(x,?y);
    ????????????g2d.drawImage(img,?
    0,?0,?iw,?ih,?null);
    ????????}
    ????????g2d.dispose();
    ????????
    return?bi;
    ????}
    ?
    ????
    /**
    ?????*?Gets?the?largest?bounding?box?size?that?can?hold?an?image?of?the?
    ?????*?specified?size?at?any?angle?of?rotation.??
    ?????*?
    ?????*?
    @param??width???the?image?width
    ?????*?
    @param??height??the?image?height
    ?????*?
    @return??the?bounding?box?size
    ?????
    */
    ????
    public?static?Dimension?getLargestBoundingBox(int?width,?int?height)?{
    ????????
    //?The?largest?bounding?box?is?the?largest?area?needed?to?fit?the?
    ????????
    //?specified?image?at?any?angle?or?rotation.??This?is?simpler?then?
    ????????
    //?getting?the?bounding?box?for?a?given?angle?because?the?largest?
    ????????
    //?box?will?put?the?corner?of?the?image?box?directly?along?the?
    ????????
    //?vertical?or?horizontal?axis?from?the?image?center?point.??The?
    ????????
    //?distance?between?the?image?rectangle's?center?and?any?corner?
    ????????
    //?is?the?hypotenuse?of?a?right?triangle?who's?other?sides?are?
    ????????
    //?half?the?width?(a)?and?half?the?height?(b)?of?the?rectangle.??
    ????????
    //?A?little?a^2?+?b^2?=?c^2?calculation?and?we?get?the?length?of?
    ????????
    //?the?hypotenuse.??Double?that?to?get?a?square?within?which?the?
    ????????
    //?image?can?be?rotated?at?any?angle?without?clipping?the?image.??
    ????????double?a?=?(double)width?/?2.0;
    ????????
    double?b?=?(double)height?/?2.0;
    ????????
    //?use?Math.ceil()?to?round?up?to?an?int?value
    ????????int?c?=?(int)Math.ceil(Math.sqrt((a?*?a)?+?(b?*?b))?*?2.0);
    ????????
    return?new?Dimension(c,?c);
    ????}
    ?
    ????
    /**
    ?????*?Gets?the?optimal/smallest?bounding?box?size?that?can?hold?an?image?of?
    ?????*?the?specified?size?at?the?specified?angle?of?rotation.??
    ?????*?
    ?????*?
    @param??width???the?image?width
    ?????*?
    @param??height??the?image?height
    ?????*?
    @return??the?bounding?box?size
    ?????
    */
    ????
    public?static?Dimension?getBoundingBox(int?width,?int?height,?double?degrees)?{
    ????????degrees?
    =?normalizeDegrees(degrees);
    ????????
    //?if?no?rotation?or?180?degrees,?the?size?won't?change
    ????????if(degrees?==?0.0?||?degrees?==?180.0)?{
    ????????????
    return?new?Dimension(width,?height);
    ????????}
    ????????
    //?if?90?or?270?(quarter?or?3-quarter?rotations)?the?width?becomes?
    ????????
    //?the?height,?and?vice?versa
    ????????if(degrees?==?90.0?||?degrees?==?270.0)?{
    ????????????
    return?new?Dimension(height,?width);
    ????????}
    ????????
    //?for?any?other?rotation,?we?need?to?do?some?trigonometry,?
    ????????
    //?derived?from?description?found?at:??
    ????????
    //?http://www.codeproject.com/csharp/rotateimage.asp
    ????????double?radians?=?Math.toRadians(degrees);
    ????????
    double?aW?=?Math.abs(Math.cos(radians)?*?width);
    ????????
    double?oW?=?Math.abs(Math.sin(radians)?*?width);
    ????????
    double?aH?=?Math.abs(Math.cos(radians)?*?height);
    ????????
    double?oH?=?Math.abs(Math.sin(radians)?*?height);
    ????????
    //?use?Math.ceil()?to?round?up?to?an?int?value
    ????????int?w?=?(int)Math.ceil(aW?+?oH);
    ????????
    int?h?=?(int)Math.ceil(oW?+?aH);
    ????????
    return?new?Dimension(w,?h);
    ????}
    posted on 2005-09-22 07:26 Pudgy's World 閱讀(277) 評論(0)  編輯  收藏 所屬分類: Computer

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


    網站導航:
     

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

    常用鏈接

    留言簿(1)

    隨筆分類(13)

    隨筆檔案(13)

    文章分類(4)

    文章檔案(5)

    相冊

    Developer

    Favorite blogs

    搜索

    •  

    積分與排名

    • 積分 - 22409
    • 排名 - 1627

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 一本久久免费视频| 亚洲国产美女精品久久久久∴| 最近最新MV在线观看免费高清| 男女午夜24式免费视频| 韩日电影在线播放免费版| 羞羞视频免费网站日本| 免费一级特黄特色大片| 日本一区二区在线免费观看| 美女羞羞免费视频网站| 特级毛片aaaa免费观看| 国产免费内射又粗又爽密桃视频 | 超pen个人视频国产免费观看| 日本三级2019在线观看免费| 中文字幕乱码免费视频| 成人免费午夜在线观看| 在线看片人成视频免费无遮挡| 免费毛片在线播放| 国产亚洲福利一区二区免费看| 免费中文字幕在线| 久久久久亚洲精品天堂久久久久久 | 男人的天堂av亚洲一区2区| 久久久久亚洲精品无码网址色欲 | 亚洲天堂2016| 亚洲精品国产综合久久久久紧| 亚洲Av永久无码精品一区二区| 粉色视频在线观看www免费| 国产精品福利在线观看免费不卡| 永久免费av无码入口国语片| 久久精品无码专区免费青青| 免费看黄视频网站| 国产jizzjizz免费视频| 亚洲永久无码3D动漫一区| 亚洲专区先锋影音| 亚洲小说图区综合在线| 四虎国产精品永免费| 国内精品久久久久影院免费 | sihu国产精品永久免费| 久久久久免费精品国产小说| 久久WWW免费人成人片| 亚洲AV永久无码精品一区二区国产| 精品国产_亚洲人成在线高清|