View Full Version : Creare Immagine in VC++
Mezzetti0903
18-10-2002, 18:33
Buongiorno a tutti!
Vi ringrazio per l'attenzione che mi riservate!
Allora io volevo in VC++ far sì che venisse creata un immagine partendo da una risorsa "incorporata".
Ho incorporato la risorsa e poi ho scritto questo:
HBITMAP sfondoimm = NULL;
sfondoimm = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE("IDR_IMMAGINE1"));
la mia domanda è: E ORA?? Come cavolo faccio a scrivere sfondoimm su disco??
Grazie per l'aiuto!
boh, non so se esiste un metodo semplice quanto in BCB; prova a guardare qui (http://www.codeguru.com/bitmap/bitmap_to_file.shtml)
Mezzetti0903
18-10-2002, 19:46
Grazie mille Misterx, adesso provo, intanto non è che qualcuno di voi non ha esempi in VC++ ??
GRAZIE!
Questo codice è per MFC, se non ti va bene te lo traduco nelle API...
CDC *pDC = this->GetDC();
// Load IDB_BITMAP1 from the resources.
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP1))
{
// Get the size of the bitmap.
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
// Create an in-memory device context compatible with the
// display device context that is used to paint.
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
// Select the bitmap into the in-memory device context.
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);
// Find a center point for the bitmap in the client area.
CRect rect;
GetClientRect(&rect);
int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;
// Copy the bits from the in-memory device context to the on-
// screen device context to do the painting. Use the computed center
// point for the target offset.
pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
}
else
TRACE0("ERROR: Where is IDB_BITMAP1?\n");
Mezzetti0903
19-10-2002, 16:41
Grazie CIO!
Ma dove cavolo trovi tutte queste cose??
Non mi dire nel cervello sennò veramente saresti un mostro!
Mezzetti0903
19-10-2002, 18:30
Scusa Cionci, non ho avuto il tempo nemmeno di guardare il codice e solo ora noto che forse non mi sono spiegato bene !!
La mia domanda era Come posso materialmente creare un file .bmp su disco contenente l'immagine bitmap??
Tra l'altro non so nemmeno se sia possibile in VB++!
Comunque tornando a noi io vorrei (prendo il titolo del file postato da misterx) :
Writing a bitmap to a BMP file
Ciao e Grazie !!
Azz...scusa avevo capito male...
Mezzetti0903
20-10-2002, 12:36
Non scusarti, trovami il codice!!
Scherzo, se ce l'hai mi fai un grande favore! Ho girato ovunque ma non ho trovato nulla se non esempi in altri linguaggi!
Grazie CIO!
Cerca su CodeGuru... L'avevo messo da parte, ma non mi riesce più di trovarlo...
Devi scrivere prima la struttura BITMAPFILEHEADER e poi BITMAPINFO...e dopo i valori dei pixel...
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.