I am using the DevExpress XtraMap MapControl within a windows service with the intention of generating the maps, saving them as images and adding them to reports. I have this setup working well when using it through a WinForms project, but when I copy the same code to a Windows Service it fails to save the image. Code in the WinForms project:
MapControl map;
public void Form1_Load_1(object sender, EventArgs e)
{
// Create a map control.
map = new MapControl();
// Create an image tiles layer and add it to the map.
ImageTilesLayer tilesLayer = new ImageTilesLayer();
tilesLayer.DataLoaded += Map_DataLoaded;
map.Layers.Add(tilesLayer);
BingMapDataProvider prov = new BingMapDataProvider();
prov.BingKey = "MY_BING_KEY";
tilesLayer.DataProvider = prov;
map.ZoomLevel = 2;
map.CenterPoint = new GeoPoint(38, -100);
map.ResumeRender();
this.Controls.Add(map);
}
private void Map_DataLoaded(object sender, EventArgs e)
{
var loc = #"C:\0Temp\Map\" + DateTime.Now.Ticks.ToString() + ".png";
map.ExportToImage(loc, System.Drawing.Imaging.ImageFormat.Png);
}
This code when run in a Windows service fails to save the image. The only difference being, in the Windows Service, the following line is removed:
this.Controls.Add(map);
When removing that line from the winforms project, it also fails to load/save. I can only assume that there is an event being triggered/monitored that adding this control to a form triggers that I am not aware of?
I believe, the Map Control is not intended to be used without showing it (or at least without creating it's handle). So when accessing to Bing Maps from Windows-service, I suggest you to use the Bing Imagery API directly.
p.s. Microsoft Bing Maps Terms of Use do not allow to
3.2 (b) Copy, store, archive, or create a database of the Content ...
Related
Good afternoon,
I am trying to use Eyeshot in a .NET Framework Web Application to create a Bitmap image. The steps of the process in my code are the following: I generate all the necessary Entities and then I add them to a Model control that is not visible in the Web Application; once all Entities are added, I use the ZoomFit() method to zoom to the desired Entities and then I use the RenderToBitmap() method to create the Bitmap image.
The issue regards the ZoomFit() method: when executed, it gives the following error message:
"Control's handle must be created first".
The portion of code regarding the creation of the Model control is the following:
Model model1 = new Model();
model1.InitializeViewports();
model1.Size = new Size(500, 300);
model1.CreateControl();
model1.Layers.Add("Grid");
model1.Layers["Grid"].LineWeight = 0.3f;
model1.Layers["Grid"].Color = Color.LightGray;
model1.Layers.Add("Gauges");
model1.Layers["Gauges"].LineWeight = 1.5f;
// List of entities for correct zooming
IList<Entity> Grid = new List<Entity>();
IList<Entity> Gauges = new List<Entity>();
// List of strings containing the paths to the dxf files on the server
List<string> drawingsFilePaths = (List<string>)Session["drawingsFilePaths"];
// List of images
List<Bitmap> drawings = new List<Bitmap>();
foreach (string path in drawingsFilePaths)
{
// Clearing the entities every time I change the file
model1.Entities.Clear();
// Creating the viewport starting from the dxf files
ReadAutodesk read = new ReadAutodesk(path);
read.DoWork();
foreach (Entity en in read.Entities)
{
if (en.LayerName == "Grid")
{
Grid.Add(en);
}
else if (en.LayerName == "Gauges")
{
Gauges.Add(en);
}
model1.Entities.Add(en);
}
model1.ActiveViewport.OriginSymbol.Visible = false;
model1.ActiveViewport.ViewCubeIcon.Visible = false;
model1.ActiveViewport.ToolBar.Visible = false;
model1.ActiveViewport.SetView(viewType.Right);
model1.ZoomFit(Gauges, false);
Bitmap tmp = model1.RenderToBitmap(1);
drawings.Add(tmp);
However, this issue is faced ONLY when publishing the Web Application on a remote Server (Windows Server 2012); in fact, when I publish it using my own personal computer (Windows 10) as a server, everything works perfectly.
I already checked the presence of all the Eyeshot DLLs in the pubblished Web Application, and the settings of IIS on my PC and on the Server are the same. Could it be an issue related to some missing references that are implicitly called by Eyeshot DLLs and are not present on Windows Server? What do you think is the problem?
Kind regards,
Giacomo Balestrieri
This is a licensing issue. Eyeshot Trial version cannot be copied on other machines. The same problem would occur if you copy your app to a different Win10 machine.
I writing Windows Forms Application application which should show image on the PictureBox control.
To retrieve this image from DICOMDIR file I use fo-dicom library (driven by this guide):
....
private void MainForm_Load(object sender, EventArgs e)
{
ImageManager.SetImplementation(WinFormsImageManager.Instance);
}
....
// this function is just for example
// real function is bit complicated
private void ShowImage()
{
// Getting DICOM file, retrieving all info from it
// Getting dicomDataset instance
....
var id = dicomDataset.Get<string>(DicomTag.ReferencedFileID, -1);
var dicomImage = new DicomImage(id);
var bitmap = dicomImage.RenderImage().AsBitmap();
pictureBox.Image = bitmap ?? pictureBox.ErrorImage;
}
When image is retrieving all works fine. But as soon as I maximize my MainForm, I got System.ArgumentException with Parameter is not valid message:
It looks like this is a .NET Framework bug, but maybe there is a way to fix it by overrideing OnPaint() method of PictureBox control?
Have anyone see this bug previously?
Thanks in advance.
P.S. During development this project I use following software:
Windows 10 x64
Visual Studio 2017 Community Edition
.NET Framework 4.5.1
fo-dicom version 3.0.2
EDIT #1
The same issue with Panel instead of PictureBox:
You are facing a known and already fixed bug in fo-dicom 3.0.2. See also https://github.com/fo-dicom/fo-dicom/issues/634.
For performance reason the Bitmap, that DicomImage.RenderImage().AsBitmap() returns, does not have its own pixel data, but has a pointer to the bytes of DicomImage. So the AsBitmap() does not duplicate all the pixel data in memory.
But if you instanciate the DicomImage in a local variable and save the Bitmap in the control, then the DicomImage is disposed at the end of the method and the pixel data gets garbace collected. The next time, the Bitmap tries to access the pixel data this exception happens.
The next release will have two methods: AsSharedBitmap() - the same as now but more obvious to the user - and AsClonedBitmap().
The workaround now is, to copy the pixel data manually by calling:
var bitmap = dicomImage.RenderImage().AsBitmap().Clone();
I'm trying to create a windows forms application that can scrub screen information from a Reflections window. The problem is that it's an older version of reflections from back when WRQ still owned the app. Since Attachmate have taken it over, I can't find any documentation on the .net API related to this older version.
What I have so far is this:
private void button1_Click(object sender, EventArgs e)
{
openApp();
}
private void openApp()
{
// Create a new instance of Reflection.
Reflection4.Session reflection = new Reflection4.Session();
reflection.Visible = true;
}
So this is fine for opening a new Reflections window, but I want it to run the screen scrape on a window that is already open.
Below is a way to get the first active Reflection4.Session using Marshal.GetActiveObject(). I found the progid for Reflection4 using the ProgID Key website on MSDN. With that I found that the following code works:
Reflection4.Session session = (Marshal.GetActiveObject("Reflection4.Session.8") as Reflection4.Session);
I couldnt find an answer to this question anywhere so I thought id ask here. Basically Iam following along with channel 9's tutorial on windows 8 phone for absolute beginners. Trying to follow along with the 'Around me' app tutorials. I create a Map element in the xaml. I create a geolocator object and attempt to set the view on my map to my current geocordinates. This doesnt work, the map view seems to show the location of microsofts headquarters in Redmond Washington each time I run the app. not Ireland, where it should be pointing? Below is my code which is all contained in the mainpage.xaml.cs
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
public async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
Geoposition position = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(30));
var GeoCoorCenter = new GeoCoordinate(position.Coordinate.Latitude,position.Coordinate.Longitude);
AroundMeMap.SetView(GeoCoorCenter,17);
}
my code is the same as that used in the tutorial and it seems to work in that app. I also have the ID_CAP_LOCATION and ID_CAP_MAP set in the app manifest. Iam really not sure what the issue is here. Iam assuming its got something to do with the fact that Iam running the application in the emulator. If anyone can help me that would be great.
I've managed to run your code like this (basing on this answer and MSDN howto):
I've started the emulator, opened AdditionalTools -> Location and clicked somewhere on the Map (as my Location)
run Maps App - I see that shows the Location I've set, Close the Maps App
after that your App should point the right Location
As it's written at MSDN - it seems to be a bug which running Maps App fixes.
I am using this code provided here.
http://www.codeproject.com/Articles/18520/Vista-Core-Audio-API-Master-Volume-Control
I am trying to control the volume of my application and 1 additional process that my application starts. Is there a way to use this code above as per application instead of master?
Here is the code in the form
MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
beiVolumControl.EditValue = (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100);
By comments listed there is a way to pick the device using a friendly name but I don't see any examples listed anywhere.
Here is the code used when my volume slider changes
//change the Volume
void ritbVolumeControl_EditValueChanged(object sender, EventArgs e)
{
TrackBarControl trackBar = sender as TrackBarControl;
//only use in vista or above.
if (useAlternateSound == false)
{
device.AudioEndpointVolume.MasterVolumeLevelScalar = ((float)trackBar.Value / 100.0f);
}
else
{
//probably using xp or lower.
}
// MessageBox.Show(trackBar.Value.ToString());
}
The End Goal is to Control my Application and one other process's volume if it's possible without controlling the master volume of all applications. So I can mute them and still use skype voice chat for an example. Am I going about this the wrong way?
Thanks.