Importing Bitmap from the Resources Code Snippet

This code snippet shows the how to import a Bitmap from the resources.

C++

#include <eVision/Easy/EImageC24.h>
#define IDB_BITMAP1 103

using namespace 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;
}

C#

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

using eVision;
// 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

Python

import eVision
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 = eVision.EImageC24(width, height)

np_view = np.asarray(image.PixelView)
np.copyto(np_view, bitmap)

# PIL loads images using RGB by default, eVision uses BGR
eVision.EasyColor.ConvertRGBImageToBGR(image, image)