Last active
December 11, 2016 19:37
-
-
Save larsschenk/630e9974d0586261ab5610fc8b566aab to your computer and use it in GitHub Desktop.
C# in powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########## | |
# C# code | |
$Source = @' | |
using System; | |
using System.Runtime.InteropServices; | |
using System.Drawing; | |
using System.Drawing.Imaging; | |
namespace ActiveBarcode.Tool | |
{ | |
public static class OCXBridge | |
{ | |
// get a .NET image object from a handle | |
public static Image getBitmapFromHBITMAP(IntPtr hBitmap) | |
{ | |
// Console.WriteLine("getBitmapFromHBITMAP: " + hBitmap); | |
Image img = Image.FromHbitmap(hBitmap); | |
return img; | |
} | |
} | |
} | |
'@ | |
Add-Type -ReferencedAssemblies 'System.Windows.Forms','System.Drawing' -TypeDefinition $Source -Language CSharp | |
############################################################################## | |
$ab # The ActiveBarode object | |
$ab = New-Object -ComObject BARCODE.BarcodeCtrl.1 | |
$result = $ab.CreatePictureBySize(400, 400) | |
$hBitmap = $ab.picture().handle() # The Windows GDI handle of the picture | |
$image = [ActiveBarcode.Tool.OCXBridge]::getBitmapFromHBITMAP($hBitmap) | |
# Or without c sharp: | |
#$image = [System.Drawing.Image]::FromHbitmap($hBitmap) | |
# Save as file | |
$filename ="$home\abtest.png" | |
$image.Save($filename) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment