I am trying to convert an image into NIT, but get a faint black border around the resized image. I got a position - that was from the person who made the destination rectangle larger than the canvas, but it does not work for me. It reads the upper and the left borders, but it is still right and down, and A full 1 px is thick black.
Am I forgetting something? My code is below
image image = ... // This source rectangle srcRectangle = The validity of the image loaded with new rectangle (0,0, width, height). Size cut FullSize = new size (width + 3, height + 3); Rectangle = destter = new rectangular (new point (-1, -1), crop size crop); (Bitmap newImage = new bitmap (using croppedFullSize.Width, croppedFullSize.Height, format)) (Graphics canvas = Graphics.FromImage (newImage)) {Canvas.SmoothingMode = SmoothingMode.AntiAlias; Canvas.InternationalMod = Interpolation mode. Highquite bibbic; Canvas Pixel offsetmod = pixeloffet mode.hequality; Canvas Filtrategle (brush transpers, destact); Canvas.DrawImage (Image, Dest., Sorregangal, GraphicsEnit.Pixel); New image Save (File name, Image. RF format); }
Try it like this, I think I never got a black border ..
You want to use System.Drawing libraries:
using (source bmp = new bitmap (sourcepath)) {decimal aspect = (decimal) SourceBmp.Width / (decimal) sourceBmp.Height; Int newHeight = (int) (nudity / aspect); (Using destinationBmp = newWidth, newHyight) {Using (destinationGfx = Graphics.FromImage (destinationBMP)) {destinationGfx.InterpolationMode = InterpolationMode.HighQualityBicubic; DestinationGfx.DrawImage (sourceBmp, new rectangle (0, 0, destinationBmp.Width, destinationBmp.Height)); DestinationBmp.Save (destination path, ImageFormat.Jpeg); }}} Or you can do the same with WPF like this:
using (output = new FileStream (outputPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None)) {var imageDecoder = BitmapDecoder.Create (InputStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); Var imageFrame = imageDecoder.Frames [0]; Decimal aspect = (decimal) imageFrame.Width / (decimal) imageFrame.Height; Var height = (int) (nudity / aspect); Var imageResized = New Transformed Bitmap (Image Frame, New Scale Transform (Nudity / ImageFram Wideth * DPI / ImageFrame. DPIX, Height / Image Frame.High * DPI / ImageFrame.Dpi, 0, 0)); Var targetFrame = BitmapFrame. Create (image resized); Var Target Encoder = New JPEGBitMap Encoder (); TargetEncoder.Frames.Add (targetFrame); TargetEncoder.QualityLevel = 80; TargetEncoder.Save (production); } I suggest WPF method compression & amp; Quality feels better ...
Comments
Post a Comment