saving google map to image from a browser component window inside a c# application - google-maps

I wanted to save the google map into an image from a webpage.
while i was searching for that i got this program.
http://www.codres.de/downloads/gms.exe[^]
besides other alternatives like print screen i wanted to use a program or map api which can save a specified dimension of google map instead of the screen.
i have used browser component in c# for http access and for displaying certain webpages.
I want to know whether there are options to capture the browser screen to image using any c# functionality or even the browser component would have given such options. just a guess.
i would like to have answers, suggestions on how to capture the map with custom dimension and zoom size to an image.

I used this to get captcha Image from the current page, so you can use similar code just amend the imageID to point to the google map image and use this solution for zooming.
public string newsavefunction(WebBrowser webBrowser1)
{
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
string imagename = string.Empty;
try
{
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
bmp.Save(#"F:\captchaimages\captchapic.jpg");
}
imagename = img.nameProp;
break;
}
}
catch (System.Exception exp)
{ }
return imagename;
}

Related

Is there a way to get a MediaStream from an URL without creating a video tag

From https://stackoverflow.com/a/21227589/130910:
var stream = videoTag.captureStream()
But I don't want to have to create the tag.
I want to do this because my stream may be from a webcam or a video, and when it's a webcam, I am setting the videoTag.srcObject to the result of navigator.mediaDevices.getUserMedia(...). So it makes the API clunky.
I want to do:
const stream = getStreamFromLocalVideoOrWebcam()
videoTag.src = stream
Is this possible? What is the best approach?
I want to do this because my stream may be from a webcam or a video
I'll take that to mean you have a MediaStream (from getUserMedia/webcam), or a URL (pointing at a video).
If you actually have a MediaStream, you should be setting the srcObject, as you are now. If you have a URL, you should be using the src property instead. So, the design of the return value of your function getStreamFromLocalVideoOrWebcam() is flawed.
You could always do something like this instead:
function setVideoSource(videoEl) {
if (... something ...) {
videoEl.src = someVideoUrl;
} else {
videoEl.srcObject = navigator.mediaDevices.getUserMedia(...);
}
}
const videoEl = document.createElement('video');
setVideoSource(videoEl);

Yii2 - Image upload and resizing,ajax upload support extension

Is there any good image uploading and resize extension for yii2; I don't want to use kartik because since I had a problem I've not gotten any help to understand where the problem is, same situation with Illustrated behavior so I am stack in my project.
What I want is multiple image uploading,ajax support(even for old browser if not to turn to normal file input), image resizing keeping good quality,allowing one image to be saved in different sizes and Preview the file when selected from client side(not obliged).
Usually I use image magick direcly.
Check if these two functions can be useful for you:
public static function generateImagesScaledAndCropped($inputFile, $outputFile, $params)
{
$imageMagickConvert = \Yii::$app->params['imagick.convert'];
$cmd = sprintf("%s %s -resize %dx%d^ -gravity Center -crop %dx%d+0+0 %s", $imageMagickConvert, $inputFile, $params['edge'], $params['edge'], $params['edge'], $params['edge'], $outputFile);
exec($cmd);
}
public static function generateImagesScaledByWidth($inputFile, $outputFile, $params)
{
$imageMagickConvert = \Yii::$app->params['imagick.convert'];
$cmd = sprintf("%s %s -resize %d %s", $imageMagickConvert, $inputFile, $params['width'], $outputFile);
exec($cmd);
}
Params are:
<?php
return [
'imagick.convert' => '/usr/bin/convert',
'imagick.composite' => '/usr/bin/composite',
];
I use Imagine as abstract layer on Imagine library which
uses populars php libraries to work with images
http://www.yiiframework.com/doc-2.0/ext-imagine-index.html

How can I embed a Google Map in Streetview mode with an iframe?

When I pull up a Google Map, there is a little gear icon near the bottom-right that allows me to share. It includes finding an embeddable <iframe>. However, once I go into Streetview this gear icon disappears.
How can I embed the streetview version of the map?
It appears the problem is that the new google maps does not have a way to embed.
If you click on the in the bottom right corner while NOT in pano / street view mode you can revert to classic maps
Then you'll see
from there you can select embed frame.
When you're in the Streeview mode, click on the "link button" next to the print button. You'll have an iframe and a link to customize and preview it.
Since Google changed in the past two years I'll post an answer that shows how to embed Street View with the new Maps.
Enter in Street View Mode with the best view you want
Click those "three dots" on the top left corner of the screen
Click "Share or Embed Image"
Click on the tab "Embed Image" and copy/paste the code
of the iframe
its too simple .just go to link below https://developers.google.com/maps/documentation/javascript/examples/streetview-embed
copy the html+javascript code into your page and modify the div style (by default it goes full screen) having id= map-canvas
now go to the desired street view and copy the latitude,longitude in the url then replace in your code in initialize function latling(latitude,longitude) done!!!! happy to post my first answer stack overflow has answered me so many times
If you are looking for a more generic way, for example to display embedded streetview based on the regular google map link or coordinates. Here is my solution:
Extract coordinates from a regular link
export const getCoordinatesFromGoogleMapURL = (url: string) => {
if (!url) {
return undefined
}
const urlParts = url.split('/#')[1]?.split(',')
if (!(urlParts && urlParts?.length > 1)) {
return undefined
}
const gpsX = parseFloat(urlParts[0])
const gpsY = parseFloat(urlParts[1])
if (isNaN(gpsX) || isNaN(gpsY)) {
return undefined
}
return [gpsX, gpsY] as [number, number]
}
Generate embed url from coordinates:
export const generateGoogleMapEmbedUrl = (coordinates: [number, number]) => {
if (!coordinates) {
return undefined
}
const baseUrl = "https://www.google.com/maps/embed/v1/streetview"
const coordinatesString = `${String(coordinates[0])},${String(coordinates[1])}`
const url = `${baseUrl}?key=${process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY}&location=${coordinatesString}`
return url
}
Finally we can put it together:
export function convertToEmbedURL(url: string): string {
const coordinates = getCoordinatesFromGoogleMapURL(url)
const embedUrl = generateGoogleMapEmbedUrl(coordinates)
return embedUrl;
}
You can read the official docs to find out more about params etc: https://developers.google.com/maps/documentation/embed/embedding-map#streetview_mode

Loading local image from Isolated Storage to html page

There's something strange and wired with the "image path" when using it in html page from IsolatedStorage.
I want to create an html-page, that will be used by app's webBrowser object. So I create an html page in IsolatedStorage and then use this page with webBroswser.Navigate.
Everything works fine except the images.
1) If I create an html page and images at the root of IsolatedStorage, everything works fine, the code <img src="image.png"> works and I can see the image at page page.
2) However, the way of saving pages and images at root is not a good idea in my opinion as I already have a number of directories, used by app there, so, I create a new directory "Html" and save all pages there.
Now, when I open this page I can't see my image. I've tried several variations of src links and still can't find an answer.
What'll be the correct link in <img src=..."> tag, if the hierarchy is:
IsolatedStorage-->Html(folder)-->index.html(file)
(1) IsolatedStorage-->Html(folder)-->image.png(file)
(2) IsolatedStorage-->Html(folder)-->Images(folder)-->image.png(file)
Actually, I thought it would be something like <img src="image.png"> for (1), but I tried several similar versions and none of them worked.
Well, that seems a bit strange:
This method will save the picture to the IsolatedStorage, but won't allow to use it in html img tag:
using (IsolatedStorageFile isopicsFile = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isopicsFile.FileExists(Constants.HtmlFolderName + "launch.png") == false)
{
Stream yourFilepath = Application.GetResourceStream(new Uri("/someUri/launch.png", UriKind.Relative)).Stream;
BitmapImage b = new BitmapImage();
b.SetSource(yourFilepath);
WriteableBitmap wb = new WriteableBitmap(b);
using (var isoFileStream = isopicsFile.CreateFile(Constants.HtmlFolderName + "launch.png"))
{
var width = wb.PixelWidth;
var height = wb.PixelHeight;
// Theoretically, there may be the problem, as the file extention is png, not jpg
System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, isoFileStream, width, height, 0, 100);
}
}
}
And this one will save the picture and will allow to use it with html tags:
string f = "somePath/launch.png";
StreamResourceInfo sr = Application.GetResourceStream(new Uri(f, UriKind.Relative));
using (BinaryReader br = new BinaryReader(sr.Stream))
{
byte[] data = br.ReadBytes((int)sr.Stream.Length);
string fileName = "launch.png";
string filePath = Constants.HtmlFolderName + fileName;
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoStore.FileExists(filePath))
{
isoStore.DeleteFile(filePath);
}
using (BinaryWriter bw = new BinaryWriter(isoStore.CreateFile(filePath)))
{
bw.Write(data);
bw.Close();
}
}
}
Also, in second case, the picture properties must be set to Content + Always Copy.

LibTiff.NET append mode bug?

I've started using LibTiff.NET for writing tiff IPTC tags lately and discovered strange behavior on some files that i have here. I'm using sample code that ships with LibTiff.NET binaries, and it works fine with most of the images, but some files are having image data corruption after these lines:
class Program
{
private const TiffTag TIFFTAG_GDAL_METADATA = (TiffTag)42112;
private static Tiff.TiffExtendProc m_parentExtender;
public static void TagExtender(Tiff tif)
{
TiffFieldInfo[] tiffFieldInfo =
{
new TiffFieldInfo(TIFFTAG_GDAL_METADATA, -1, -1, TiffType.ASCII,
FieldBit.Custom, true, false, "GDALMetadata"),
};
tif.MergeFieldInfo(tiffFieldInfo, tiffFieldInfo.Length);
if (m_parentExtender != null)
m_parentExtender(tif);
}
public static void Main(string[] args)
{
// Register the extender callback
// It's a good idea to keep track of the previous tag extender (if any) so that we can call it
// from our extender allowing a chain of customizations to take effect.
m_parentExtender = Tiff.SetTagExtender(TagExtender);
string destFile = #"d:\00000641(tiffed).tif";
File.Copy(#"d:\00000641.tif", destFile);
//Console.WriteLine("Hello World!");
// TODO: Implement Functionality Here
using (Tiff image = Tiff.Open(destFile, "a"))
{
// we should rewind to first directory (first image) because of append mode
image.SetDirectory(0);
// set the custom tag
string value = "<GDALMetadata>\n<Item name=\"IMG_GUID\">" +
"817C0168-0688-45CD-B799-CF8C4DE9AB2B</Item>\n<Item" +
" name=\"LAYER_TYPE\" sample=\"0\">athematic</Item>\n</GDALMetadata>";
image.SetField(TIFFTAG_GDAL_METADATA, value);
// rewrites directory saving new tag
image.CheckpointDirectory();
}
// restore previous tag extender
Tiff.SetTagExtender(m_parentExtender);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
After opening i see mostly blank white image or multiple black and white lines instead of text that have been written there (i don't need to read\write tags to produce this behavior). I noticed this happens when image already has a custom tag (console window alerts about it) or one of tags have got 'bad value' (console window in this case says 'vsetfield:%pathToTiffFile%: bad value 0 for "%TagName%" tag').
Original image: http://dl.dropbox.com/u/1476402/00000641.tif
Image after LibTiff.NET: http://dl.dropbox.com/u/1476402/00000641%28tiffed%29.tif
I would be grateful for any help provided.
You probably should not use CheckpointDirectory method for files opened in append mode. Try using RewriteDirectory method instead.
It will rewrite the directory, but instead of place it at it's old
location (as WriteDirectory() would) it will place them at the end of
the file, correcting the pointer from the preceeding directory or file
header to point to it's new location. This is particularly important
in cases where the size of the directory and pointed to data has
grown, so it won’t fit in the space available at the old location.
Note that this will result in the loss of the previously used
directory space.