|
Hi, I have a string of RGB RGB RGB RGB bytes that makes up a image, and I'd like to display it onto the screen. Can someone please give me the road map for doing that? It's kinda confusing for someone w/ minium graphical background. Here's what I wanted to do:
1. Put the RGBRGBRGBRGB string into a CBitmap
2. Display the CBitmap onto my screenDC (where screen may have any color bit depth -32bit 24bits 16bits...)
My CBitmap image only displays properly when my monitor is set to 32bit/pixel. I believe I need to use DIB for these various bit depth compatability.
THANKS IN ADVANCE!
|
|
|
|
|
Yes, to get an image that will display on any screen, you need a DIBSECTION. There are some good DIBSECTION wrappers on this site. The good thing is having created on, you get a pointer to the image data, and can just move your byte array into it. There's a catch though - Windows stores images a BGR, not RGB. If indeed you have RGB ( not BGR ), you'll need to swap some values as you copy them in, otherwise memset will be fine.
If the wrapper you use does not have a draw method, you can just create a DC and select your image into it.
CDC memDC;
memDC.CreateCompatibleDC(NULL);
memDC.SelectObect(name of your image, dereferenced if it's a pointer, assuming it offers operator HBITMAP);
then you can just BitBlt it onto the screen.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Thank you Christian for the tip. I found a DIBSection wrapper in Code Project, but the image still does not display properly with 16-bit color depth monitor setting.
I think it's because I am creating a bitmap wrong. Can you please take a look at the following:
*imageBuffer points to my image array BGRxBGRxBGRx...
<br />
bitmapBefore.CreateBitmap(sizeBefore.cx, sizeBefore.cy, 1, 32, imageBuffer);<br />
And then I display the bitmapBefore in my view.
This is what I did before in view:
<br />
CBitmap *bitmap = &(pDoc->bitmapBefore);<br />
dcTemp.CreateCompatibleDC(&cDC);<br />
dcTemp.SelectObject(bitmap);<br />
cDC.BitBlt(0,0, pDoc->sizeAfter.cx, pDoc->sizeBefore.cy,<br />
&dcTemp, 0, 0, SRCCOPY);<br />
<br />
and this is what I changed w/ DIBSection wrapper:
<br />
CBitmap *bitmap = &(pDoc->bitmapBefore);<br />
CDIBSectionLite dibsection;<br />
dibsection.SetBitmap(*bitmap);<br />
dibsection.Draw(&cDC, CPoint(0,0));<br />
They give the same results... Whenever I set my screen color depth to anything other than True Color (32bit), I get white surface. Can you spot what I'm doing wrong?
Thanks for your help!
Jerry
|
|
|
|
|
Having looked at the DIBSectionLite code, the draw function works one of two ways, depending on if hDrawDib is defined ( not NULL ).
I don't know anything about DibDrawDib, but if you comment out lines 636-649 of DibSectionLite, it will then act the way I was anticipating, and I see no reason for you to have any worries.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Christian has already answered your question in an authoritative fashion, but I'd like to point out two more catches (apart from the BGR order) you should be aware of:- There's a padding issue, namely that all bitmap rows must occupy a number of bytes that is multiple of 4. For instance, if your image is 5 pixels wide, then the bitmap is stored as
/----row 1-----\/----row 2-----\/----row 3-----\
BGRBGRBGRBGRBGRXBGRBGRBGRBGRBGRXBGRBGRBGRBGRBGRX... Where the X is one padding byte that makes every row occupy 16 bytes (the value of this byte is irrelevant).
- The first row stored is at the bottom, and the last one at the top. The usual assumption is the other way around, but the MS guys decided on this order for some strange reason.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Really? I'm a bit confused... I experimented w/ byte ordering RGB values in my CBitmap, and it came out to be BGRxBGRxBGRx... which displayed properly in a 32-bit color depth monitor setting.
So, that must be what's wrong w/ my code then? I should create BGRBGRBGRBGRX... and how should I create this DIB? Is DIB a sub-catagory of CBitmap?
Also, since CreateDIBSection asks for pDC, how can I create an DIB image when I don't have a DC that goes with it... or can I?
Thanks man!
|
|
|
|
|
Yes, the bottom to top ordering and the BGR ordering are standard in windows, so if the image is coming in that way, then it's fine.
CBitmap is a DDB - a device dependant bitmap. A DIB is device INdependant, in other words it defines it's own colour depth instead of relying on the colour depth of a device. A DIB cannot be used to draw on, etc. using a CDC. A DIBSection is a hybrid creature - a DIB that has a HBITMAP which can be selected into a DC and used like any other HBITMAP ( which CBitmap is an extended wrapper for ).
CreateDIBSection can just be passed in a CDC created with CreateCompatibleDC(NULL); The code I pointed you to on the WDJ site does this.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Thanks Christian for the explaination. Thanks Jouquin for your help also. PJ Arends sent me a really helpful section of the code using CreateDIBSection and SetDIBits. Just like you said. I am able to display images in different bit depths now Thanks so much.
|
|
|
|
|
I need some ideas. I have an encrypted executable file on disk. I decrypt the file to an array of bytes in memory. I would like to execute the file directly from memory without writing the decrypted file to disk. Anyone have an idea how to do this on Windows 2000?
|
|
|
|
|
Well, seems what you intend is feasible in principle. The idea is to create a virtual memory area allocated, commited and given execution access with VirtualAlloc(...,MEM_COMMIT,PAGE_EXECUTE_READWRITE) , copy the data there and jump into it (this last part might become tricky IMHO). Do a search on Usenet for "VirtualAlloc PAGE_EXECUTE", lots of information about this issue, though none conclusive.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Yes, it does look pretty tricky. The system apparently creates a process kernal object, then a 4-GB address space for the process, and maps the exe file into the address space. Then it calls LoadLibrary on each of the dlls listed in the exe file and does some address fixups when necessary. In short, this is quickly becoming very complicated. What I need is something like a CreateProcess that takes a memory address instead of a filename. Or, maybe even better, a way to create a virtual disk drive in memory and just do a file copy to the virtual drive and use CreateProcess or ShellExecute. Have you heard of any virtual disk drive programs for Win2000? I know that they are available for MS-DOS.
|
|
|
|
|
I have a program installed where I need to change one of the toolbar images. All I have is the executable, I believe it is possible to extract resources from an executable but is it possible to modify these resources (in the case of the tool bar bmp).
Regards,
SAK
|
|
|
|
|
You can open the executable with Visual C++, select open as resources, and then edit the toolbar bitmaps.
I just tried it.
|
|
|
|
|
Look at these functions:
BeginUpdateResource<br />
UpdateResource<br />
EndUpdateResource
Good luck!
|
|
|
|
|
If you're looking for a tool for the job, ResourceHacker is probably the best one out there.
Regards,
Alvaro
|
|
|
|
|
Hi all,
I implemented an ActiveX which runs fine in Debug mode.
When I compiled the project in Release mode, I got this
error message "Can't execute program".
Apparently, after the compilation process, the
myApp::InitInstace() is called which in turn calls
STDAPI DllRegisterServer(void)
{
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
return ResultFromScode(SELFREG_E_CLASS);
return NOERROR;
}
for some wild reason, It trys to run something after InitInstance.
The DllRegisterServer() function returns NOERROR.
I tried this on the command line, still got the same error:
c:>regsvr32 myActx.ocx
Does anyone know why?
Thanks
|
|
|
|
|
Try to register it with: (menu command) Tools->Register Control
or
Try to execute it from the activex control container tool
or
You still can debug it Release, goto: Project->Settings
C/C++ Tab:
Optimizations: Default
Debug Info: Program Database for Edit and Continue
Link Tab:
[x] Generate Debug Info
Good luck!
|
|
|
|
|
Thanks Ernest,
Debugging the release version won't help.
I register the activex on the command line as follows:
c:>regsvr32.exe myActX.ocx
The result was successfull. Right after that, regsvr32
trys to run something else. Then the MsDev pops up along
with the popup window with the error message:
"Cannot execute program"
It only happens when I try to build a release version.
The strange thing is It never happens in debug version don't know why
|
|
|
|
|
Can you see your control with the "ActiveX Control Container Test" program?
"Microsoft Visual Studio\Common\Tools\tstcon32.exe". If it works, your problem
is caused by something else. And check carefully the path of the control.
click "New control" toolbar button.
|
|
|
|
|
Yes, I can see the ActiveX control in "ActiveX Control Container Test".
It works and the path of the control is also correct.
The client test program is also working. The regsvr32.exe does
install/uninstall the ActiveX. The BUG (perhaps not a good choice of word
for today ) appears right after install/uninstall the ActiveX.
Thanks for your inputs.
|
|
|
|
|
Problem solved !
|
|
|
|
|
I'm developing a custom application to Capture Sequences.
I'm using Videofor Windows Macro to capture sequences.
I'm istalled a matrox Marvel G450eTv.
I Need to select runTime,before capture startes, the videoCompression to use:I know that there is the capDlgVideoCompression macro....but this is not good for my application.I need to select video Compression Through a different method such as special functions or silmilar solutions.
anybody know how can I do this???
thanks
DIEGO
|
|
|
|
|
Select codec by it's name in silence:
VidCap1.Compressor = "h263"
http://www.banasoft.net/AVPhone.htm
|
|
|
|
|
Hi, all, I want to read text files for processing in my CRichEditView text editor. If I don't set the attribute m_bRTF to FALSE when loading, it can't read other text files besides my own. How to test for other text files?
|
|
|
|
|
rtf files are, of course, text files. There is nothing absolutely definitive. There are some 99.9999% tests you can use.
Here is a sample of an rtf file. (it contains a string of 10 "a" characters. you could check for some of the first chars maybe "{\rtf" would be specific enough and yet general enough for all versions. I don't know if there are files with {\rft0 or {\rtf2.
{\rtf1\ansi\ansicpg1252\uc1 \deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman{\*\falt Times};}{\f55\froman\fcharset238\fprq2 Times New Roman CE{\*\falt Times};}
{\f56\froman\fcharset204\fprq2 Times New Roman Cyr{\*\falt Times};}{\f58\froman\fcharset161\fprq2 Times New Roman Greek{\*\falt Times};}{\f59\froman\fcharset162\fprq2 Times New Roman Tur{\*\falt Times};}
{\f60\froman\fcharset186\fprq2 Times New Roman Baltic{\*\falt Times};}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;
\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{
\nowidctlpar\widctlpar\adjustright \fs20\cgrid \snext0 Normal;}{\*\cs10 \additive Default Paragraph Font;}}{\info{\title sfdsdfsdsdfsdff}{\author WilsonB5}{\operator WilsonB5}{\creatim\yr2001\mo12\dy12\hr15\min41}{\revtim\yr2001\mo12\dy12\hr15\min42}
{\version2}{\edmins0}{\nofpages1}{\nofwords0}{\nofchars0}{\*\company }{\nofcharsws0}{\vern71}}\widowctrl\ftnbj\aenddoc\formshade\viewkind4\viewscale110\pgbrdrhead\pgbrdrfoot \fet0\sectd \linex0\endnhere\sectdefaultcl {\*\pnseclvl1
\pnucrm\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang{\pntxta )}}{\*\pnseclvl5
\pndec\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang
{\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}\pard\plain \nowidctlpar\widctlpar\adjustright \fs20\cgrid {aaaaaaaaaa
\par }}
Hope this helps,
Bill
|
|
|
|