2012年3月14日水曜日

少しのコードで実装可能な15のスマートフォンサイト用小技集

少しのコードで実装可能な15のスマートフォンサイト用小技集
http://www.webcreatorbox.com/tech/smartphone-snippets/

The 50 smartest people in tech

http://tech.fortune.cnn.com/2010/07/09/the-50-smartest-people-in-tech/

What constitutes tech savvy today? An alchemy of intellect, ambition, and that uncanny ability to peer around corners. Some of our choices may surprise you.
By Jessi Hempel and Beth Kowitt
"The empires of the future," Winston Churchill once said, "are the empires of the mind." Those words have never held more weight. Our greatest technological advances come not through physical might, tools, or cash but through intellect and imagination. As Fortune gets set to acknowledge these advances at our annual Brainstorm Tech conference in Aspen (July 22–24), we think it only fitting to introduce you to 50 of the field's brawniest brains. These are the people whose collective intelligence propels us into a future that looks nothing like the present. They've dreamed up phones that let us surf the Net, websites that help us feel more connected, and movie characters who step off the screen.
So what do we mean by smart? We salute intelligence, but also impact. Accel partner Jim Breyer is a bright guy, but he is worthy of inclusion on Fortune's list because he applies his mind to investments that have the potential to change lives -- or at least lifestyles. We're most concerned with the present. Thus, you won't find the Polish polymath Nicolaus Copernicus on our list, nor will you find Bill Gates. And this is not a ranking based on pure IQ. In the ecosystem that leads to commercializing technological advances, thoughtful business executives are just as important as engineering geniuses.

2012年3月2日金曜日

Word文書のプレビュー画像を取得する方法

Word文書のプレビュー画像を取得する方法

>XPS形式

開発環境がVS2003とOffice2003のようなのであげてなかったんですが、以下のようなソースでXPSからビットマップが得られます。
#WPFが要るのでVS2003だけで画像にするのは無理かと

この方法だとXPSに出力できればEXCELでもWORDでも画像が得られます。
ただ、そのXPSを出力するのにMicrosoft XPS Document Writerへファイル印刷させる必要があります。
これはActivePrinterをMicrosoft XPS Document WriterにしてやればXPSファイルが得られます。

Word97で試しても印刷をファイル出力先を指定できるので割と簡単に実現
Excel2000以降ではPrintOutにファイル指定できるので簡単です。Excel97ではファイル出力先指定が面倒でした…
#Word/EXCELの操作は面倒なのでVB.NETを使用

using System;
using System.Collections.Generic;
using System.Windows.Xps.Packaging; //ReachFramework
using System.Windows.Xps; //ReachFramework
using System.Windows.Documents; //PresentationCore
using System.Windows; //WindowBase
using System.Windows.Media.Imaging;//PresentationCore

namespace XPS
{
internal static class XPSTool
{
public static SortedList GetBitmaps(string xpsPath)
{
return GetBitmaps(xpsPath, null, false);
}
public static SortedList GetBitmaps(string xpsPath, IEnumerable pages)
{
return GetBitmaps(xpsPath, pages, false);
}

/// XPSファイルのページを画像にして取得
/// XPSファイルへのパス
/// 取得したいページのリスト nullで全ページ
/// true:変換エラーで打ち切るか false:エラー
///
public static SortedList GetBitmaps(string xpsPath, IEnumerable pages, bool breakPageError)
{
SortedList list = new SortedList();

try
{
using (XpsDocument xpsDoc = new XpsDocument(xpsPath, System.IO.FileAccess.Read))
{
FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
DocumentReferenceCollection drc = docSeq.References;

foreach (DocumentReference dr in drc)
{
FixedDocument fixdoc = dr.GetDocument(false);
if (pages == null)
{
int pageCount = docSeq.DocumentPaginator.PageCount;
for (int page = 0; page < pageCount; page++)
{
FixedPage fixedPage = (FixedPage)docSeq.DocumentPaginator.GetPage(page).Visual;
list.Add(page, TranslateBitmap(fixedPage));
}
}
else
{
foreach (int page in pages)
{
FixedPage fixedPage = (FixedPage)fixdoc.DocumentPaginator.GetPage(page).Visual; ;
list.Add(page, TranslateBitmap(fixedPage));
}
}
}
}
}
catch
{
if (!breakPageError)
{
throw;
}
}
return list;
}

/// 描画状態が固定されているページをPNGに変換
private static System.Drawing.Bitmap TranslateBitmap(FixedPage fixedPage)
{
System.Drawing.Bitmap bmp = null;
double width;
double height;
width = fixedPage.Width;
height = fixedPage.Height;

System.Windows.Size size = new System.Windows.Size(width, height);
fixedPage.Measure(size);
fixedPage.Arrange(new System.Windows.Rect(new System.Windows.Point(), size));
fixedPage.UpdateLayout();

BitmapImage bmpimage = new System.Windows.Media.Imaging.BitmapImage();

//96dpiが基本?
RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, System.Windows.Media.PixelFormats.Default);

renderTarget.Render(fixedPage);

BitmapEncoder encoder = new PngBitmapEncoder();
BitmapFrame frame = BitmapFrame.Create(renderTarget);
encoder.Frames.Add(frame);

using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
encoder.Save(ms);
ms.Position = 0;
bmp = new System.Drawing.Bitmap(ms);
}
return bmp;
}
}
}

Javascriptでflash playerのバージョン判別( Webサイト「0から目指すWebマスター」)

Javascriptでflash playerのバージョン判別( Webサイト「0から目指すWebマスター」)