So klappt’s: Mappoint-Bilder mithilfe von VB.NET extrahieren von Justin James am 3. August 2007 , 14:05 Uhr <br /> Private Sub SaveToImage(ByVal MappointControlMapToSave As AxMapPoint.AxMappointControl, ByVal SaveImageFormat As System.Drawing.Imaging.ImageFormat, ByVal FileName As String, ByVal ImageWidth As Integer, ByVal ImageHeight As Integer)<br /> Dim BitmapSaveToImage As System.Drawing.Bitmap<br /> Dim BitmapOriginalImage As System.Drawing.Bitmap<br /> Dim StringTempMDIImageName As String<br /> Dim StringTempTIFFImageName As String<br /> Dim MODIImageConverter As MODI.Document<br /> Dim StringOriginalActivePrinter As String<br /> StringTempMDIImageName = TempFiles.AddExtension(„mdi“)<br /> StringTempTIFFImageName = TempFiles.AddExtension(„tiff“)<br /> MODIImageConverter = New MODI.Document<br /> StringOriginalActivePrinter = MappointControlMapToSave.ActivePrinter<br /> MappointControlMapToSave.ActivePrinter = „<span class='wp_keywordlink'><a href="https://www.zdnet.de/unternehmen/microsoft/" title="Themenschwerpunkt: Microsoft">Microsoft</a></span> <span class='wp_keywordlink'><a href="https://www.zdnet.de/themen/office-2013/" title="Themenschwerpunkt: Microsoft Office">Office</a></span> Document Image Writer“<br /> MappointControlMapToSave.ActiveMap.PrintOut(StringTempMDIImageName, „“, 1, MapPoint.GeoPrintArea.geoPrintFullPage, MapPoint.GeoPrintQuality.geoPrintQualityPresentation, MapPoint.GeoPrintOrientation.geoPrintAuto, False, False, False, False)<br /> KillTask(„MSPVIEW“, 120)<br /> MappointControlMapToSave.ActivePrinter = StringOriginalActivePrinter<br /> MODIImageConverter.Create(StringTempMDIImageName)<br /> MODIImageConverter.SaveAs(StringTempTIFFImageName, MODI.MiFILE_FORMAT.miFILE_FORMAT_TIFF_LOSSLESS, MODI.MiCOMP_LEVEL.miCOMP_LEVEL_LOW)<br /> MODIImageConverter.Close()<br /> BitmapOriginalImage = New Bitmap(StringTempTIFFImageName)<br /> BitmapSaveToImage = ScaleImage(BitmapOriginalImage, ImageWidth, ImageHeight)<br /> BitmapSaveToImage.Save(FileName, SaveImageFormat)<br /> MappointControlMapToSave = Nothing<br /> BitmapSaveToImage = Nothing<br /> BitmapOriginalImage = Nothing<br /> MODIImageConverter = Nothing<br /> End Sub<br /> Prozesse beenden <br /> Private Sub KillTask(ByVal TaskName As String, Optional ByVal Delay As Integer = 0)<br /> Dim Processes() As Process<br /> Dim ProcessTemp As Process<br /> Dim StartTime As DateTime = Now<br /> Dim IntegerCloseAttempts As Integer<br /> Processes = System.Diagnostics.Process.GetProcessesByName(TaskName)<br /> Do Until StartTime.AddSeconds(Delay) < Now Or Processes.GetLength(0) > 0<br /> Processes = System.Diagnostics.Process.GetProcessesByName(TaskName)<br /> Loop<br /> IntegerCloseAttempts = 0<br /> While Processes.GetLength(0) > 0<br /> ProcessTemp = Processes(0)<br /> ProcessTemp.CloseMainWindow()<br /> ProcessTemp.WaitForExit(1000)<br /> ProcessTemp.Refresh()<br /> If ProcessTemp.HasExited Then<br /> IntegerCloseAttempts = 0<br /> Else<br /> IntegerCloseAttempts += 1<br /> If IntegerCloseAttempts >= 10 Then<br /> ProcessTemp.Kill()<br /> End If<br /> End If<br /> Processes = System.Diagnostics.Process.GetProcessesByName(TaskName)<br /> End While<br /> Processes = Nothing<br /> End Sub<br /> Das Bild skalieren <br /> Private Function ScaleImage(ByVal BitmapToScale As System.Drawing.Bitmap, ByVal MaximumWidth As Integer, ByVal MaximumHeight As Integer) As System.Drawing.Bitmap<br /> Dim BitmapScaledImage As System.Drawing.Bitmap<br /> Dim GraphicsImageEditor As System.Drawing.Graphics<br /> Dim IntegerNewWidth As Integer<br /> Dim IntegerNewHeight As Integer<br /> Dim DoubleScaleRatio As Double<br /> If BitmapToScale.Width <= MaximumWidth And BitmapToScale.Height <= MaximumHeight Then DoubleScaleRatio = 0 IntegerNewWidth = BitmapToScale.Width IntegerNewHeight = BitmapToScale.Height End If If BitmapToScale.Width > MaximumWidth And BitmapToScale.Height <= MaximumHeight Then DoubleScaleRatio = MaximumWidth / BitmapToScale.Width IntegerNewWidth = MaximumWidth IntegerNewHeight = Math.Min(CInt(BitmapToScale.Height / DoubleScaleRatio), MaximumHeight) End If If BitmapToScale.Width <= MaximumWidth And BitmapToScale.Height > MaximumHeight Then<br /> DoubleScaleRatio = MaximumHeight / BitmapToScale.Height<br /> IntegerNewWidth = Math.Min(CInt(BitmapToScale.Width * DoubleScaleRatio), MaximumWidth)<br /> IntegerNewHeight = MaximumHeight<br /> End If<br /> If BitmapToScale.Width > MaximumWidth And BitmapToScale.Height > MaximumHeight Then<br /> If BitmapToScale.Width / MaximumWidth > BitmapToScale.Height / MaximumHeight Then<br /> DoubleScaleRatio = MaximumWidth / BitmapToScale.Width<br /> IntegerNewWidth = MaximumWidth<br /> IntegerNewHeight = Math.Min(CInt(BitmapToScale.Height * DoubleScaleRatio), MaximumHeight)<br /> Else<br /> DoubleScaleRatio = MaximumHeight / BitmapToScale.Height<br /> IntegerNewWidth = Math.Min(CInt(BitmapToScale.Width * DoubleScaleRatio), MaximumWidth)<br /> IntegerNewHeight = MaximumHeight<br /> End If<br /> End If<br /> BitmapScaledImage = New Bitmap(IntegerNewWidth, IntegerNewHeight, Imaging.PixelFormat.Format32bppArgb)<br /> GraphicsImageEditor = Graphics.FromImage(BitmapScaledImage)<br /> GraphicsImageEditor.DrawImage(BitmapToScale, 0, 0, IntegerNewWidth, IntegerNewHeight)<br /> GraphicsImageEditor = Nothing<br /> Return BitmapScaledImage<br /> End Function<br /> Klasse für temporäre Dateien <br /> Public Class TempFileCollection<br /> Inherits List(Of String)<br /> Private sBaseDirectory As String<br /> ReadOnly Property BaseDirectory() As String<br /> Get<br /> Return sBaseDirectory<br /> End Get<br /> End Property<br /> Public Function AddExtension(ByVal Extension As String, ByVal CreateFile As Boolean) As String<br /> Dim StringTempFileName As String<br /> Dim StringTempFullPath As String<br /> Dim RegExNameChecker As System.Text.RegularExpressions.Regex<br /> Dim StreamTemp As System.IO.Stream<br /> RegExNameChecker = New System.Text.RegularExpressions.Regex(„[^0-9a-zA-Z]“)<br /> StringTempFileName = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName)<br /> StringTempFullPath = Me.BaseDirectory + „“ + StringTempFileName + „.“ + Extension<br /> While System.IO.File.Exists(StringTempFullPath) Or RegExNameChecker.IsMatch(StringTempFileName)<br /> StringTempFileName = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName)<br /> StringTempFullPath = Me.BaseDirectory + „“ + StringTempFileName + „.“ + Extension<br /> End While<br /> If CreateFile Then<br /> StreamTemp = System.IO.File.Create(StringTempFullPath)<br /> StreamTemp.Close()<br /> End If<br /> Me.Add(StringTempFullPath)<br /> Return StringTempFullPath<br /> End Function<br /> Public Function AddExtension(ByVal Extension As String) As String<br /> Return AddExtension(Extension, True)<br /> End Function<br /> Public Sub Delete()<br /> While Me.Count > 0<br /> If System.IO.File.Exists(Me.Item(0)) Then<br /> Try<br /> System.IO.File.Delete(Me.Item(0))<br /> Catch ex As Exception<br /> End Try<br /> End If<br /> Me.RemoveAt(0)<br /> End While<br /> End Sub<br /> Public Sub Delete(ByVal TempFileName As String)<br /> If System.IO.File.Exists(TempFileName) Then<br /> Try<br /> System.IO.File.Delete(TempFileName)<br /> Catch ex As Exception </p> <p style="background:transparent">End Try<br /> End If<br /> Me.Remove(TempFileName)<br /> End Sub<br /> Protected Overrides Sub Finalize()<br /> Me.Delete()<br /> System.IO.Directory.Delete(Me.BaseDirectory)<br /> MyBase.Finalize()<br /> End Sub<br /> Public Sub New(ByVal BaseDirectory As String)<br /> MyBase.New()<br /> sBaseDirectory = BaseDirectory.TrimEnd(System.IO.Path.DirectorySeparatorChar)<br /> If Not System.IO.Directory.Exists(sBaseDirectory) Then<br /> System.IO.Directory.CreateDirectory(sBaseDirectory)<br /> End If<br /> End Sub<br /> End Class<br /> « vorherige Seite123InhaltSo klappt's: Mappoint-Bilder mithilfe von VB.NET extrahierenDie LösungHauptfunktion
Neueste Kommentare
Noch keine Kommentare zu So klappt’s: Mappoint-Bilder mithilfe von VB.NET extrahieren
Kommentar hinzufügenVielen Dank für Ihren Kommentar.
Ihr Kommentar wurde gespeichert und wartet auf Moderation.