我正在嘗試調整.NET位圖的大小而不實際縮放圖像。這裏的想法是在圖像上方和下方創建一個空間,用黑色矩形填充它,並在其中放置一些文本(不會覆蓋或破壞原始圖像的任何部分)。在VB.NET中添加文本BELOW位圖
到目前爲止,我所見過的所有代碼和示例都展示瞭如何縮放圖像,而不是展開畫布。到目前爲止,我嘗試過的所有東西都可以縮放/拉伸圖像。
這是我有:
Dim imageSize As System.Drawing.Size
Dim exifImage As Image
exifImage = System.Drawing.Image.FromFile(originalPath)
imageSize.Height = exifImage.Height
imageSize.Width = exifImage.Width
imageSize.Height += BLAH '' whatever I need to add to my height for the text
'' this doesn't work, because the image gets stretched instead of stuff getting added above and below
Dim exifOverlayImage As New System.Drawing.Bitmap(exifImage, imageSize)
Dim graphic As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(exifOverlayImage)
graphic.InterpolationMode = InterpolationMode.HighQualityBicubic
graphic.SmoothingMode = SmoothingMode.HighQuality
graphic.PixelOffsetMode = PixelOffsetMode.HighQuality
graphic.CompositingQuality = CompositingQuality.HighQuality
'' Draw Title at the Top
Dim upperBackgroundRectangle = New Rectangle(0, 0, imageSize.Width, pointFontSize * 2)
graphic.DrawRectangle(Pens.Black, upperBackgroundRectangle)
graphic.FillRectangle(Brushes.Black, upperBackgroundRectangle)
graphic.DrawString(upperTitleCommentString, watermarkFont, New SolidBrush(Color.White), New Point(0, 3))
'' ... and more stuff ...
我懷疑我需要改變某種縮放模式進行,或者創建一個新的畫布或東西是比我原來的圖像更大?想法/建議將不勝感激。謝謝。