Dear all Master,
I'm a newbie on vb.net.
I need help converting the code below to vb.net and also teach me how to run the code properly in vb.net.
If there is a misunderstanding, you can ask me. For the record I'm using vs 2010. to run the process requires a library. You can request me so I share the
The following example demonstrates usage of InputImageFile class. The code collects all JPEG images from the specifed directory and prepares them for watermarking.
try
{
Watermarker w = new Watermarker("demo", "demo");
List<InputImageFile> inputImages = new List<InputImageFile>();
You've made no effort to convert the code, despite the fact that you can read it for yourself and/or use various online and downloadable code converters. How about you make the effort to do what you can for yourself first and then come here with a specific question about a specific line or two of code that you don't understand. This site is not here to get people to do your work so you don't have to. It's to help with stuff that you can't do for yourself but, if you don't even try, you have no idea what you can and can't do for yourself. If you're not going to make an effort on your own behalf, why should we make an effort?
dear all master,
I've converted the code to vb.net. there is an error "add' is not a member of 'System.Array' in vb.net". Below is my convert code.
Code:
Imports System.IO
Imports Bytescout.Watermarking
Imports System.Collections.Generic
Imports System.Windows.Forms
Module Module1
Sub main()
Try
Dim w As Watermarker = New Watermarker("demo", "demo")
Dim twm As TextWatermark = New TextWatermark
Dim inputImages As List(Of InputImageFile) = New List(Of InputImageFile)
Dim imageFiles() As String = System.IO.Directory.GetFiles("C:\emp\input", "*.png", System.IO.SearchOption.AllDirectories)
For Each filename As String In imageFiles
w.InputImages.add(New InputImageFile(filename, Path.GetFileName(filename)))
'twm.Text = "Copyright � John Doe, 2008"
'w.OutputOptions.OutputDirectory = "c:\emp\output"
'w.Execute()
Next
Catch e As System.Exception
MessageBox.Show(e.Message)
End Try
'w.AddInputFile("c:\emp\input\image1.jpg", "image1_watermarked.jpg")
'Dim twm As TextWatermark = New TextWatermark
'twm.Text = "Copyright � John Doe, 2008"
'twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
'twm.TextColor = Color.Red
'twm.Transparency = 40
'twm.Alignment = TextAlignment.Center
'twm.Placement = WatermarkPlacement.BottomRight
'twm.Margins = New WatermarkMargins(20, 20, 20, 20)
'w.AddWatermark(twm)
'w.OutputOptions.OutputDirectory = "c:\emp\output"
'w.Execute()
'Catch e As System.Exception
'MessageBox.Show(e.Message)
'End Try
End Sub
End Module
You've made no effort to convert the code, despite the fact that you can read it for yourself and/or use various online and downloadable code converters. How about you make the effort to do what you can for yourself first and then come here with a specific question about a specific line or two of code that you don't understand. This site is not here to get people to do your work so you don't have to. It's to help with stuff that you can't do for yourself but, if you don't even try, you have no idea what you can and can't do for yourself. If you're not going to make an effort on your own behalf, why should we make an effort?
dear sir,
I've converted the code to vb.net. there is an error "add' is not a member of 'System.Array' in vb.net". Below is my convert code.
thanks
So why did it take until post #5 for that to happen? You obviously were capable of doing more for yourself than you initially indicated. Hopefully you will do all you can before posting in future.
As for the issue, maybe you could indicate exactly where the error occurs in the code, rather than expecting us to trawl through the code and work it out for ourselves. You could bold the line or colour it, or copy it and post it separately. Again, you can make an effort to make it as easy as possible for us to help you. The less effort you make, the less effort we'll be inclined to make.
You have provided no indication where that Watermarker type comes from but it would appear that you have reproduced it incorrectly. If the original C# code actually worked:
then that Watermarker.InputImages must be a collection of some sort, rather than an array. I did a web search for "Watermarker.InputImages" and found nothing, so I have no idea what it actually is but I can tell you that it can't be an array or that original code simply wouldn't have compiled, the same way yours won't compile. Where did this code come from in the first place?
Dear sir,
thanks for your reply
I got the original code from the documentation. I attached a screenshot of the original source code.
Below I marked the red color of the problem code,
thanks
Based on the second code snippet, it looks like Watermark.InputImages property may actually expose an array and that array gets created and populated internally when you call the AddInputFile method.
Basically, I think that you should ignore the first code snippet and just use the second. It watermarks a bunch of image files and that's what you want to do, I assume, so that's what you should do.
Based on the second code snippet, it looks like Watermark.InputImages property may actually expose an array and that array gets created and populated internally when you call the AddInputFile method.
Basically, I think that you should ignore the first code snippet and just use the second. It watermarks a bunch of image files and that's what you want to do, I assume, so that's what you should do.
dear sir
thanks for your reply. I share the code after I modified it according to your instructions.
but I still have a problem I marked it with a red marking in the code below.
thanks
Code:
Sub main()
Try
Dim w As Watermarker = New Watermarker("demo", "demo")
Dim twm As TextWatermark = New TextWatermark
Dim inputImages As List(Of InputImageFile) = New List(Of InputImageFile)
Dim imageFiles() As String = System.IO.Directory.GetFiles("C:\emp\input", "*.png", System.IO.SearchOption.AllDirectories)
For Each filename As String In imageFiles
inputImages.Add(New InputImageFile(filename, Path.GetFileName(filename)))
w.AddInputFile()
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = "c:\emp\output"
w.Execute()
Next
Catch e As System.Exception
MessageBox.Show(e.Message)
End Try
'w.AddInputFile("c:\emp\input\image1.jpg", "image1_watermarked.jpg")
'Dim twm As TextWatermark = New TextWatermark
'twm.Text = "Copyright � John Doe, 2008"
'twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
'twm.TextColor = Color.Red
'twm.Transparency = 40
'twm.Alignment = TextAlignment.Center
'twm.Placement = WatermarkPlacement.BottomRight
'twm.Margins = New WatermarkMargins(20, 20, 20, 20)
'w.AddWatermark(twm)
'w.OutputOptions.OutputDirectory = "c:\emp\output"
'w.Execute()
'Catch e As System.Exception
'MessageBox.Show(e.Message)
'End Try
End Sub
End Module
Do they really look similar? You don't need the List so get rid of it. When you call AddInputFile, you need to pass the appropriate arguments. Put the call to AddInputFile inside the loop and pass the appropriate values for the current file.
Do they really look similar? You don't need the List so get rid of it. When you call AddInputFile, you need to pass the appropriate arguments. Put the call to AddInputFile inside the loop and pass the appropriate values for the current file.
Dear sir,
after I learned I've tried the code and it worked. how to code if i want to change change to openfiledialog in windows form.
thanks
Code:
Sub main()
Try
Dim w As Watermarker = New Watermarker("demo", "demo")
Dim twm As TextWatermark = New TextWatermark
Dim inputImages As List(Of InputImageFile) = New List(Of InputImageFile)
Dim imageFiles() As String = System.IO.Directory.GetFiles("C:\emp\input", "*.png", System.IO.SearchOption.AllDirectories)
For Each filename As String In imageFiles
inputImages.Add(New InputImageFile(filename, Path.GetFileName(filename)))
w.AddInputFile(filename)
twm.Text = "Copyright � John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = "c:\emp\output"
w.Execute()
Next
Catch e As System.Exception
MessageBox.Show(e.Message)
End Try
End Sub
You need to stop thinking about how turn an idea into code and start thinking about logic and how to implement it in code. You already know how to loop over a list of file paths and you're already doing that in your code. All you need to do is get a list of file paths from an OpenFileDialog and use that instead of the list you already have. There are loads of examples around of getting a list of file paths from an OpenFileDialog so you don't need me to tell you how to do that. Think about the logic and then write code to implement that logic. That's what I've been trying to get you to do all along and you have written all that code on your own that you assumed that you couldn't to start with. You just need to put in a little more thought and you'll get yourself the rest of the way.
That said, why do you still have the List(Of InputImageFile) in there? What's that actually doing? Again, if you consider the logic first and then write the code to implement the logic then you won't write code to do totally useless things because those things won't be part of the logic.
You need to stop thinking about how turn an idea into code and start thinking about logic and how to implement it in code. You already know how to loop over a list of file paths and you're already doing that in your code. All you need to do is get a list of file paths from an OpenFileDialog and use that instead of the list you already have. There are loads of examples around of getting a list of file paths from an OpenFileDialog so you don't need me to tell you how to do that. Think about the logic and then write code to implement that logic. That's what I've been trying to get you to do all along and you have written all that code on your own that you assumed that you couldn't to start with. You just need to put in a little more thought and you'll get yourself the rest of the way.
That said, why do you still have the List(Of InputImageFile) in there? What's that actually doing? Again, if you consider the logic first and then write the code to implement the logic then you won't write code to do totally useless things because those things won't be part of the logic.
dear sir,
"Dim inputImages As List(Of InputImageFile) = New List(Of InputImageFile)" if I don't I use the code even though the output is successful but still the error "add' is not a member of 'System.Array' so I have to use that code so there is no such error.
dear sir,
"Dim inputImages As List(Of InputImageFile) = New List(Of InputImageFile)" if I don't I use the code even though the output is successful but still the error "add' is not a member of 'System.Array' so I have to use that code so there is no such error.
thanks
It's like you just forgot everything we've discussed up to now. The reason you don't get that error now is that you're doing this:
That has got exactly ZERO to do with the List(Of InputImageFile). Get rid of that List. It does nothing useful.
Dear sir,
this is the final code :
Code:
Sub main()
Try
Dim w As Watermarker = New Watermarker("demo", "demo")
Dim twm As TextWatermark = New TextWatermark
Dim imageFiles() As String = System.IO.Directory.GetFiles("C:\emp\input", "*.png", System.IO.SearchOption.AllDirectories)
For Each filename As String In imageFiles
w.AddInputFile(filename)
twm.Text = "Copyright John Doe, 2008"
twm.Font = New WatermarkFont("Arial", FontStyle.Bold, FontSizeType.Percents, 2)
twm.TextColor = Color.Red
twm.Transparency = 40
twm.Alignment = TextAlignment.Center
twm.Placement = WatermarkPlacement.BottomRight
twm.Margins = New WatermarkMargins(20, 20, 20, 20)
w.AddWatermark(twm)
w.OutputOptions.OutputDirectory = "c:\emp\output"
w.Execute()
Next
Catch e As System.Exception
MessageBox.Show(e.Message)
End Try
End Sub