.net - Adding text BELOW bitmap in VB.NET -


I'm actually trying to resize a .NET bitmap without scaling the image. The idea here is to make a place above and below the image, fill it with a black rectangle, and place some text there (without hiding or destroying any part of the original picture).

I have seen all the code and examples so far just to show how the image scale, the canvas is not expanded so far, whatever I have adopted, it also spreads the scales / image.

What do I have here:

  System as a dim image. Drawing Size dim exifImage image exifImage = System.Drawing.Image.FromFile (originalPath) imageSize.Height = exifImage.Height imageSize.Width = exifImage.Width imageSize.Height + = blah 'to' whatever I text my height is needed to add 'does not work, because the image instead of goods up and down graphic dim exifOverlayImage New System.Drawing.Bitmap (exifImage, imageSize) System.Drawing.Graphics = System.Drawing.Graphics. FromImage gets spread of added below as (exifOverlayImage) Graphic.InterolationMode = InterpolationMode.HighQualityBicubic graphic.SmoothingMode = SmoothingMode.HighQuality graphic. Pixel OffsetMode = Pixel OffsetMod. Highlight Graphic CompositingQuality = Computing Properties High quality 'draws on the top title Shirshkbakgrounderektengl = new Rectangle (0, 0, Imejasijh Waidth, PointFontSize * 2) Grafikkdrayre ctangle (Pens.Black, upperBackgroundRectangle) graphic.FillRectangle (Brushes.Black, upperBackgroundRectangle) graphic.DrawString ( upperTitleCommentString, watermarkFont, new SolidBrush (ColorkWhite), new Point (0, 3)) '... and more content ...   

I suspect that I'm some sort Need to change scaling mode, or maybe a new canvas or something that is larger than my original image, Need Nane? The idea / advice would be greatly appreciated thanks.

You have to create a bitmap with the idea of ​​the new width and height, how do I do it (this In C #, but you can use it to change): ( Width + pixel pinning and ** height + bottom size + pixel padding ** is the place where padding is added. )

  using (var DST = new bitmap (width + pixelPadding, height + bottomSize + pixelPadding, PixelFormat.Format24bppRgb)) {var rSrcImg = new Rectangle (0,0, src.Width , Src.Height); Var rDstImg = New Rectangle (Pixel Padding / 2, Pixel Padding / 2, DCT .With - Pixel Padding, DCT. High-Pixel Pinning - Bottom Size); Use (Graphics G = Graphics. Framesize (DST)) {g.Clear (Color.FromArgb (64, 64, 64)); G.FillRectangle (Brush White, RDSIMG); G.CompositingMode = CompositingMode.SourceOver; G.CompositingQuality = Compositing Quality GammaCorrected; G. SabootingMode = Smoothing. High quality; G. Interpolation mode = Interpolation mode. Highquite bibbic; G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; G.DrawImage (src, rDstImg, rSrcImg, GraphicsUnit.Pixel); } Var MS = new memorystream (); // Save the bitmap to the stream ... dst.Save (ms, ImageFormat.Png); Ms.osition = 0;   

I have written a blog post about this. It resizes and adds some padding to the image.
Basically, you have to make a bitmap + padding of the size image. Then fill a rectangle with your image and drag a string into your desired area. The article is in Persian but you can use Google Translate. I have given the source code there.

Comments