Importing Bitmap from the Resources
Functional Guide | Reference: SetImagePtr
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using Euresys.Open_eVision;
static partial class Snippet
{
// Use this function to speed up the copy of the bitmap
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
static void ImportingBitmapFromResource()
{
///////////////////////////////////////////////////////////////
// This code snippet shows how to import a Bitmap from //
// the resources. //
///////////////////////////////////////////////////////////////
// Get the bitmap
Bitmap bitmap = new Bitmap("...");
int width = bitmap.Width;
int height = bitmap.Height;
BitmapData bmd = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
EImageC24 image = new EImageC24(width, height);
// Number of bytes per row to copy
uint strideWidth = (uint)(3 * width);
for (int y = 0; y < height; ++y)
{
CopyMemory(image.GetImagePtr(0, y), bmd.Scan0 + y * bmd.Stride, strideWidth);
}
bitmap.UnlockBits(bmd);
// Process the image
}
}
#include <Open_eVision.h>
void ImportingBitmapFromResource()
{
///////////////////////////////////////////////////////////////
// This code snippet shows the how to import a Bitmap from //
// the resources. //
///////////////////////////////////////////////////////////////
#define IDB_BITMAP1 103
using namespace Euresys::Open_eVision;
// Get the bitmap
HBITMAP hbitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
BITMAP bitmap;
GetObject(hbitmap, sizeof(bitmap), (LPVOID)&bitmap);
int width = bitmap.bmWidth;
int height = bitmap.bmHeight;
UINT8* buffer = reinterpret_cast<UINT8*>(bitmap.bmBits);
EImageC24 image(width, height);
for (int y = 0; y < height; ++y)
{
// Copy the entire row
memcpy(image.GetImagePtr(0, height - 1 - y), buffer, 3 * width);
buffer += 3 * width;
}
}
def ImportingBitmapFromResource():
###############################################################
## This code snippet shows how to import a Bitmap from ##
## the resources. ##
###############################################################
import open_evision as oev
from PIL import Image
import numpy as np
# Get the bitmap
bitmap = np.asarray(Image.open("...", "r"))
width = bitmap.shape[0]
height = bitmap.shape[1]
image = oev.EImageC24(width, height)
np_view = np.asarray(image.PixelView)
np.copyto(np_view, bitmap)
# PIL loads images using RGB by default, Open eVision uses BGR
oev.EasyColor.ConvertRGBImageToBGR(image, image)