Click here to Skip to main content
15,901,373 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: How to write text to an image? Pin
David Crow1-Aug-08 3:47
David Crow1-Aug-08 3:47 
AnswerOT- Nice article. Pin
CPallini1-Aug-08 8:26
mveCPallini1-Aug-08 8:26 
AnswerRe: How to write text to an image? Pin
Anthony Appleyard1-Aug-08 9:41
Anthony Appleyard1-Aug-08 9:41 
GeneralRe: How to write text to an image? Pin
Mark Salsbery1-Aug-08 10:29
Mark Salsbery1-Aug-08 10:29 
GeneralRe: How to write text to an image? Pin
Anthony Appleyard1-Aug-08 12:11
Anthony Appleyard1-Aug-08 12:11 
GeneralRe: How to write text to an image? Pin
Mark Salsbery1-Aug-08 12:49
Mark Salsbery1-Aug-08 12:49 
GeneralRe: How to write text to an image? Pin
Anthony Appleyard1-Aug-08 19:10
Anthony Appleyard1-Aug-08 19:10 
GeneralRe: How to write text to an image? Pin
Mark Salsbery2-Aug-08 6:20
Mark Salsbery2-Aug-08 6:20 
Anthony Appleyard wrote:
But please now I want to be able to write text to those images. So I need some way to set up an image which all of:-
* Has an HDC device-context handle and so can be written to by TextOut() etc.
* Can be written to or from by BitBlt().
* I can access its component bit patterns directly.


Besides the fact that a bitmap doesn't "have" an HDC (a bitmap can
be selected into a DC), a DIBsection fits your requirements exactly.

CreateDIBSection[^]

You say you've got the BITMAPINFO and bitmap bits in memory.
Given a BITMAPINFO *bmi and a void *bmbits, the following code will
create a DIBSection - a bitmap that you can select into a DC and also read/write
its pixel bits directly:
BITMAPINFO *bmi = ...;
void *bmbits = ...;

BYTE *pDIBSectionBits;
HBITMAP hBitmap = ::CreateDIBSection(NULL, bmi, DIB_RGB_COLORS, (void**)&pDIBSectionBits, NULL, 0);

if (hBitmap)
{
    // Copy source bitmap pixel bits to the new DIBsection
    LONG lStride = (((bmi->bmiHeader.biWidth * (long)bmi->bmiHeader.biBitCount + 31L) & (~31L)) / 8L);
    memcpy(pDIBSectionBits, bmbits, lStride * abs(bmi->bmiHeader.biHeight));

    // do something with the DIBSection

    ::DeleteObject(hBitmap);
}

Pretty simple Smile | :)

Mark

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

QuestionDatabase support Pin
Member 4431371-Aug-08 1:15
Member 4431371-Aug-08 1:15 
AnswerRe: Database support Pin
Rajesh R Subramanian1-Aug-08 1:26
professionalRajesh R Subramanian1-Aug-08 1:26 
AnswerRe: Database support Pin
Varghese Paul M1-Aug-08 1:32
Varghese Paul M1-Aug-08 1:32 
AnswerRe: Database support Pin
Le@rner1-Aug-08 18:30
Le@rner1-Aug-08 18:30 
QuestionLAUNCHING Application Pin
paul crescent31-Jul-08 23:58
paul crescent31-Jul-08 23:58 
AnswerRe: LAUNCHING Application Pin
CPallini1-Aug-08 0:00
mveCPallini1-Aug-08 0:00 
AnswerRe: LAUNCHING Application Pin
ThatsAlok1-Aug-08 0:47
ThatsAlok1-Aug-08 0:47 
AnswerRe: LAUNCHING Application Pin
Iain Clarke, Warrior Programmer1-Aug-08 3:18
Iain Clarke, Warrior Programmer1-Aug-08 3:18 
QuestionBuffer Copy / Concat Issue [modified] Pin
Programm3r31-Jul-08 22:57
Programm3r31-Jul-08 22:57 
AnswerRe: Buffer Copy / Concat Issue Pin
CPallini31-Jul-08 23:04
mveCPallini31-Jul-08 23:04 
GeneralRe: Buffer Copy / Concat Issue Pin
Programm3r31-Jul-08 23:06
Programm3r31-Jul-08 23:06 
QuestionRe: Buffer Copy / Concat Issue Pin
CPallini31-Jul-08 23:18
mveCPallini31-Jul-08 23:18 
AnswerRe: Buffer Copy / Concat Issue Pin
Perspx31-Jul-08 23:17
Perspx31-Jul-08 23:17 
AnswerRe: Buffer Copy / Concat Issue Pin
Cedric Moonen31-Jul-08 23:42
Cedric Moonen31-Jul-08 23:42 
QuestionType Conversion Pin
T.RATHA KRISHNAN31-Jul-08 22:14
T.RATHA KRISHNAN31-Jul-08 22:14 
AnswerRe: Type Conversion Pin
CPallini31-Jul-08 22:20
mveCPallini31-Jul-08 22:20 
GeneralRe: Type Conversion Pin
T.RATHA KRISHNAN31-Jul-08 22:26
T.RATHA KRISHNAN31-Jul-08 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.