|
I'd verify that the contents of the stream are a JPEG by loading it into memory using GetHGlobalFromStream followed by a GlobalLock on the HGLOBAL you got back from the first function. Then verify that the memory starts with the string "JFIF".
I used the WinHttp functions to download a JPG and found that the JPG started after the first six bytes of the response (I created a stream on a set of bytes) - I needed to offset the stream by six bytes to get the Bitmap to load:
Gdiplus::Bitmap* LoadBitmapFromUrl(CString const& url)
{
HINTERNET hInternet = WinHttpOpen(L"hello", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
if (!hInternet) return 0;
HINTERNET hConnection = WinHttpConnect(hInternet, L"www.python.org", INTERNET_DEFAULT_PORT, 0);
if (!hConnection) return 0;
LPCWSTR types[] = { L"image/jpeg", 0 };
HINTERNET hRequest = WinHttpOpenRequest(hConnection, L"GET", L"/images/success/standrews.jpg", 0, WINHTTP_NO_REFERER, types, 0);
if (!hRequest) return 0;
if (!WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0)) return 0;
if (!WinHttpReceiveResponse(hRequest, 0)) return 0;
HGLOBAL gblBuffer = GlobalAlloc(0, 1<<20);
LPBYTE buffer = (LPBYTE)GlobalLock(gblBuffer);
DWORD nBytesRead;
if (!WinHttpReadData(hRequest, buffer, 1<<20, &nBytesRead)) return 0;
IStream* pStream = 0;
CreateStreamOnHGlobal(gblBuffer, FALSE, &pStream);
ULARGE_INTEGER size; size.QuadPart = nBytesRead;
pStream->SetSize(size);
LARGE_INTEGER offset; offset.QuadPart = 6;
pStream->Seek(offset, STREAM_SEEK_SET, 0);
return new Gdiplus::Bitmap(pStream, FALSE);
}
(Please ignore the memory leak - I couldn't be bothered to tidy up - it's not production code )
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Dear Stuart,
Thanks for the help. I'd get invalid image if I offset the stream by 6 bytes. I am not sure why it worked in your case.
Anyway, I found where my problem was. I have that code running outside of GDI+ library init scope. After I moved the following init code to CWinApp::InitInstance() , it worked fine.
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
|
|
|
|
|
I took it as a given that the GDI+ stuff was right - more fool me
J.B. wrote: I'd get invalid image if I offset the stream by 6 bytes. I am not sure why it worked in your case.
Maybe because I was using WinHttpReadData rather than getting a stream directly from the IWinHttpRequest object.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: Maybe because I was using WinHttpReadData rather than getting a stream directly from the IWinHttpRequest object.
That'd be strange, because I checked the my Stream buffer and it had the same pattern as you described - after first 6 bytes, it comes with "JFIF"
FF D8 FF E0 00 10 4A 46 49 46
J F I F
|
|
|
|
|
I'm wrong - I thought the JFIF came at the start of a JPEG file - having just looked at a JPG in a hex editor, it doesn't.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
trongduy wrote:
1. Be organized classes and write the application to allow load and display all kinds of image files with the extensions in the following categories. Jpg,. Bmp,. Dib,. Gif. Programs that change the image as horizontal turn, vertical (mirror), dial 90degree, the gray level to get the sound, get the wrong picture of the two special functions and stored into different (but still one of the significantly above).
Requirements: The thought by the audience. Can be programmed in the Windows environment. Do not use static function as eg in the theory, does not switch, in the case.
2. An "input directory" is a folder or a file, a directory of many "input folder". Drive is a special case of the directory. Be organized classes to perform concept computer, disk drive, folder, file with the relationship as over. Write the application for permission to view the content of the object type as similar functions of the software Tree NC.
3. For the types: circle, ellipse image, the polygon, crescent,'s wings, rhombus, parallelogram, trapezium, rectangle, square, triangle, triangle square, square triangle needed. Write a program that allows applications to create (or enter) the two pictures in one of the above. Notice in two pictures that are not intersecting, if any color to the bowl and the dark sea of the interface. The user can press the arrow keys to move one of two pictures, the +, - to zoom out one of the two pictures. Programs can work with all kinds of equipment in different graphics modes, text mode (each a '*' is a moral pixels). Program can zoom to pixel morally, from the graphics mode to text or vice versa, users do not see the object to be exhaustive or bé tí hon.
4. A road of many road Polyline (line), each line can be a straight section (Strait line), and (ARC), or a bezier polyline. Organization of classes necessary, establish the relationship between class and write a program that allows to create polyline, create a copy of the polyline, zoom in, zoom out, turn polyline, polyline separation (separation of the polyline in the a polyline into the road (line, arc, bezier), define two functions have polyline cross or not?
|
|
|
|
|
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi there,
I have in my application a button that launches another application such as the on-screen keyboard using the createprocess function. If the button is pressed again I want to close the application. How can I do this safely?
Many thanks
Jim
|
|
|
|
|
jimjim733 wrote: If the button is pressed again I want to close the application. How can I do this safely?
By calling ExitProcess() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Or if you want to kill the new application from the one that spawned it, use TerminateProcess().
|
|
|
|
|
I am BATMAN wrote: ...use TerminateProcess().
Which is unsafe.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
I suppose Batman isn't expected to terminate gracefully a process...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
jimjim733 wrote: safely
Define what you mean by 'safe' - that'll help indicate what an appropriate solution is.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I stored the data in structure and placed it into a vector. However i need to upload this data through web service to the server and this happend for every 5 mins(i used a waitable timer).thus i used an array and send the data from vector to an array
LogInfo *Info = new LogInfo [m_vectStruct.size()];
for (int j = 0; j < m_vectStruct.size(); ++j)
{
ThreatInfo[j] = m_vectStruct.at(j);
}
However the data is going beyong 800MB and becoz of this the network is getting blocked.
Thus please let me know how can i send the data from vector to an array even if the size of the data is more than 3GB???
I Even Used the below code but of no use.
copy ( m_vectStruct.begin(), m_vectStruct.end() , &Info );
Please help its bit urgent...
Thanks in Advance
|
|
|
|
|
Instead of using a waitable timer, why can't you choose a limit on the number of elements in the vector and upload it as soon as it hits this limit? Also, what's with copying stuff into an array and all? I don't get the idea.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
brucewayn wrote: this happend for every 5 mins
brucewayn wrote: However the data is going beyong 800MB and becoz of this the network is getting blocked.
Not sure we have the entire picture, but based on that picture there might be a need to send the data in smaller segments rather than sending all of it every 5 minutes.
|
|
|
|
|
brucewayn wrote: thus i used an array and send the data from vector to an array
Does the vector get cleared periodically? If not, then...why bother? Underneath the covers, a vector == an array.
brucewayn wrote: Thus please let me know how can i send the data from vector to an array even if the size of the data is more than 3GB???
For a start with a 64bit OS and 8GB+ of RAM?
Can you give some more information about what you're trying to achieve, what the context is, 'cause from what you've given us, I'm baffled by what you're doing.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Folks, I know we can use unsigned/signed int and char to define our own Boolean type in C. We can either use 0 or 1 to distinguish FALSE or TRUE or use TRUE as anything which is non-zero.
Why can't I use float data type to define my own boolean type?
Can I use the zero and no zero concept using float and define my boolean type using it?
|
|
|
|
|
A custom boolean type? I mean - you are going to have a true , false and then third state, which would signify maybe or dunno state?
Seriously though, why do you need such a thing? If you need it, you already seem to know that you can use an int . I just don't get it.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Basically, I am looking to use only two states TRUE or FALSE, YES or NO anything which is not FALSE will be TRUE, so no intermediate state.
Someone pointed that using float would be wrong. Just looking to know that why it would be wrong.
|
|
|
|
|
So, you can initialize all your boolean variables with true and make sure that unless you set it to false, it would remain true. Am I missing something big?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
kaku_lala wrote: Basically, I am looking to use only two states TRUE or FALSE, YES or NO anything which is not FALSE will be TRUE, so no intermediate state.
kaku_lala wrote: Someone pointed that using float would be wrong. Just looking to know that why it would be wrong.
Quote Selected Text
In any case it is pointless.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Possibly he need a fuzzy logic [^] variable...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
kaku_lala wrote: Why can't I use float data type to define my own boolean type?
You could. Doesn't this compile?
float f;
if (f) { }
Now, why would you want to? What benefit is there from using a float as a boolean?
There are plenty of flaws as well - as soon as you start doing arithmetic with floats involving numbers that cannot be precisely represented in a float, you're in for trouble.
Consider this short program:
#include <iostream>
int main()
{
float g = 0.0;
while (g < 10.0)
{
g += 0.1;
std::cout << g << std::endl;
}
}
Simple, right? Not entirely - here's part of the output:
7.7
7.79999
7.89999
7.99999
8.09999
8.2
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
kaku_lala wrote: Why can't I use float data type to define my own boolean type?
Can you guess the output ? Try this code;
typedef float FLOATBOOL;
bool func_check_BF(FLOATBOOL x)
{
if (x)
{
cout << x << " is TRUE - FLOATBOOL" << endl;
return true;
}
else
{
cout << x << " is FALSE - FLOATBOOL" << endl;
return false;
}
}
bool func_check(bool x)
{
if (x)
{
cout << x << " is TRUE - bool" << endl;
return true;
}
else
{
cout << x << " is FALSE - bool" << endl;
return false;
}
}
int main(int argc, char* argv[])
{
func_check_BF((FLOATBOOL)0);
func_check_BF((FLOATBOOL)0.1);
func_check_BF((FLOATBOOL)1);
func_check((bool)0);
func_check((bool)0.1);
func_check((bool)1);
return 0;
}
Any way it is pointless! It should be only TRUE or FALSE for a boolean variable.Otherwise your customer may blessed with cocktails from a tea wending machine.
|
|
|
|
|