Creating Images with Mono / C#

I just wrote some sample code on how to create GIF images in C#:

using System;
using System.Drawing;
using System.Drawing.Imaging;


public class Tester {
  static void Main() {
    Bitmap bmp = new Bitmap(79,121);
    Graphics graph = Graphics.FromImage(bmp);
    Font font = new Font("Times", 6, FontStyle.Italic);

    for(int i=0; i<10000; i++) {
      graph.Clear(Color.White);
      graph.DrawString(i + " - Test", font, SystemBrushes.WindowText, 1, 1); 
      bmp.Save(i + "foo.gif", ImageFormat.Gif);
    }
  }
}

To compile that code you have to make an reference:

$ mcs -r:System.Drawing pic01.cs

To create 10.000 images takes about 12 seconds on my notebook. If you prefer PNG it takes a little bit longer ~ 26s.

Creating Windows EXE-Files under Linux

Sometimes a cross-compile environment can be very handy. Sam Lantinga form the libsdl.org project made a shell script (build-cross.sh) that makes it very easy to setup an GCC cross-compile environment for MinGW.

I used the follwing changes for the script:

  • GCC_VERSION=3.4.2-20040916-1
  • BINUTILS=binutils-2.15.91-20040904-1
  • MINGW=mingw-runtime-3.3
  • W32API=w32api-2.5

The EXE-files are a little bit large in size, but when you strip them the size is reduced drastically.

OC4J JSP Profiling with JProbe

I have done some Profiling with JProbe - hey I didn't know that you can download a Freeware Edition from Quest.

To get it working with Oracle OC4J 10g (Version 10.1.3) I used the following configuration:

  • Application Server Type: Other Server
  • Server Directory: toplevel directory where you installed OC4J (<install -dir>)
  • Server Class: oracle.oc4j.loader.boot.BootStrap
  • Class Path: <install -dir>/j2ee/home/oc4j.jar
  • Java Executable: /usr/java/j2sdk1.4.2_09/bin/java
  • Java Options: -DORACLE_HOME=<install -dir>
  • Working Directory: <install -dir>
  • Server Class Arguments: -config <install -dir>/j2ee/home/config/server.xml

I hope that helps to get you started with profiling. It is always a cool thing to see where the performance bottlenecks are buried inside of some piece of software. Sometimes some "improvements" make it worse when seeking to make it better :-D.

Having Fun with Bugs

Ups :-)
It is a little bit embarrassing, but software bugs can also happen to me. Bugs in web applications can lead to something like that showing up in search engine results:

error message in search engine

That error message was caused by an flaw on how I handled the
input from the HTTP Accept-Language line, if it was missing my code run into the above error.

So, that example proves one thing - it is very hard to review and audit your own code for flaws and security holes.