|
This is the same issue as all your other questions in this forum. Perhaps you should try some of the suggestions you have already been given.
Veni, vidi, abiit domum
|
|
|
|
|
Don Guy wrote: What approach needs to be taken?
What you're supposed to do is respond to the button click by generating new HTML on the fly, and telling the HtmlDialog to load it. I don't recall the exact function names, but you'll find it all in the documentation.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
To make the question much more simpler
1. Can i pass the Image file (JPG, PNG) as a memory buffer like "unsigned char *" from my MFC app to the HTML page and then use some JavaScript function to understand that it's a Image file and display on the HTML page. It can be done either by passing the JPG to the "src" of Image or drawing it on a CANVAS. But all JS/HTML should have is a memory buffer of Image file.
So the 1st question is,
1. How to read a Image file as memory buffer (unsigned char *) in MFC? i.e, making sure it doesn't loose any NULL terminators or any binary contents.
And 2nd question is,
1. How to pass this memory buffer to the JavaScript function in the HTML page?
And 3rd question is,
1. How can the JavaScript function decrypt this memory buffer into a Image file and display in the HTML page?
The reason why i want to do it this way is because the HTML should never be able to display the Image file from a file path or URL. That is a requirement for the project i am doing.
HTML page should only use a memory buffer containing the Image file info. Hope this information helps.
Thanks in advance. I appreciate the 2 earlier responses i got.
|
|
|
|
|
If you want/need to do it that way, then why use the html dialog at all? Why not just make a regular dialog box that shows the graphic, and you can pass the memory buffer to it.
As far as I know, there is no way to do it the way you are describing.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I am going to assume you will follow what Richard said and reload the HTML in the dialog. I am also going to assume that you are able to modify the HTML from within your code.
In this case, you should be able to achieve what you want by embedding the image as Base64 encoded data, but note that this process increases the size of your data. This is also know as The Data URI Scheme:
http://en.wikipedia.org/wiki/Data_URI_scheme[^]
Here is a CodeProject Tip on the subject: Embedded HTML Help File with Images[^]
Be careful not to overdo it. Notice how slow this article loads because the resulting HTML document is 6.7 MB large: Walks Of Life[^]
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Hello there,
I am writing an MFC app in Visual Studio 2012 that will open a JPG file as binary and read all the contents to a CString.
I am able to read it to a std::Vector, but that doesn't help me much as i need to pass all the binary content as a MFC CString to another function.
Can anyone help me with a sample code for that?
Thanks in advance
|
|
|
|
|
Don Guy wrote: binary content
Don Guy wrote: MFC CString
These terms generally don't mix, something sounds wrong. a CString is not a good way to pass binary data.
|
|
|
|
|
While a CString object can contain null (i.e., \0 ) characters, their presence may produce unexpected results. Is CString a requirement.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
That's totally the wrong way to do it. A jpg file is pure binary and as such may contain null bytes which would cause any characters following it to be lost when copying into a CString object. Use a pure byte array and deal with data in the manner best suited to its type.
Veni, vidi, abiit domum
|
|
|
|
|
Let me explain the problem a little more deeper.
I am trying to call a JavaScript (JS) function in a HTML page and then want to pass the binary date. The C++ function that calls the JS is given below.
bool CallJavaScript(const CString strFunc,CComVariant* pVarResult);
The 1st argument is the JS Function Name and 2nd is the one to pass the Binary Data. 1st argument works fine as i am able to call the JS fucntion called "LoadImage" without any problem. Problem is with 2nd argument that's supposed to take the Binary data of the JPG file.
If i try to pass a std::Vector or std::string then it will give me an error.
But it's happy if i pass CString. But then with CString there's a problem with NULL characters.
Actually my plan is to pass the binary of a JPG to a JS function and let it display the JPG in the HTML page.
Is there a better way of doing this?
Can i typecast a Vector or std::string to a CComVariant*?
Please help.
Thanks
|
|
|
|
|
The function wants a pointer to a CComVariant object. So you must create a CComVariant object and attach the data in a format that is supported by the receiving function (your LoadImage function). Binary data are mainly passed as SAFEARRAY variants (see Array Manipulation Functions[^] about functions to create and access such arrays).
|
|
|
|
|
Don Guy wrote: Is there a better way of doing this? Can you retool the JS function to accept the image filename and let it do the loading?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
I'm working on ffmpeg to create a video using ffmpeg library.
I'm capturing desktop and using raw data to create a video, video is being created but there is nothing in video.
My code is:
for screen capture:
HANDLE BmpFile=INVALID_HANDLE_VALUE;
screenWidth = GetSystemMetrics(SM_CXSCREEN);
screenHeight = GetSystemMetrics(SM_CYSCREEN);
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
hBmp = CreateCompatibleBitmap(GetDC(0), screenWidth, screenHeight);
SelectObject(hCaptureDC, hBmp);
BitBlt(hCaptureDC, 0, 0, screenWidth, screenHeight, hDesktopDC, 0, 0, SRCCOPY|CAPTUREBLT);
BITMAPINFO bmi = {0};
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
bmi.bmiHeader.biWidth = screenWidth;
bmi.bmiHeader.biHeight = screenHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
pPixels = new RGBQUAD[screenWidth*screenHeight];
GetDIBits(hCaptureDC,hBmp,0,screenHeight,pPixels,&bmi,DIB_RGB_COLORS);
for video creation and frame write up:
AVCodec* codec;
AVCodecContext* c = NULL;
uint8_t* outbuf;
int i, out_size, outbuf_size;
avcodec_register_all();
printf("Video encoding\n");
codec = avcodec_find_encoder(CODEC_ID_H264); c = avcodec_alloc_context();
c->bit_rate = 20000000;
c->width = 1024;
c->height = 768;
c->time_base.num = 1;
c->time_base.den = 10;
c->gop_size = 12;
c->max_b_frames = 2;
c->keyint_min = 1;
c->i_quant_factor = (float)0.71;
c->b_frame_strategy = 20;
c->qcompress = (float)0.6;
c->qmin = 20;
c->qmax = 51;
c->max_qdiff = 4;
c->refs = 4;
c->trellis = 1;
c->pix_fmt = PIX_FMT_YUV420P;
c->codec_id =CODEC_ID_H264;
c->codec_type = CODEC_TYPE_VIDEO;
if (avcodec_open(c, codec) < 0) {
fprintf(stderr, "Could not open codec\n");
exit(1);
}
else printf("H264 codec opened\n");
outbuf_size = 100000 + c->width*c->height*(32>>3);
outbuf = static_cast<uint8_t *>(malloc(outbuf_size));
printf("Setting buffer size to: %d\n",outbuf_size);
FILE* f = fopen("example.h264","wb");
if(!f) printf("x - Cannot open video file for writing\n");
else printf("Opened video file for writing\n");
for(i=0;i<STREAM_FRAME_RATE*STREAM_DURATION;i++) {
fflush(stdout); screencap(); int nbytes = avpicture_get_size(PIX_FMT_YUV420P, c->width, c->height); uint8_t* outbuffer = (uint8_t*)av_malloc(nbytes*sizeof(uint8_t));
AVFrame* inpic = avcodec_alloc_frame();
AVFrame* outpic = avcodec_alloc_frame();
outpic->pts = (int64_t)((float)i * (1000.0/((float)(c->time_base.den))) * 90);
avpicture_fill((AVPicture*)inpic, (uint8_t*)pPixels, PIX_FMT_RGB32, c->width, c->height);
avpicture_fill((AVPicture*)outpic, outbuffer, PIX_FMT_YUV420P, c->width, c->height);
inpic->data[0] += inpic->linesize[0]*(screenHeight-1);
inpic->linesize[0] = -inpic->linesize[0];
struct SwsContext* fooContext = sws_getContext(screenWidth, screenHeight, PIX_FMT_RGB32, c->width, c->height, PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL);
sws_scale(fooContext, inpic->data, inpic->linesize, 0, c->height, outpic->data, outpic->linesize);
out_size = avcodec_encode_video(c, outbuf, outbuf_size, outpic); printf("Encoding frame %3d (size=%5d)\n", i, out_size);
fwrite(outbuf, 1, out_size, f);
delete [] pPixels; av_free(outbuffer);
av_free(inpic);
av_free(outpic);
}
outbuf[0] = 0x00;
outbuf[1] = 0x00;
outbuf[2] = 0x01;
outbuf[3] = 0xb7;
fwrite(outbuf, 1, 4, f);
fclose(f);
avcodec_close(c); free(outbuf);
av_free(c);
How can I do it?
Please share your opinions and experiences over it.
|
|
|
|
|
Hello amazing people, just have 2 questions
1- assuming I use Drawtext to output a text on HDC, is it possible to reverse that? i meant get that text which i drawn from HDC not from the buffer?
2- How in the world we know the length of executed code in an app? is it SizeOfRawData or what/?
I know how to use DOS header and the NTheader.. but i still do not know the length exactly, it seems that it's different if do calculation, I am sure that i did it wrong....
Thanks...
modified 6-Sep-13 4:00am.
|
|
|
|
|
1. I am not aware of any functions that can read a device context.
2. What do you mean by "length of executed code"? The size of an executable program in memory will be larger than its loadable exe file as it has the addition of stack and heap space. It can also grow and shrink during execution.
Veni, vidi, abiit domum
|
|
|
|
|
about the 2 question..
Yes i did mean that, but what if i want the size of written code inside a section? not the size of the section.. it's oky even if it before loading to the memory... basically not the extra 0000 in the size just the raw code....
this what i am trying to find out...?
modified 6-Sep-13 4:22am.
|
|
|
|
|
How do you define "written code inside a section", what is a section in this context? Do you mean source lines of code or object code, etc?
Veni, vidi, abiit domum
|
|
|
|
|
Hi to all.
In combobox control, I modified the context font,e.g. AMDGT_IV25,and display is ok.Now I need to get the item text, used the GetDlgItemText function,but the result was unrecognizable code.
Thanks!
|
|
|
|
|
just wondering A or W? the third parameter (LPSTR) or (LPWSTR) check that out...
modified 6-Sep-13 3:58am.
|
|
|
|
|
You do not use GetDlgItemText() to get a ComboBox item. Please show the code you are using, and what actual results you see.
Veni, vidi, abiit domum
|
|
|
|
|
Thanks for your answer
first:in CCombobox::DrawItem(LPDRAWITEMSTRUCT pDIStruct) function modified the dc font and dc.DrawText(str,itemRect,DT_LEFT|DT_VCENTER|DT_SINGLELINE);//显示文本
second: in mfc interface, display the special symbol.It's ok.e.g. input a "t",and display the special symbol.
third: how to get the special symbol string? E.g. is the "t" string,but other string.
Sorry!
|
|
|
|
|
Sorry but I did not understand that at all.
Veni, vidi, abiit domum
|
|
|
|
|
Hello there,
Is there a way i can convert a std::vector<byte> to MFC CString?
Also, Is there a way to convert std::string to MFC CString?
When i use,
std::string s;
CString str(s.c_str());
I see that it's not copying all the contents of std::string to CString.
Thanks in advance.
|
|
|
|
|
Don Guy wrote: Is there a way i can convert a std::vector<byte> to MFC CString? Yes, but you would need to write the code to make append vector item to the string in turn.
Don Guy wrote: I see that it's not copying all the contents of std::string to CString. You need to provide more information; show your code, and the values of all variables.
Veni, vidi, abiit domum
|
|
|
|
|