【发布时间】:2011-07-24 23:08:38
【问题描述】:
我试图在不实际缩放图像的情况下调整 .NET 位图的大小。这里的想法是在图像上方和下方创建一个空间,用黑色矩形填充它,并在其中放置一些文本(不覆盖或破坏原始图像的任何部分)。
到目前为止,我看到的所有代码和示例都只是展示了如何缩放图像,而不是扩展画布。到目前为止,我自己尝试过的所有操作都会缩放/拉伸图像。
这是我所拥有的:
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 ...
我怀疑我需要更改某种缩放模式,或者创建一个新画布或比我的原始图像更大的东西?想法/建议将不胜感激。谢谢。
【问题讨论】:
标签: .net vb.net image image-processing