-
1 Attachment(s)
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
-
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?
-
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.
-
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.
-
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
-
Re: How to change the specified color in the picture to another color?
Awww Shaggy, that's cheating. :)
-
Re: How to change the specified color in the picture to another color?
Quote:
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.
-
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. :)
-
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.
-
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
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Elroy
Awww Shaggy, that's cheating. :)
The first rule of graphics: Cheat whenever possible.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
dreammanor
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
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Peter Swinkels
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
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
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
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
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
I Love VB6
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Schmidt
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.
-
2 Attachment(s)
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.
-
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
-
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
-
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Eduardo-
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
dilettante
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
dreammanor
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.
-
Re: How to change the specified color in the picture to another color?
Thank you, Dilettante. I will continue to do some testing.
-
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.
-
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.
-
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
-
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.
-
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
I Love VB6
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Tanner_H
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).
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
dilettante
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Eduardo-
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.
-
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?
-
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..
-
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
dilettante
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).
http://vbRichClient.com/Downloads/EMZtoPNG.png
Olaf
-
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).
-
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.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
dilettante
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
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
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.
-
2 Attachment(s)
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Schmidt
@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.
-
Re: How to change the specified color in the picture to another color?
Maybe a silly question, but why not use Word documents instead of RTF?
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Arnoutdv
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.
Thanks for your reply. I need to store some information into the database. Some of this information is manually entered, and some are copied from MS-Word or Web-Page. Some pictures are product design drawings, can not be distorted.
-
Re: How to change the specified color in the picture to another color?
But you do everything via the RTB control.
Why not store the originals of pictures/documents?
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Arnoutdv
But you do everything via the RTB control.
Why not store the originals of pictures/documents?
you get out of here with that nonsense... this is a programming forum.
(but seriously. storing original documents and files is how most "real" collaborative project management software works.)
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Arnoutdv
But you do everything via the RTB control.
Why not store the originals of pictures/documents?
In most cases, I just need to keep plain text data, but in a few cases, I also need to save some useful pictures. So I need to separate the text data and image data: all the text data is saved in a DB-Field, and the image data is selected so that only the useful pictures are saved in another DB-Field.
-
Re: How to change the specified color in the picture to another color?
Do you need the complexity of RTF for the information you are storing? Would something simpler like Markdown not suffice? MD wouldn't let you embed the images directly but it would certainly let you link to them if they existed in a file system or could have a valid URL generated for them.
-
Re: How to change the specified color in the picture to another color?
If you need plain text and image data then why store them in the RTB first?
Just get the plain text and use the original image as used in the original document.
If all you have is a hammer, everything looks like a nail
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
DEXWERX
you get out of here with that nonsense... this is a programming forum.
(but seriously. storing original documents and files is how most "real" collaborative project management software works.)
Some customers have not installed MS Word on their computers, but they need to view and edit the data.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
Arnoutdv
When I copy data from Ms Word to RTB, the picture is changed. Please see my post #16.
-
Re: How to change the specified color in the picture to another color?
Then don't copy it to the RTB!
Why do you insist on doing so.
Just use the images from the document.
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
dreammanor
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.
I guess you didn't read my post correctly. I pasted your images (all three) from MS-WORD into RTB and they are exactly the same
-
Re: How to change the specified color in the picture to another color?
Quote:
Originally Posted by
I Love VB6
I guess you didn't read my post correctly. I pasted your images (all three) from MS-WORD into RTB and they are exactly the same
I'm sorry I did not explain it clearly. I mean: when you copy pictures and text at the same time, the color of some pictures will change, and some pictures appear jagged. If you only copy the pictures, then the color of the pictures has not changed, but the pictures are still jagged.
If your computer is not the case, please tell me your Windows version and RichTextBox version, or send a screenshot that pictures and text without distortion, thank you.
In addition, I merged the question into another post:
http://www.vbforums.com/showthread.p...35#post5147035