スキップしてメイン コンテンツに移動

投稿

ActionScript 3.0: Resize Image

Main flow part code. package utils.tool { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Loader; import flash.net.URLRequest; import flash.events.Event; import utils.ImageUtils; public class ImageResizer { private var maxW:int, maxH:int; private var smoothing:Boolean; private var saveFunction:Function; public function ImageResizer(maxW:int, maxH:int, smoothing:Boolean = false, type:String="jpg") { this.maxW = maxW; this.maxH = maxH; this.smoothing = smoothing; if (type === "png") { saveFunction = ImageUtils.saveBitmapDataAsPNGAsync; } else if(type === "jpg"){ saveFunction = ImageUtils.saveBitmapDataAsJPEGAsync; } else { throw new Error("Not Supported"); } }

ActionScript 3.0: Save BitmapData As JPEG or PNG

public static function saveBitmapDataAsJPEG(path:String, bitmapData:BitmapData, quality:Number=50.0):void { saveByteData(new JPEGEncoder(quality).encode(bitmapData), path); } public static function saveBitmapDataAsJPEGAsync(path:String, bitmapData:BitmapData, quality:Number=50.0):void { saveByteDataAsync(new JPEGEncoder(quality).encode(bitmapData), path); } public static function saveBitmapDataAsPNG(path:String, bitmapData:BitmapData):void { saveByteData(new PNGEncoder().encode(bitmapData), path); } public static function saveBitmapDataAsPNGAsync(path:String, bitmapData:BitmapData):void { saveByteDataAsync(new PNGEncoder().encode(bitmapData), path); } Here is my IO Utility methods. public static function saveByteData(data:ByteArray, path:String):void { try { var file:File = new File(path); var fs:FileStream = new FileStream(); fs.open(file, FileMode.WRITE); fs.writeBytes(data); fs.close(); } catch (err:IOError) { trace(err); } } public static function saveB

JavaのID3タグ解析ライブラリ

Javaでmp3ファイルのID3タグを解析するライブラリを色々と調べてみました。参考になれば幸いです。 以下に挙げていくコードは、特に意味のあることをしている訳ではありませんが、 どうやってタグの読み込み、書き換えを行えるかというサンプルとして参考にして頂ければと思います。 MyID3: a Java ID3 Tag Library import java.io.File; import java.io.IOException; import org.cmc.music.common.MusicMetadata; import org.cmc.music.myid3.MusicMetadataSet; import org.cmc.music.myid3.MyID3; /** * {@link http://www.fightingquaker.com/myid3/} */ public class MyID3Tester { public static void main(String[] args) throws IOException { File mp3File = new File("C:\\temp\\music.mp3"); MyID3 id3 = new MyID3(); MusicMetadataSet src_set = id3.read(mp3File); // read metadata if (src_set == null){ System.out.println("could not read data"); return; } // You can extract simplified information MusicMetadata metadata = src_set.getSimplified(); System.out.println(metadata.getArtist()); System.out.println(metadata.getAlbum()); // this doesn't work for me somehow :( System.out.println(metad

Java: Get Available Font on AWT environment

If you would like to check available font on Java environment, you should use this method. GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); The following code is utility class for Font. package com.dukesoftware.utils.common; import java.awt.Font; import java.awt.GraphicsEnvironment; import java.util.Arrays; public class FontUtils { public static void main(String[] args) { printAvailableFonts(); } public static void printAvailableFonts() { System.out.println(Arrays.toString(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames())); } public static boolean isAvailableFont(String font){ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final String[] fontNames = ge.getAvailableFontFamilyNames(); for(String name: fontNames){ if(name.equals(font)){ return true; } } return false;

Youtube API + GAEJ + FreeMarker + Spring

I have developed very very simple youtube sample application on Google App Engine. Internally I have used FreeMarker and Spring. The purpose of this blog entry is just giving hints how to use Spring + FreeMarker on GAEJ with youtube API example. Youtube API Here is the code for extracting video url etc from Youtube API response. I frequently use JDOM for parsing XML. package com.dukesoftware.gaej.youtube; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.Namespace; import org.jdom.input.SAXBuilder; import org.jdom.xpath.XPath; import com.dukesoftware.utils.io.JDOMUtils; import com.dukesoftware.utils.io.MinimumIOUtils; public class YouTube { private final static XPath XPATH_MEDIA; private final static Namespace NS_MEDIA = Namesp

C#: Download All Image Links from Html Page

I know this is not perfect way. But I would like to give hints to anyone who would like to download all links in html page. Example usage is something like this. // only download "jpg" files HttpUtils.SaveFirstLevelLinksToFile("", Encoding.UTF8, "c:/temp/", link => link => ".jpg".Equals(Path.GetExtension(link.Link), StringComparison.OrdinalIgnoreCase) ); Main code is below. // main entry point method public static void SaveFirstLevelLinksToFile(string baseUri, Encoding enc, string dir, Func<LinkAttr, bool> filter) { ProcessAllExtractedLinksInHtmlText(GetPage(baseUri, enc), link => { try { if (!filter(link)) return; Uri uri = ConvertToAbsoluteURL(baseUri, link.Link); var filePath = dir + uri.AbsoluteUri.GetFileName().Replace("?", ""); uri.AbsoluteUri.GetAndSaveToFile(filePath);

ActionScript 3.0: Loading Bytes from URL

I wrote a utility class for loading bytes from URL because the official method needs a lot of preparation. Here is the usage. var loader:ByteLoadHelper = new ByteLoadHelper(); loader.addEventListener(ByteLoadEvent.COMPLETE, completeHandler); loader.load(url); function completeHandler(evt:ByteLoadEvent):void { loader.removeEventListener(ByteLoadEvent.COMPLETE, completeHandler); var bytes:ByteArray = evt.data; // do something nice :D } Here is the core code. package utils.tool { import flash.events.Event; import flash.events.EventDispatcher; import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.net.URLRequest; import flash.utils.ByteArray; public class ByteLoadHelper extends EventDispatcher { public function ByteLoadHelper() { } public function load(url:String):void { var urlLoader:URLLoader = new URLLoader(); urlLoader.dataFormat = URLLoa