Victor Image Processing Library How-to Tips

Add .Net Graphics to a Victor Image

This is pic1.tif loaded as a Victor image and displayed as a .Net bitmap.

Add a .NET graphic element




Apply a Victor Image Processing function




Reload original image


The Victor Library gives the web .ASPX developer and the desktop .Net developer the advantages of speed, small size, and ease of use when creating an application to modify or analyze images. But sometimes the developer has a specific need that requires the addition of graphic elements that are part of the .Net framework.

Only a few simple steps are needed to add these graphic elements. A typical sequence is:

This image can now accessed both by Victor Library functions and by .Net functions.

In this example we load a tiff into a Victor image then create a .Net bitmap in the image. The buttons trigger the addition of simple .Net graphic elements or application of Victor image processing. Each of the buttons generates a call to the process function which selects the action to apply to the image.

For an introduction to creating online applications using the Victor Library see the application note Creating an ASP.NET Online Image Processing Application




VB.NET Source Code | Web Form Source Code | Entire App Source Code


Adding Graphics to an Image - the ASPX VB.NET Source Code

Requires Victor Image Processing Library 5.6 or higher, commercial release or eval copy.
Sub process (s as Object, e as Eventargs)
' .NET objects
dim bm as bitmap
dim g1 as graphics
dim bitmapbuff as system.intptr
dim format as pixelformat
Dim drawFont As New Font("Arial", 16)

' Conventional variables
dim rcode as integer
dim width as integer
dim length as integer
dim bpp as integer
dim bmh as  BITMAPINFOHEADER
dim action_requested as string

	' Get bitmapinfoheader from myimage, the Victor image descriptor
	getbmhfromimage(bmh, myimage)
	width = bmh.biWidth
	length =  bmh.biHeight
	bpp = bmh.biBitCount
	bitmapbuff = IntPtr.op_Explicit(myimage.ibuff) ' myimage.ibuff is the address of the pixel data

	' Create a bitmap inside a Victor image	
	select case bpp 
		case "1" 
			format = pixelformat.Format1bppIndexed
		exit select
		case "8"
			format = pixelformat.Format8bppIndexed
		exit select
		case "24"
			format = pixelformat.Format24bppRgb
		exit select
	end select      
	bm = New bitmap(width, length, myimage.buffwidth, format, bitmapbuff)
	g1 = graphics.fromimage(bm)

	action_requested = mid(s.id, 3)
	if(action_requested <> "") then ' Add a graphic or do some processing 
		select case action_requested 

			' Add .NET graphic element
			case "rectangle" 
				g1.drawrectangle(pens.red, 50, 50, width-100, length-100)
			exit select
			case "block"
				g1.fillrectangle(brushes.blue, 270, 200, 40, 30)
			exit select
			case "text"
				g1.drawstring("hello", drawfont, brushes.green, 10, 10 )
			exit select

			' Victor Image Processing
			case "blur"
				blur(myimage, myimage)
			exit select
			case "brighten"
				gammabrighten(0.5, myimage, myimage)
			exit select
			case "sharpen"
				sharpen(myimage, myimage)
			exit select

			' Reload original image
			case "reload"
				reload(myimage)
			exit select

		end select
	end if
	      
	' Display the modified Victor image
	displayimage_dtnt(image1, bm, width, length)	
end sub


Adding Graphics to an Image - the ASPX Web Form Source Code

		
<form id="Form1" encType="multipart/form-data" runat="server">
	<asp:image id="image1" runat="server"></asp:image><asp:label id="errormsg" runat="server"></asp:label>
	<p class="caption">This is <a href="http://www.catenarysystems.com/demos/images/pic1.tif">pic1.tif</a> loaded 
	as a Victor image and displayed as a .Net bitmap.
	</p>
	
	<div class="left">
	<p class="caption">Add a .NET graphic element</p>
	<asp:button class="testbutton" id="b_rectangle" onclick="process" runat="server" text="Rectangle" type="submit"></asp:button><br>
	<asp:button class="testbutton" id="b_block" onclick="process" runat="server" text="Solid block" type="submit"></asp:button><br>
	<asp:button class="testbutton" id="b_text" onclick="process" runat="server" text="Text" type="submit"></asp:button><br>
	
	<p class="caption">Apply a Victor Image Processing function</p>
	<asp:button class="testbutton" id="b_blur" onclick="process" runat="server" text="Blur" type="submit"></asp:button><br>
	<asp:button class="testbutton" id="b_brighten" onclick="process" runat="server" text="Brighten" type="submit"></asp:button><br>
	<asp:button class="testbutton" id="b_sharpen" onclick="process" runat="server" text="Sharpen" type="submit"></asp:button><br>
	
	<p class="caption">Reload original image</p>
	<asp:button class="testbutton" id="b_reload" onclick="process" runat="server" text="Reload" type="submit"></asp:button><br>
	</div>		
</form>


Victor Image Processing Library

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

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