How can i show the image name when i taking a picture? - vb.net

Im trying to show the name of the image i take with my Camera but i dont know how.
Do i need a another function to show the image name?
My Code for taking picture:
Public Function takePicture() As String
Dim url = THETA_URL & "commands/execute"
Dim payload = New Dictionary(Of Object, Object) From {
{"name", "camera.takePicture"}
}
Dim request As Net.WebRequest = Net.WebRequest.Create(url)
request.Credentials = New Net.NetworkCredential(THETA_ID, THETA_PASSWORD)
Dim resp As Net.WebResponse = request.GetResponse()
End Function

See the line where is says:
End Function
Look in the line numbers margin; next to it there is a blank bar (mine is dark gray in my theme) - click in it to put a red dot:
End Function will go red too..
Then run your code and retrieve your image. The code will stop with a yellow bar pointing to End Function
Take a look at the bottom of VS - you'll either have an Autos window or a Locals window - either one will do. It will show the response object and you can drill into it like a tree, open the headers collection, have a look if anything in it contains the data you want.. It also thus tells you how to get the data you want out of it..
e.g. if I wanted the "Content-Disposition" value I could say resp.Headers("Content-Disposition") - AllKeys is showing me what available strings I can use to index the headers collection
Content-Disposition probably won't list a filename on its own - it'll be something more involved like "attachment; filename=someimage.jpg" so you'll need to pull the data you want out of it. Don't get your hopes up if this is a basic cam; it's unlikely to have any meaningful sort of filename. It might be IMG_0001 etc, if it's there at all - I think you should instead make your own name up, as you'll be able to put more info into it, it will be more meaningful than what you get from the cam (and if the cam doesn't send a filename you'll have to do it anyway)

Related

How do you add a picture to the ID3 Album tag using taglib#

I've been searching the internet and trying various methods to save a picturbox image to the the id3 Album picture tag. One sample code says the Album cover tag name is taglib.ipicture another says taglibVariable.Image and yet another says taglibVariable.picture(0).
I am becoming so confused I'm starting to repeat sample test code.
Where is the documentation that will explain what I have to do.?
What little information I can find are dead links to sample code or incomplete code using variables without explanations. When I look up the commands and try to format or convert to the needed data type, I get an error. Usually system.image.bmp cannot be converted to iPicture.
Can anyone give me some working code or a pointer on how to word the proper search term to add a picturebox.image to the Album picture tag. Saving the image as a file then opening as image to put in tag then deleting file is not an option. I need to create a memory image and add that to the picture tag.
This is what I use:
public void SavePicture(string fileName, string picName) {
try {
IPicture[] pics = new TagLib.IPicture[1];
pics[0] = new TagLib.Picture(picName);
using (var songTag = TagLib.File.Create(fileName)) {
songTag.Tag.Pictures = pics;
songTag.Save();
}
}
catch {
// process
// mpeg header is corrupt
}
}
fileName is the full path to the audio file;
picName is the full path to the picture.
You can add multiple pics by setting the array size for the IPicture array accordingly...

apply text formatting from string to text for FlowDocument in richtextbox

I know that when adding text/content/DataContext in XAML you refer to resource dictionary or inline mark up for styling around text or in template.
Q:
However I'm having trouble trying to find a way to do the following:
Data is coming from a View Model/Model that is pulled from a database.
(string value)
I am a <Bold>smart</Bold> man.
to show in a flow document like this:
I am a smart man.
Q end
Either by binding to a converter, behavior, or would saving the paragraph/document that I put in the flow document to a .rtf file in memory stream be a better option?
I've tried to utilize the option for behavior listed > here < but that is for text block and unable to redirect for type text instead of text block.
Trying to make it streamlined.
Tried to use data binding and apply the converter but even though I have the resource for the behavior / converter, it work due to the type conversion.
One clever solution is presented by Rockford Lhotka in post Set rich text into RichTextBlock control. His idea is to create a custom control which then creates the RichTextBlock using XamlReader.Load.
This allows you to use code like the following:
<local:RichTextDisplay Xaml="{Binding Hello}" HorizontalAlignment="Center"
VerticalAlignment="Center"/>
Where Hello is:
public string Hello { get; set; } = "I am a <Bold>smart</Bold> man.";
With a result:
If you use UWP/Win 8.1 XAML, you can use the original code from the blog post with the following small change (Paragraphs added):
<UserControl
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006"">
<Grid>
<RichTextBlock><Paragraph>");
xaml.Append(ctl.Xaml);
xaml.Append(#"
</Paragraph></RichTextBlock>
</Grid>
</UserControl>
");
To answer my own question:
My case was creating a Document style display for user to update and save as a PDF, but I didn't want to rely on Office being on our application Server.
So I resolved this in my case by using a full "doc.RTF" document and importing that as a memory stream/string and apply my needed updates for values to that.
i.e. VB.net snippet example
Using uStream = Assembly.GetExecutingAssembly.GetManifestResourceStream("Resourcefilepath.rtf")
Using mStream As system.IO.MemoeryStream = New MemoryStream()
uStream.CopyTo(mStream)
rtfstring = Encoding.UTF8.GetSTring(mStream.toArray())
'--Do the updates to the needed string as needed:
rtfstring.Replace("Value","UpdatedValue")
'--Load Property Memory String this method is returnind
RTFDataProperty = New MemoryStream(Encoding.UTF8.GetBytes(rtfstring))
End Using
End Using
Then I loaded my XAML Rich Text Box with that memory stream as DataFormats.Rtf.
RichTextBox1.SelectAll()
RichTextBox1.Selection.Load(ClassName.RTFDataProperty, DataFormats.Rtf)
This gave me a template for formatting and layout of that document. (More of a case scenario and not a normal practice)
I also wanted to apply a starting selection so here is what I did there:
'--Get my RichTextBox Text
rtbtext As String = New TextRange(RichTextBox1.Document.contentStart, RichTextbox1.Document.ContentEnd).Text
Dim strStartSelection As String = "Comments..."
Dim startTP As TextPointer
Dim endTP As TextPointer
'--Loop through the paragraphs of the richtextbox for my needed selection starting point:
For Each para As Paragraph In RichTextBox1.Document.Blocks
Dim paraText As String = New TextRange(para.ContentStart, para.ContentEnd).Text
If paraText = "" Then
Dim pos As TextPointer = para.ContentStart
startTP = pos
endTP = startTP.GetPositionAtOffset("".Length + 3) '--my string had ... on the end so had to add for avoiding the escape of that on length
RichTextBox1.Selection.Select(startTP, endTP)
RichTextBox1.Focus()
Exit For
End If
Next
This is the simple VB.net code layout, but you can simplify and adjust from there if you find it useful.
Thanks

VB.NET - How to correctly load a resource icon with API

I need to extract an icon resource from a file. I have a structure (Resource) that contains the byte array, size, find handle, load handle, lock handle (from FindResource, LoadResource and LockResource, respectively).
I know that I need to obtain the Icon handle of my icon. Then I need to use GetIconInfo to retrieve the bit-mask. Then I use Image.FromHbitmap(h) to get an image. I then use the dimensions of the image as parameters to CreateIconFromResourceEx to retrieve a properly sized Icon.
Does anyone have some code to do this? I can declare all P/Invoke myself. Thanks!
My original code is returning a 32x32 every time.
Dim out As ICONINFO
Dim h As IntPtr = res.hLock
GetIconInfo(h, out)
Dim s As Image = Image.FromHbitmap(out.hbmMask)
h = ResourceExplorer.CreateIconFromResourceEx(res.bArray, res.hSize, True, &H30000, s.Width, s.Height, 0)
PictureBox1.Image = Icon.FromHandle(h).ToBitmap

How can I get a list of URLs of all images that appear on a webpage?

I'm trying to use VB.NET (2010) to get the absolute URLs of each image that appears on a specific webpage. So far, I've figured out how to get all of the URLs inside of an image tag, like so...
For Each SeparateImage As HtmlElement In WebBrowser1.Document.Images
ListBox1.Items.Add(SeparateImage.GetAttribute("src"))
Next
That works perfectly. But what I can't figure out is how to extract image URLs that appear within CSS styles. For example...
background-image:url('image.jpg');
Does anyone know of a simple way to do this? I would need to extract the image URLs not only from inline CSS code, but from external stylesheets as well.
I reckon that one way to do it would be to grab the source code of the entire HTML page page and related CSS stylesheet, and then parse out all of the image URLs using a bunch of string splits and/or regex. But that could get pretty complicated to figure out the correct absolute URL of each image, because of all the different possibilities of "relative" URL paths I may come across. For example...
background-image:url('image.jpg');
background-image:url('/image.jpg');
background-image:url('./image.jpg');
background-image:url('../image.jpg');
background-image:url('../otherdirectory/image.jpg');
So... it would be really nice if something like this existed...
For Each CSS_Style As HtmlElement In WebBrowser1.Document.Styles
ListBox1.Items.Add(CSS_Style.GetAttribute("background-image"))
Next
Does anyone know how I might be able to accomplish something like that? Or have any other ideas that don't involve mind numbing amounts of regex and logic? :)
Thanks in advance!
If you're specifically looking to avoid "mind numbing amounts of regex and logic", have you considered the HtmlAgilityPack ?
The following brief code should show all image URLs contained within the HTML downloaded from the bbc.co.uk website. It shouldn't be too hard to extend this code to parse the image links from any CSS files that are referenced from the HTML document.
Imports HtmlAgilityPack
Module Module1
Sub Main()
Dim mainUrl As String = "http://www.bbc.co.uk"
Dim doc As HtmlDocument
doc = New HtmlDocument()
Dim sourceString As String = New System.Net.WebClient().DownloadString(mainUrl)
doc.LoadHtml(sourceString)
For Each link As HtmlNode In doc.DocumentNode.SelectNodes("//img[#src]")
Dim linkAddress = GetAbsoluteUrl(link.Attributes("src").Value, mainUrl)
Console.WriteLine("Image: {0}", linkAddress)
Next
End Sub
'
Function GetAbsoluteUrl(partialUrl As String, baseUrl As String)
Dim myUri = New Uri(partialUrl, UriKind.RelativeOrAbsolute)
If (myUri.IsAbsoluteUri = False) Then
myUri = New Uri(New Uri(baseUrl), partialUrl)
End If
GetAbsoluteUrl = myUri
End Function
End Module

Modify HTML in a Internet Explorer window using external.menuArguments

I've got a VB.NET class that is invoked with a context menu extension in Internet Explorer.
The code has access to the object model of the page, and reading data is not a problem. This is the code of a test function...it changes the status bar text (OK), prints the page HTML (OK), changes the HTML by adding a text and prints again the page HTML (OK, in the second pop-up my added text is in the HTML)
But the Internet Explorer window doesn't show it. Where am I doing wrong?
Public Sub CallingTest(ByRef Source As Object)
Dim D As mshtml.HTMLDocument = Source.document
Source.status = "Working..."
Dim H As String = D.documentElement.innerHTML()
MsgBox(H)
D.documentElement.insertAdjacentText("beforeEnd", "ThisIsATest")
H = D.documentElement.outerHTML()
MsgBox(H)
Source.status = ""
End Sub
The function is called like this from JavaScript:
<script>
var EB = new ActiveXObject("MyObject.MyClass");
EB.CallingTest(external.menuArguments);
</script>
To the best of my understanding, in order to use insertAdjacentText or any of the other editing methods, the document object should be in the design mode.
In design mode you can edit the document freely, and so can the user.
Check this site for more details
I do not think that Alex is right, something else is the matter.
When I tried to do something like that, insertBefore would not work for me, but appendChild worked just fine, so adding an element is possible.
I worked in Javascript, but I don't expect that makes a difference.