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