<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Branberyheag!! Lab &#187; 縦横比</title>
	<atom:link href="http://lab.branberyheag.com/tag/%e7%b8%a6%e6%a8%aa%e6%af%94/feed" rel="self" type="application/rss+xml" />
	<link>http://lab.branberyheag.com</link>
	<description>ActionScript3.0やJavascriptを使っていろんなものを作ってみます。</description>
	<lastBuildDate>Fri, 03 Feb 2012 06:28:02 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom:link rel='hub' href='http://lab.branberyheag.com/?pushpress=hub'/>
		<item>
		<title>外部から読み込んだ画像の縦横比を維持して縮小する方法</title>
		<link>http://lab.branberyheag.com/2009/08/28/%e5%a4%96%e9%83%a8%e3%81%8b%e3%82%89%e8%aa%ad%e3%81%bf%e8%be%bc%e3%82%93%e3%81%a0%e7%94%bb%e5%83%8f%e3%81%ae%e7%b8%a6%e6%a8%aa%e6%af%94%e3%82%92%e7%b6%ad%e6%8c%81%e3%81%97%e3%81%a6%e7%b8%ae%e5%b0%8f.html</link>
		<comments>http://lab.branberyheag.com/2009/08/28/%e5%a4%96%e9%83%a8%e3%81%8b%e3%82%89%e8%aa%ad%e3%81%bf%e8%be%bc%e3%82%93%e3%81%a0%e7%94%bb%e5%83%8f%e3%81%ae%e7%b8%a6%e6%a8%aa%e6%af%94%e3%82%92%e7%b6%ad%e6%8c%81%e3%81%97%e3%81%a6%e7%b8%ae%e5%b0%8f.html#comments</comments>
		<pubDate>Fri, 28 Aug 2009 14:45:59 +0000</pubDate>
		<dc:creator>isao</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[縦横比]]></category>

		<guid isPermaLink="false">http://lab.branberyheag.com/?p=269</guid>
		<description><![CDATA[JavaScriptやActionScript3でも外部から読み込んだ画像の縦横比を維持して拡大・縮小をしたもの。今までこれにずっとつまずいていた。今、作っているものもちょっと、この縦横比を維持して縮小をしたかった。いろ [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScriptやActionScript3でも外部から読み込んだ画像の縦横比を維持して拡大・縮小をしたもの。今までこれにずっとつまずいていた。今、作っているものもちょっと、この縦横比を維持して縮小をしたかった。いろいろ調べてみたら、考え方が書いてあったので紹介したい。</p>
<p>縦横比を求めるには、縦の長さ / 横の長さ で比率が求められる。<br />
これを横をたとえば200pxにしたいとすると・・・縦の長さを横の長さに対して求めればいいと思う。</p>
<p>横の長さを基準にして縦の長さを求めると<br />
横の長さx上で求めた縦横比 = 横を200pxにしたときの縦の長さ</p>
<p>例）ActionScriptで記述すると</p>
<pre class="brush: jscript; title: ; notranslate">
 // 変数 hpw に 「高さ/横幅」 の比を取得
 var hpw:Number = photoFrame._height/photoFrame._width;
 // もし横幅が120より大きい場合
 if (photoFrame._width&gt;120) {
 // 横幅を120にする
 photoFrame._width = 120;
 // そして高さもその比に合わせて変える
 photoFrame._height = 120*hpw;
 }
 // 上の縮小をしても(しなくても)まだ高さが160より大きい場合
 if (photoFrame._height&gt;160) {
 // 高さを160にする
 photoFrame._height = 160;
 // そして横幅もその比に合わせて変える
 photoFrame._width = 160/hpw;
 }
 </pre>
<p><span>変形しないように画像を表示するときに役に立つと思う。<br />
これだけクラスファイルにするのも手だと思う。<br />
</span><strong>関連した記事</strong>
<ul class="similar-posts">
<li><a href="http://lab.branberyheag.com/2011/05/19/javascript%e3%81%ae%e9%85%8d%e5%88%97%e3%82%92%e7%a9%ba%e3%81%ab%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95.html" rel="bookmark" title="2011年5月19日">Javascriptの配列を空にする方法</a></li>
<li><a href="http://lab.branberyheag.com/2010/06/07/css_sprites_overflow.html" rel="bookmark" title="2010年6月7日">背景画像を使用しないCSSスプライト</a></li>
<li><a href="http://lab.branberyheag.com/2011/04/23/dd_belatedpng%e3%81%8c%e8%83%8c%e6%99%af%e3%81%8c%e9%81%95%e3%81%86%e4%bd%8d%e7%bd%ae%e3%81%ab%e3%81%aa%e3%81%a3%e3%81%a6%e3%81%97%e3%81%be%e3%81%a3%e3%81%9f%e3%80%82.html" rel="bookmark" title="2011年4月23日">DD_belatedPNGが背景が違う位置になってしまった。</a></li>
<li><a href="http://lab.branberyheag.com/2011/03/30/window%e3%81%ae%e4%b8%80%e7%95%aa%e4%b8%8b%e3%81%be%e3%81%a7%e3%82%b9%e3%82%af%e3%83%ad%e3%83%bc%e3%83%ab%e3%81%95%e3%82%8c%e3%81%9f%e3%81%93%e3%81%a8%e3%82%92%e5%8f%96%e5%be%97%e3%81%99%e3%82%8b.html" rel="bookmark" title="2011年3月30日">Windowの一番下までスクロールされたことを取得する方法</a></li>
<li><a href="http://lab.branberyheag.com/2010/01/11/sukinabasho.html" rel="bookmark" title="2010年1月11日">コミュニティサイト「すきなばしょ」プレリリース</a></li>
</ul>
<p><!-- Similar Posts took 3.788 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://lab.branberyheag.com/2009/08/28/%e5%a4%96%e9%83%a8%e3%81%8b%e3%82%89%e8%aa%ad%e3%81%bf%e8%be%bc%e3%82%93%e3%81%a0%e7%94%bb%e5%83%8f%e3%81%ae%e7%b8%a6%e6%a8%aa%e6%af%94%e3%82%92%e7%b6%ad%e6%8c%81%e3%81%97%e3%81%a6%e7%b8%ae%e5%b0%8f.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

