Page 1 of 2 12 LastLast
Results 1 to 40 of 52

Thread: How to change the specified color in the picture to another color?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    How to change the specified color in the picture to another color?

    Hi, how to change the specified color in the picture(StdPicture) to another color? For example, change the red color to blue. Thanks in advance.




    Note: I merged this topic into another post (This may cause confusion and inconvenience, sorry):
    http://www.vbforums.com/showthread.p...35#post5147035
    Attached Images Attached Images  
    Last edited by dreammanor; Mar 8th, 2017 at 06:03 AM.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Re: How to change the specified color in the picture to another color?

    Hi, you could loop through all the pixels using a For-Next loop and get a pixel's color using the "Point(x, y)" function. You would then replace that pixel if it has the color that is to be changed using the "PSet(x, y)" method. Unfortunately this will be rather slow except for small images. Perhaps you would get a better answer if you were more specific about what you're trying to accomplish. Do you want to be able to modify any color in any image, are you trying to create an animation, etc? Do you have any code already?
    Last edited by Peter Swinkels; Mar 2nd, 2017 at 09:37 AM.

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to change the specified color in the picture to another color?

    Another question is whether or not the color to change is one exact, specific color or not. Altering one color is fairly easy, but "shades of a color" is another thing altogether.

    If your source image comes from a file format using lossy compression (I'm laughing at you, JPEG) you'll almost certainly have multiple shades, color fringes, etc. as artifacts of the compression.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: How to change the specified color in the picture to another color?

    The simplest answer is probably outside of the language: Take the image, copy it, change it as you want, then save the new image. When you do whatever would cause one to change to the other, you'd just swap the two images rather than changing the existing image.
    My usual boring signature: Nothing

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,910

    Re: How to change the specified color in the picture to another color?

    IMHO, Tanner should be the one responding to this. Dreammanor, take a look at Tanner's PhotoDemon project (source here).

    Specifically, take a look at his ReplaceSelectedColor procedure. It does precisely what you're asking, and it's got threshold settings to overcome the issues brought up by Dilettante. It'd take a bit of work to cut out Tanner's procedure and incorporate it into your project, but it'd be an excellent learning process for you.

    Note that Tanner's work is BSD open source licensed. Therefore, if you use sections of his work in yours, your work should be open source as well.

    Manipulating images can get very complex very quickly, but they're not impossible. Also, if you're really interested in image manipulation, it'll soon be time to start studying the GDI and the GDI+.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,910

    Re: How to change the specified color in the picture to another color?

    Awww Shaggy, that's cheating.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: How to change the specified color in the picture to another color?

    Note that Tanner's work is BSD open source licensed. Therefore, if you use sections of his work in yours, your work should be open source as well.
    Actually, it's just the opposite. BSD licenses are *not* copyleft. Usage of the code in closed-source or commercial projects is 100% okay!

    @dreammanor: dilettante did a great job laying out the problems with this task, and I gotta be honest - I think Shaggy's suggestion is spot-on. Run-time color changes can certainly be done, but "doing it right" is non-trivial. Saving two image copies is much easier (and faster, depending on the image sizes involved).

    If you can elaborate a bit on what you want to accomplish, we could probably be more helpful. Specifically: is there any advantage to changing the color at run-time, vs just saving two copies of the image? Are you loading the image from file, or drawing it at run-time? Stuff like this makes a big difference.
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,910

    Re: How to change the specified color in the picture to another color?

    Ahhh, sorry about that, Tanner. I'm much more familiar with the GPLv3 which I attach to my primary application, and is definitely a copyleft protection. You're very generous to attach a "totally" open license to your software.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Thanks all the replies.

    This is the case: When I copy data from MS-Word to RichTextBox, the color of the image contained in the data automatically changes. So I want to change the color of these pictures into the original color (or black).

    I will upload a test program tomorrow, thanks very much.
    Last edited by dreammanor; Mar 2nd, 2017 at 08:22 AM.

  10. #10
    Hyperactive Member
    Join Date
    Oct 2016
    Posts
    369

    Re: How to change the specified color in the picture to another color?

    Your request now is totally different from your first post. You made it sound like you wanted to change a solid color (red) to another solid color (blue) which is plausible. No, you say you want to take an image that has one or more colors that has been changed automatically back to it's original colors. The only way I can think of is to have a copy of the original image unchanged before the copy takes place and then after the copy process you retrieve this original image and place it in the RTB where the changed image is positioned. This is basically the same thing as Shaggy Hiker suggested in post #4

    The question I have now is the data from MS-Word a combination of text and image or just an image only. A problem would be how do you get the image from the source before you transfer the data over to the RTB.

    BTW: What causes the image colors to change in the first place? Maybe this might be your problem to be solved
    Last edited by I Love VB6; Mar 2nd, 2017 at 01:40 PM.

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by Elroy View Post
    Awww Shaggy, that's cheating.
    The first rule of graphics: Cheat whenever possible.
    My usual boring signature: Nothing

  12. #12
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by dreammanor View Post
    This is the case: When I copy data from MS-Word to RichTextBox, the color of the image contained in the data automatically changes. So I want to change the color of these pictures into the original color (or black).
    You still sure, that going with RTF is the right choice for the Data-Format you want to
    "put in storage" somewhere (I assume DB-Fields)?

    Why not use HTML for that (since Word puts also HTML-format onto the Clipboard as well)?

    There's quite good HTML-Editors out there, which you can use on e.g. a VB-Form,
    to edit such copied HTML-content after retrieval.

    Olaf

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by Peter Swinkels View Post
    Hi, you could loop through all the pixels using a For-Next loop and get a pixel's color using the "Point(x, y)" function. You would then replace that pixel if it has the color that is to be changed using the "PSet(x, y)" method. Unfortunately this will be rather slow except for small images. Perhaps you would get a better answer if you were more specific about what you're trying to accomplish. Do you want to be able to modify any color in any image, are you trying to create an animation, etc? Do you have any code already?
    Yes, using "Point(x, y) and PSet(x, y) method will be rather slow. In the following test program, I will clearly explain my purpose, thank you.


    Quote Originally Posted by dilettante View Post
    Another question is whether or not the color to change is one exact, specific color or not. Altering one color is fairly easy, but "shades of a color" is another thing altogether.

    If your source image comes from a file format using lossy compression (I'm laughing at you, JPEG) you'll almost certainly have multiple shades, color fringes, etc. as artifacts of the compression.
    At first, I just wanted to change several colors (red, green, blue), but now it looks like this is not enough. Because things began to get complicated, there ware mutiple shades in the picture. Thank you, you gave me too much help.

    Quote Originally Posted by Shaggy Hiker View Post
    The simplest answer is probably outside of the language: Take the image, copy it, change it as you want, then save the new image. When you do whatever would cause one to change to the other, you'd just swap the two images rather than changing the existing image.
    Maybe what you said is just a joke, but now it seems that it may be the only viable way. Thank you.

    Quote Originally Posted by Elroy View Post
    IMHO, Tanner should be the one responding to this. Dreammanor, take a look at Tanner's PhotoDemon project (source here).

    Specifically, take a look at his ReplaceSelectedColor procedure. It does precisely what you're asking, and it's got threshold settings to overcome the issues brought up by Dilettante. It'd take a bit of work to cut out Tanner's procedure and incorporate it into your project, but it'd be an excellent learning process for you.

    Note that Tanner's work is BSD open source licensed. Therefore, if you use sections of his work in yours, your work should be open source as well.

    Manipulating images can get very complex very quickly, but they're not impossible. Also, if you're really interested in image manipulation, it'll soon be time to start studying the GDI and the GDI+.

    Good Luck,
    Elroy
    Elroy, I will study Tanner's source code carefully. But now things are getting complicated, see my test program. Thank you.


    Quote Originally Posted by Tanner_H View Post
    Actually, it's just the opposite. BSD licenses are *not* copyleft. Usage of the code in closed-source or commercial projects is 100% okay!

    @dreammanor: dilettante did a great job laying out the problems with this task, and I gotta be honest - I think Shaggy's suggestion is spot-on. Run-time color changes can certainly be done, but "doing it right" is non-trivial. Saving two image copies is much easier (and faster, depending on the image sizes involved).

    If you can elaborate a bit on what you want to accomplish, we could probably be more helpful. Specifically: is there any advantage to changing the color at run-time, vs just saving two copies of the image? Are you loading the image from file, or drawing it at run-time? Stuff like this makes a big difference.
    Tanner, please see the following test program. You are graphic expert, please give more help, thank you.
    Last edited by dreammanor; Mar 3rd, 2017 at 04:20 AM.

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by I Love VB6 View Post
    Your request now is totally different from your first post. You made it sound like you wanted to change a solid color (red) to another solid color (blue) which is plausible. No, you say you want to take an image that has one or more colors that has been changed automatically back to it's original colors. The only way I can think of is to have a copy of the original image unchanged before the copy takes place and then after the copy process you retrieve this original image and place it in the RTB where the changed image is positioned. This is basically the same thing as Shaggy Hiker suggested in post #4

    The question I have now is the data from MS-Word a combination of text and image or just an image only. A problem would be how do you get the image from the source before you transfer the data over to the RTB.

    BTW: What causes the image colors to change in the first place? Maybe this might be your problem to be solved
    At first, I just wanted to change several colors (red, green, blue), but now it looks like this is not enough. Because things began to get complicated. please see my test program, thank you.

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by Schmidt View Post
    You still sure, that going with RTF is the right choice for the Data-Format you want to
    "put in storage" somewhere (I assume DB-Fields)?

    Why not use HTML for that (since Word puts also HTML-format onto the Clipboard as well)?

    There's quite good HTML-Editors out there, which you can use on e.g. a VB-Form,
    to edit such copied HTML-content after retrieval.

    Olaf
    Olaf, I have encountered too many problems in using RTF, I am now some discouraged, maybe HTML is a better choice. I'm just worried that HTML is bloated and will take up too much database storage space. If the entire HTML file (including pictures) is stored in a database field, this is feasible? There will be a lot of HTML documents need to be stored in the database.

    Please advise, thanks very much.

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    When I copy data from MS-Word to RichTextBox, I encountered the following three questions:
    ◆ The image color is changed
    ◆ The edge of the picture appears jagged
    ◆ The Unicode characters can't be displayed

    Please look at the test program source code, thanks.
    Attached Images Attached Images  
    Attached Files Attached Files

  17. #17
    Hyperactive Member
    Join Date
    Oct 2016
    Posts
    369

    Re: How to change the specified color in the picture to another color?

    Sorry, I can't use your program as I do not have MS Word
    Last edited by I Love VB6; Mar 3rd, 2017 at 01:43 PM.

  18. #18
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to change the specified color in the picture to another color?

    Word may well copy to the clipboard in multiple formats, perhaps generic system defined formats and private formats only Word implements. The RichTextBox can probably only accept a few formats such as text, RTF text, and a set of object formats such as an OLE bitmap, WMF, EMF, etc. that the system will synthesize.

    Your "high fidelity" snippet probably isn't something that RichEdit can accept without distortion.

    See Clipboard Formats

  19. #19
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,671

    Re: How to change the specified color in the picture to another color?

    It seems that it's not a problem of the clipboard, because saving the file as RTF from Word and then loading it in the RTB, the same happends.

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by Eduardo- View Post
    It seems that it's not a problem of the clipboard, because saving the file as RTF from Word and then loading it in the RTB, the same happends.
    Yes, I think so. Thanks for the reply.

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by dilettante View Post
    Word may well copy to the clipboard in multiple formats, perhaps generic system defined formats and private formats only Word implements. The RichTextBox can probably only accept a few formats such as text, RTF text, and a set of object formats such as an OLE bitmap, WMF, EMF, etc. that the system will synthesize.

    Your "high fidelity" snippet probably isn't something that RichEdit can accept without distortion.

    See Clipboard Formats
    Just as Eduardo said, it seems that it's not a problem of the clipboard, because I copied the image from MsWord to MSPaint, the picture was not distorted.

    The problems of picture color and Unicode can be put into the future, I can temporarily fix these two problems by manually modifying the picture.

    But picture distortion is a big trouble, because picture fidelity is very important to my project. I wonder if there is any way to solve this problem. Thanks very much.
    Last edited by dreammanor; Mar 4th, 2017 at 07:43 AM.

  22. #22
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by dreammanor View Post
    Just as Eduardo said, it seems that it's not a problem of the clipboard, because I copied the image from MsWord to MSPaint, the picture was not distorted.
    I don't think you realize that you both moved the goalposts. You haven't proven anything suggesting this isn't related to clipboard operations and object formats RichEdit supports.

  23. #23

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Thank you, Dilettante. I will continue to do some testing.

  24. #24
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to change the specified color in the picture to another color?

    I'm not sure you are going to find a solution.

    If we knew what problem you are trying to solve instead of how you have decided to solve it we might be able to back your train up to a point where another more viable path could be taken instead.

    If your problem is really "Users have Word documents they will copy and paste into my application and I have to decode this crap and somehow stuff it into a database" well... yeah, then you're stuck.

    But if the real problem is something entirely different and you are just stuck down here in the weeds due to choices you made then people might have alternatives to suggest.

    Is Word even in the picture at all because you made it part of the problem?

    As I asked, can you back this train up closer to the departing station? You seem to be on the track to Crazy Town, and you may not have a path to the real destination beyond that. Crazy Town may be at the end of the line.

  25. #25
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: How to change the specified color in the picture to another color?

    I also don't have Word so I can't test directly, but the loss of antialiasing suggests that EMF may be in use. It's possible Word is placing "newer" EMF+ data on the clipboard, with old-style EMF included as a backup. (I say "newer" because EMF+ has been around since XP days... so not that new.)

    While you could use some clipboard APIs to manually figure out what formats Word is sticking on the clipboard, as others have suggested, that won't help you solve the problem of the Rich Text Box picking whatever format it pleases.

    My only remaining guess would be something messy like subclassing the clipboard, intercepting paste messages before they hit the Rich Text Box, and possibly sending your own EM_PASTESPECIAL or EM_CANPASTE messages until you find a combination that maintains image fidelity. That's not a project for the faint of heart, however.
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  26. #26
    Hyperactive Member
    Join Date
    Oct 2016
    Posts
    369

    Re: How to change the specified color in the picture to another color?

    I pasted your images from MS-WORD into RTB and they are exactly the same

  27. #27
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to change the specified color in the picture to another color?

    The Asian characters give credence to the theory that some format of Metafile is being copied. They fail to convert into ANSI in the pasted image.

  28. #28
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,671

    Re: How to change the specified color in the picture to another color?

    dreammanor: since you can see that with RichTextBox1.LoadFile (App.Path & "\sample.rtf") you have the exact same problem, you can realize that it is an intrinsic limitation (or bug in the fist case when it changes the colors) of the RichTextBox.

    I tried with some other Rich Edit implementations with no result.

    Did you consider using an OLE Container instead of the RichTextBox?

    PS: I can't help you much with the OLE Container because I never used it.

  29. #29

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by I Love VB6 View Post
    I pasted your images from MS-WORD into RTB and they are exactly the same
    For the first image in the sample.doc, when you copy the image only into RTB, the color of the picture does not change, but the lines appear jagged. When you copy both the picture and the top of the text, the color of the picture will change.

  30. #30

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by Tanner_H View Post
    I also don't have Word so I can't test directly, but the loss of antialiasing suggests that EMF may be in use. It's possible Word is placing "newer" EMF+ data on the clipboard, with old-style EMF included as a backup. (I say "newer" because EMF+ has been around since XP days... so not that new.)

    While you could use some clipboard APIs to manually figure out what formats Word is sticking on the clipboard, as others have suggested, that won't help you solve the problem of the Rich Text Box picking whatever format it pleases.

    My only remaining guess would be something messy like subclassing the clipboard, intercepting paste messages before they hit the Rich Text Box, and possibly sending your own EM_PASTESPECIAL or EM_CANPASTE messages until you find a combination that maintains image fidelity. That's not a project for the faint of heart, however.
    Yes, EMF is used. After testing, I found the following phenomena:
    1. When I save sample.doc as htm file, I find that MS-Word saved each image as an emf and a gif file.
    2. When I save sample.doc as sample.rtf, if I open the sample.rtf with MS-Word, the image is not distorted (no jagged). However, when I open the sample.rtf in the RTB, the image has changed: the color changed, also produced a jagged, Unicode characters can not be displayed. In other words, RTB can not correctly read color info., anti-aliasing info. and Unicode info. In fact, all of this information is present in the clipboard or in the RTF file.

    As you said, before the data copy into RTB, if we suclass the clipboard and convert the pictures into PNG images, the problem may be solved. But this method is very difficult to me. I'll try the way TOM (Dilettante told me in the other thread).

  31. #31

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by dilettante View Post
    I'm not sure you are going to find a solution.

    If we knew what problem you are trying to solve instead of how you have decided to solve it we might be able to back your train up to a point where another more viable path could be taken instead.

    If your problem is really "Users have Word documents they will copy and paste into my application and I have to decode this crap and somehow stuff it into a database" well... yeah, then you're stuck.

    But if the real problem is something entirely different and you are just stuck down here in the weeds due to choices you made then people might have alternatives to suggest.

    Is Word even in the picture at all because you made it part of the problem?

    As I asked, can you back this train up closer to the departing station? You seem to be on the track to Crazy Town, and you may not have a path to the real destination beyond that. Crazy Town may be at the end of the line.
    Dilettante, I am sorry for the misunderstanding. Maybe I should solve a question first, and then solve the next question, rather than put all the questions together.

    In fact I have been trying to find a solution, I know Clipboard should be a breakthrough point for the solution. But ClipBoard's knowledge is so much, we have to spend a lot of time to fully understand it. I was thinking, is there a convenient way?

    I'm still doing a lot of testing, including testing CKEditor and Krool's RichTextBox. I am also going to test Open Office and WPS (a Chinese Word processing software) to see if they can fully support Windows Clipboard, and make the image without distortion. If there is a software(except MS-Word) that can be high-fidelity to read Rich-Text (including pictures) from the Clipboard, then we should be able to find a solution to the problem.
    Last edited by dreammanor; Mar 5th, 2017 at 10:12 AM.

  32. #32

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by Eduardo- View Post
    dreammanor: since you can see that with RichTextBox1.LoadFile (App.Path & "\sample.rtf") you have the exact same problem, you can realize that it is an intrinsic limitation (or bug in the fist case when it changes the colors) of the RichTextBox.

    I tried with some other Rich Edit implementations with no result.

    Did you consider using an OLE Container instead of the RichTextBox?

    PS: I can't help you much with the OLE Container because I never used it.
    Thank you, Eduardo. I will continue to do some testing, including OLE Container.

  33. #33
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to change the specified color in the picture to another color?

    I guess what I was wondering is why Word or any other word processor is part of the problem at all if this is about capturing information to be stored in a database. What happens if the source is copied from an open PDF document or an HTML web page? Don't you face similar issues?


    The RichTextBox has some severe imitations. It is a wrapper around early versions of RichEdit (1.0, or 2.0 or 3.0 in "1.0 emulation mode" post-Win95). RichEdit 4.1 is available in Windows XP SP2 and later I think but RichTextBox never uses it.

    Word started using its own internal private RichEdit a long time ago, probably back to Word 2000 if not Word 97. Each version of Word since then has its own newer version of internal RichEdit.

    So to get even a little bit closer to Word capabilities you need a 3rd party "RichTextBox" or a lot of code to create your own in VB6 or C++ that wraps the RichEdit 4.1 version inside Msftedit.dll instead of the older Riched20.dll.


    It seems like you want to use RichTextBox as both a paste/drop target and a display control for the pasted/dropped data and probably for such data retrieved from your database later. I'm not sure that even a RichEdit 4.1 is going to do everything you want.

    But at this point we don't know what you want to do, only how you have decided to do it.

    To use the travel analogy again, if we knew where you are starting from and where you are trying to get to we might be able to suggest another route. Is copy/pasting from Word a requirement or just something you chose hoping it might help?

  34. #34
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: How to change the specified color in the picture to another color?

    My RichTextBox uses Msftedit.dll (if exist) or the older Riched20.dll.
    And I guess he has also there problems. So that cannot be the cause..

  35. #35
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How to change the specified color in the picture to another color?

    Yeah, I didn't think that would be a magic bullet.

    It might be worth trying the ClipBoard API so that pasting EMF+ is possible, but I'm not sure whether a StdPicture can even handle those anyway.

  36. #36
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by dilettante View Post
    Yeah, I didn't think that would be a magic bullet.

    It might be worth trying the ClipBoard API so that pasting EMF+ is possible, but I'm not sure whether a StdPicture can even handle those anyway.
    Those *.emz which are generated (on the ClipBoard, but also during HTML-export from Word),
    are not "EMF+" (which is just a GDI+ applied antialiased rendering from normal EMF-records-enumerations) -
    they are plain "GZip-compressed EMF-files".

    @the OP
    FWIW, here's a Cairo-based EMZtoPNG-converter (although we still don't know, what the whole exercise really is for).

    Code:
    Option Explicit
    
    Private Sub Form_Load()
      EMZ2PNG App.Path & "\image001.emz", App.Path & "\image001.png", 480
      EMZ2PNG App.Path & "\image003.emz", App.Path & "\image003.png", 480
      EMZ2PNG App.Path & "\image005.emz", App.Path & "\image005.png", 480
      
      'now show a preview for one of the converted Images
      Set Picture = Cairo.ImageList.AddImage("", App.Path & "\image003.png").Picture
    End Sub
    
    Private Sub EMZ2PNG(EMZFile As String, PNGFile As String, ByVal DstHeightPxl As Long)
      Dim BCmp() As Byte, BDec() As Byte, EMFPage As cReportPage, Srf As cCairoSurface
          BCmp = New_c.FSO.ReadByteContent(EMZFile) 'read the entire File into a Byte-Array
      
      New_c.Crypt.GzDecompress BCmp, BDec 'decode the ByteArray with the GZ-Decompression-algo
    
      'create a new ReportPage-instance (cReportPage is handling EMF internally)
      Set EMFPage = New_c.ReportPage
          EMFPage.EMFContent = BDec 'provide the GZ-Decoded EMF-bytes as the Page-content
        
      'prepare an oversized Cairo-Surface for as a target for the EMF-rendering
      Set Srf = Cairo.CreateWin32Surface(3.3 * DstHeightPxl * EMFPage.AspectRatio, 3.3 * DstHeightPxl)
          Srf.CreateContext.Paint 1, Cairo.CreateSolidPatternLng(vbWhite)
      EMFPage.RenderTo Srf.GetDC, 0, 0, Srf.Width, Srf.Height 'render the EMF onto the CairoSrf
      With Srf.CreateContext 'correct the missing Alpha-Info on the just rendered EMF-content
        .Operator = CAIRO_OPERATOR_DEST_ATOP
        .Paint 1, Cairo.CreateSolidPatternLng(vbBlack)
      End With
     
      'finally a high-quality downstretching from the oversized Cairo-Surface to a smaller one
      With Cairo.CreateSurface(DstHeightPxl * EMFPage.AspectRatio, DstHeightPxl).CreateContext
        .RenderSurfaceContent Srf, 0, 0, .Surface.Width, .Surface.Height, CAIRO_FILTER_GAUSSIAN
        .Surface.WriteContentToPngFile PNGFile
      End With
    End Sub
     
    Private Sub Form_Terminate()
      New_c.CleanupRichClientDll
    End Sub
    Here's a preview of the green-circle after conversion (from one of those EMZs, which were created during HTML-export).


    Olaf

  37. #37

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    I tesed WPS, WPS can be high-fidelity to read all the information in the clipboard.

    I compared the first picture in WPS and MS Word, found that there is still a very small difference between the two images, may be their anti-aliasing algorithm is somewhat different.

    I guess WPS work is like this:
    (1) First, parse the Clipboard data format
    (2) Redraw all the text, pictures and other objects to the wps-editor.

    That is, if we can analyze the format of the ClipBoard thoroughly, we can also redraw all the rich-text (include text and images) on our device(vbform, picturebox or memory device).

  38. #38
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,735

    Re: How to change the specified color in the picture to another color?

    Like others have asked before, can you please explain what the purpose is of your application and what workflow you have chosen?
    Maybe you are trying to fix something which can be solved in a complete different way.

  39. #39

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by dilettante View Post
    I guess what I was wondering is why Word or any other word processor is part of the problem at all if this is about capturing information to be stored in a database. What happens if the source is copied from an open PDF document or an HTML web page? Don't you face similar issues?
    I just use the Windows clipboard to exchange data between different applications. MS-Word is one of the data sources, and in the future, I also need to copy data from Web pages, PDFs or other applications.

    Windows clipboard is super powerful, it's the ideal data caching tools and exchange tools. I just do not know enough about it now.


    Quote Originally Posted by dilettante View Post
    So to get even a little bit closer to Word capabilities you need a 3rd party "RichTextBox" or a lot of code to create your own in VB6 or C++ that wraps the RichEdit 4.1 version inside Msftedit.dll instead of the older Riched20.dll.
    I don't know how to use RichEdit 4.1 to replace Riched20.dll but I will try it.


    Quote Originally Posted by dilettante View Post
    It seems like you want to use RichTextBox as both a paste/drop target and a display control for the pasted/dropped data and probably for such data retrieved from your database later. I'm not sure that even a RichEdit 4.1 is going to do everything you want.

    But at this point we don't know what you want to do, only how you have decided to do it.

    To use the travel analogy again, if we knew where you are starting from and where you are trying to get to we might be able to suggest another route. Is copy/pasting from Word a requirement or just something you chose hoping it might help?
    Rich-Text (text and picture) format will be used in many cases, and now I use it to enter text data and picture data, and save it to the database. In the future, I also need to use it to save product design drawings, exam-papers, Web pages, instant messages and many other information.

    If we can effectively combine RichTextBox and clipboard, it will be very convenient for us to work.

    I will continue to study the TOM and clipboard, and strive to find a good solution, developing a simple editor that can read MS Word doc is also one of the options, hoping to get you more help. thanks very much.
    Last edited by dreammanor; Mar 6th, 2017 at 09:15 AM.

  40. #40

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: How to change the specified color in the picture to another color?

    Quote Originally Posted by Schmidt View Post
    @the OP
    FWIW, here's a Cairo-based EMZtoPNG-converter (although we still don't know, what the whole exercise really is for).

    Code:
    Option Explicit
    
    Private Sub Form_Load()
      EMZ2PNG App.Path & "\image001.emz", App.Path & "\image001.png", 480
      EMZ2PNG App.Path & "\image003.emz", App.Path & "\image003.png", 480
      EMZ2PNG App.Path & "\image005.emz", App.Path & "\image005.png", 480
      
      'now show a preview for one of the converted Images
      Set Picture = Cairo.ImageList.AddImage("", App.Path & "\image003.png").Picture
    End Sub
    
    Private Sub EMZ2PNG(EMZFile As String, PNGFile As String, ByVal DstHeightPxl As Long)
      Dim BCmp() As Byte, BDec() As Byte, EMFPage As cReportPage, Srf As cCairoSurface
          BCmp = New_c.FSO.ReadByteContent(EMZFile) 'read the entire File into a Byte-Array
      
      New_c.Crypt.GzDecompress BCmp, BDec 'decode the ByteArray with the GZ-Decompression-algo
    
      'create a new ReportPage-instance (cReportPage is handling EMF internally)
      Set EMFPage = New_c.ReportPage
          EMFPage.EMFContent = BDec 'provide the GZ-Decoded EMF-bytes as the Page-content
        
      'prepare an oversized Cairo-Surface for as a target for the EMF-rendering
      Set Srf = Cairo.CreateWin32Surface(3.3 * DstHeightPxl * EMFPage.AspectRatio, 3.3 * DstHeightPxl)
          Srf.CreateContext.Paint 1, Cairo.CreateSolidPatternLng(vbWhite)
      EMFPage.RenderTo Srf.GetDC, 0, 0, Srf.Width, Srf.Height 'render the EMF onto the CairoSrf
      With Srf.CreateContext 'correct the missing Alpha-Info on the just rendered EMF-content
        .Operator = CAIRO_OPERATOR_DEST_ATOP
        .Paint 1, Cairo.CreateSolidPatternLng(vbBlack)
      End With
     
      'finally a high-quality downstretching from the oversized Cairo-Surface to a smaller one
      With Cairo.CreateSurface(DstHeightPxl * EMFPage.AspectRatio, DstHeightPxl).CreateContext
        .RenderSurfaceContent Srf, 0, 0, .Surface.Width, .Surface.Height, CAIRO_FILTER_GAUSSIAN
        .Surface.WriteContentToPngFile PNGFile
      End With
    End Sub
     
    Private Sub Form_Terminate()
      New_c.CleanupRichClientDll
    End Sub
    Olaf
    Excellent. VbRichClient5 can be perfect to read EMZ file format, which is really useful. I will study it carefully, thanks very much.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by dreammanor; Mar 6th, 2017 at 08:36 AM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width