<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 閱讀(275) 評論(0)  編輯  收藏 所屬分類: Computer

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


    網站導航:
     

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

    常用鏈接

    留言簿(1)

    隨筆分類(13)

    隨筆檔案(13)

    文章分類(4)

    文章檔案(5)

    相冊

    Developer

    Favorite blogs

    搜索

    •  

    積分與排名

    • 積分 - 22385
    • 排名 - 1627

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲线精品一区二区三区影音先锋 | 亚洲精品第一国产综合境外资源| 精品久久久久久亚洲精品| 少妇人妻偷人精品免费视频| 亚洲va久久久噜噜噜久久狠狠| 在线观看肉片AV网站免费| 亚洲午夜久久久久久噜噜噜| 国产在线精品观看免费观看| 久久久久亚洲精品中文字幕 | 久久久久久亚洲精品成人| 色欲国产麻豆一精品一AV一免费| 亚洲日本中文字幕| 日本zzzzwww大片免费| 亚洲国产精品乱码在线观看97| 国色精品卡一卡2卡3卡4卡免费| 久久久久精品国产亚洲AV无码| 成人一a毛片免费视频| 亚洲欧美国产国产综合一区| 国产免费av片在线无码免费看| 日本黄页网址在线看免费不卡| 国产亚洲精品福利在线无卡一| 日韩免费在线视频| 亚洲伊人久久大香线蕉结合| 免费羞羞视频网站| a级毛片免费网站| 久久精品国产亚洲av高清漫画| 99热在线精品免费全部my| 亚洲成a人片在线不卡一二三区| 亚洲精品国精品久久99热| A片在线免费观看| 亚洲乱人伦精品图片| 全免费一级毛片在线播放| 国产免费久久精品99久久| 久久亚洲精品中文字幕| 午夜神器成在线人成在线人免费| 九九全国免费视频| 亚洲专区一路线二| 久久亚洲AV无码西西人体| 曰曰鲁夜夜免费播放视频 | 又粗又硬免费毛片| 国产精品99久久免费观看|