Red de conocimiento informático - Material del sitio web - En el procesamiento de imágenes por computadora, ¿cómo convertir una imagen en blanco y negro en una matriz 01? ¿Qué formato de imagen es más fácil de reconocer para las computadoras?

En el procesamiento de imágenes por computadora, ¿cómo convertir una imagen en blanco y negro en una matriz 01? ¿Qué formato de imagen es más fácil de reconocer para las computadoras?

Requiere el modo de aplicación mfc

MemoryImage.H

#ifndef H_MEMORY_IMAGE

#define H_MEMORY_IMAGE

#include lt; /p>

clase CMemoryImage

{

privado:

HBITMAP m_hBitmap

LPPICTURE m_hImage; p> público:

CMemoryImage( );

virtual ~CMemoryImage();

privado:

BOOL Image2Bitmap(); /p>

público:

BOOL LoadPictureFromMemory(long nSize, lpBuffer)

público:

BOOL LoadPictureFromMemory(long nSize, lpBuffer) LPVOID lpBuffer);

Operador HBITMAP () const {return m_hBitmap;}

}; p>

#include "stdafx .h"

#include "MemoryImage.h"

CMemoryImage::CMemoryImage()

{

p>

m_hBitmap = NULL;

m_hImage = NULL;

}

CMemoryImage.

CMemoryImage: :~CMemoryImage( )

{

if (m_hBitmap ! = NULL) {

DeleteObject(m_hBitmap

m_hBitmap = NULL);

}

if (m_hBitmap !

if (m_hImage ! = NULL){

m_hImage-gt; Release();

m_hImage = NULL

}

}

BOOL CMemoryImage::Image2Bitmap(){

BOOL; blnRet = FALSO;

HDC hdc = NULL;

__try{

__try{

OLE_HANDLE picHandle; > m_hImage-gt ;get_Handle(amp;picHandle);

hdc = ::CreateCompatibleDC(NULL);

> HBITMAP hOld = (HBITMAP)::SelectObject(hdc,

(HGDIOBJ) picHandle

m_hBitmap = (HBITMAP)::GetCurrentObject(hdc, OBJ_BITMAP); >

::SelectObject(hdc, hOld);

blnRet = TRUE;

}__except(EXCEPTION_EXECUTE _HANDLER){

__leave; >

}

}__final{

if(hdc ! = NULL){

EliminarDC(hdc);

}

}

}

}

Devuelve blnRet

}

BOOL; CMemoryImage::LoadPictureFromMemory(long nSize, LPVOID lpBuffer){

USES_CONVERSION;

BOOL blnRet = FALSE

HGLOBAL hMem = NULL

<; p> LPVOID lpAccess = NULL;

IStream * lpStream = NULL

__try{

__try{

hMem = :

hMem = :: GlobalAlloc(GMEM_FIXED, nSize);

lpAccess = :: GlobalLock(hMem);

memcpy(lpAccess, lpBuffer, nSize); p>

HRESULT hr = ::CreateStreamOnHGlobal(hMem, FALSE, amp; lpStream

if(!SUCCEEDED(hr)){

__leave;

hr = ::OleLoadPicture(lpStream,

0,

0,

IID_IPicture, reinterpret_castlt; LPVOID *gt; (amp ; m _hImage));

if(! SUCCEEDED(hr) || m_hImage == NULL){

__leave; p> blnRet = Image2Bitmap();

}__except(EXCEPTION _EXECUTE_HANDLER){

}

}___último{

if(lpStream ! = NULL){

lpStream-gt;Release();

}

if (lpStream !

if(lpAccess ! = NULL){

:: GlobalUnlock(hMem);

if (lpAccess !

if (hMem ! = NULL) {

::GlobalFree(hMem);

}

p>

if (hMem !

}

}

return blnRet;

}