0

I'm trying to make a screen sharing program, the program flows will be like this:

  1. capture screen
  2. slice to 9
  3. compare new slice with old slice
  4. replace the different slice
  5. upload to web (with new slice)

But I've got some problems with replacing the slices (in replace function). From all the source I have searched I need to convert the bitmap image (the slice) to string, then I can replace. but there's no example for converting bitmap double array to strings.

Is there any possibility to replace the image without convert it to strings?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • What was that `iframe` about? I've removed it. – John Saunders Feb 06 '14 at 08:22
  • actually i've removed it myself but somehow there's no changes. i was trying to put my code there. sorry i'm new here, and thanks for edit it :) –  Feb 06 '14 at 09:41

2 Answers2

0

Why would you need to replace bitmap data using a string as intermediate? You can use bitmap manipulation functions just fine. Also, I'm having trouble understanding your algorithm. You get a bitmap of the whole screen. Then you cut it into 9 parts (are those the corners, edges and center?), compare each of the slices to their old versions one by one, replace the ones that changed, and then you upload the whole bitmap? Don't you want to upload each of the slices separately, only uploading the ones that changed? Otherwise it doesn't really make sense to do the slicing at all, or does it?

Now, it's true that converting the data to string lets you use the string comparison functions and other stuff like that, but that's an awful idea. The fastest way to compare two byte arrays would be using the memcmp function in msvcrt.dll. This answer gives you the solution to that - https://stackoverflow.com/a/2038515/3032289, including reading the data from the original bitmaps.

Then you just send the slices that aren't the same as their older versions and you're done, no replacing needed.

Community
  • 1
  • 1
Luaan
  • 62,244
  • 7
  • 97
  • 116
  • here is my code : http://dotnetfiddle.net/yB7Nlz i don't know why somebody removed it from my post. anyway, i need to slice the image into 9 bitmaps, so that i can compare it 1 by 1. because the goal of the program is to use the bandwidth as minimal as possible. that's why the replacement will only applied to the different slice. –  Feb 06 '14 at 09:49
  • @Eren I still don't understand where the replacement comes in. What are you trying to replace? You just have to send the slices that changed, and apply them on the other side. Any other way just makes you send everything anyway. The other side has to do the "combining". – Luaan Feb 06 '14 at 10:24
  • the replacement from the new screen capture that has been sliced into 9. –  Feb 06 '14 at 11:19
  • @Eren Well, your code is awfully inefficient, but it should work just fine. What's your problem? – Luaan Feb 06 '14 at 12:15
  • @Eren Also, why are you saving the bitmaps to files at all? If you're just sending them to a server and comparing them to some others you have stored, why not just do all that in memory, including sending the diff files? – Luaan Feb 06 '14 at 12:23
  • emm, actually the server will only receive the fix image, which is already compared and replaced. my problem is, when i compare i need to take the old slice image from the folder (using path so those files become strings) and compare with new slice image (which is bitmap), and if there is any different the new image will replace the old image (need to save the new bitmap into the folder). after this, all files will be transferred to the server. –  Feb 06 '14 at 14:51
0

Probably the best way is to perform a Base64 encoding

Google for base64 C++ source code.

Trifon
  • 1,081
  • 9
  • 19