Victor Image Processing Library How-to Tips

Load and View a BMP Using Java



This example loads a BMP image and displays it on the screen. The sequence of Victor Library function calls used is:
            bmpinfo        to get dimensions and pixel depth of the image file
            allocimage     to allocate an image buffer to hold the image
            loadbmp        to load the image into memory
            viewimageex    to display the image
            freeimage      to release the memory used by the image buffer
Using Victor Library functions in Java is identical to using them in C but you must add the prefix "vic.vic32jni." to each function and defined constant.

To make it easy to use Windows the Victor Java Native Interface, "vic." includes functions for getting Window and device context handles.

Load and View a BMP

Requires Victor Image Processing Library v 5.3 or higher, the Victor Java Native Interface vic.zip and Java 2.

Place the dlls:

vic32.dll in x:\java\bin
victw32.dll in x:\java\bin
vic32jni.dll in the same subdirectory as the application

To compile and run bmp2jpeg.class:

javac -classpath x:\java bmpviewer.java
java -classpath x:\java;x:\java\vic bmpviewer

 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
import vic.*;
/*
   javac -classpath e:\java bmpviewer.java
   java -classpath e:\java;e:\java\vic bmpviewer
*/
class bmpviewer {
   public static void main(String args[]) {
   String loadfilename;
   int rcode = 0; 
   vic.imgdes timage = new vic.imgdes();
   vic.BITMAPINFOHEADER filedata = new vic.BITMAPINFOHEADER();
   rcode = vic.vic32jni.enableunicode(1);  // Turn on Unicode if available
            // load bmp 
   loadfilename = "test.bmp";
   rcode = vic.vic32jni.bmpinfo(loadfilename, filedata);
   if(rcode == vic.vic32jni.NO_ERROR) {
      rcode = vic.vic32jni.allocimage(timage, filedata.biWidth, filedata.biHeight, (int)filedata.biBitCount);
      if(rcode == vic.vic32jni.NO_ERROR) {
         System.out.println("Allocation successful, loading bmp file");
         System.out.println("  image width in pixels = " + filedata.biWidth);
         System.out.println("  image length in pixels = " + filedata.biHeight);
         System.out.println("  buffer width in bytes = " + timage.buffwidth);
         rcode = vic.vic32jni.loadbmp(loadfilename, timage);
         if(rcode == vic.vic32jni.NO_ERROR) {
            int hwnd, hdc;
            int scrnx, scrny;
            vic.refvar hpal = new vic.refvar();
            hwnd = vic.vic32jni.GetActiveWindow();
            hdc = vic.vic32jni.GetDC(hwnd);
            scrnx = 0;
            scrny = 0;
            rcode = vic.vic32jni.viewimageex(hwnd, hdc, hpal, 0, 0, timage, scrnx, scrny, vic.vic32jni.VIEWOPTPAL);
            if(hpal.value > 0)
               vic.vic32jni.DeleteObject(hpal.value);
            vic.vic32jni.ReleaseDC(hwnd, hdc);
            System.out.println(" hwnd = " + hwnd + " hdc = " + hdc + " hpal = " + hpal.value);
            System.out.println("  viewimage rcode = " + rcode );
            }
         vic.vic32jni.freeimage(timage);
         }
      }
   } // end of main()
} // end of class
Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code




Copyright © 2001 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.