Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
RHCSA, RHCE, AWS, Docker, Kubernetes Training
Sanjeewani95
Updated:
Yesterday at 10:28 AM
🛡️ Kaspersky Antivirus – 1 Year / 1 Device | Rs. 2,300 | Only 9 Left
KSPathirana
Updated:
Monday at 2:42 PM
Ad icon
Professional CCTV Installation Service
Techguy231
Updated:
Sunday at 10:50 AM
Ad icon
I'll research & write an article - Rs. 2000 onwards
Blogerwiki
Updated:
Thursday at 9:11 PM
House Plan
lenura
Updated:
Sep 2, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
asp .net හෝ C# දන්නා කෙනෙක්ගෙන් මට ලොකු උදව්වක් ඕනේ
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="K_ZONE" data-source="post: 15030827" data-attributes="member: 207562"><p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px">හ්ම්. . . මගෙ system එකේ කොහෙවත් Save වෙන්නෙ නැ බං, 3rd party Libraries use කරෙ නැති හින්දා මම කෙලින්ම Image එකම pass කරනවා, </span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px">[CODE]using System;</span></p> <p style="text-align: center"><span style="font-size: 15px">using System.Collections.Generic;</span></p> <p style="text-align: center"><span style="font-size: 15px">using System.Linq;</span></p> <p style="text-align: center"><span style="font-size: 15px">using System.Text;</span></p> <p style="text-align: center"><span style="font-size: 15px">using System.Drawing;</span></p> <p style="text-align: center"><span style="font-size: 15px">using System.IO;</span></p> <p style="text-align: center"><span style="font-size: 15px">using System.Drawing.Imaging;</span></p> <p style="text-align: center"><span style="font-size: 15px">using System.Drawing.Drawing2D;</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px">namespace Skynet.ImageProsses</span></p> <p style="text-align: center"><span style="font-size: 15px">{</span></p> <p style="text-align: center"><span style="font-size: 15px"> public class ImageProsses</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> //Overload for crop that default starts top left of the image.</span></p> <p style="text-align: center"><span style="font-size: 15px"> public static Image CropImage(System.Drawing.Image Image, int Height, int Width)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> return CropImage(Image, Height, Width, 0, 0);</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> //The crop image sub</span></p> <p style="text-align: center"><span style="font-size: 15px"> public static System.Drawing.Image CropImage(System.Drawing.Image Image, int Height, int Width, int StartAtX, int StartAtY)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> Image outimage;</span></p> <p style="text-align: center"><span style="font-size: 15px"> MemoryStream mm = null;</span></p> <p style="text-align: center"><span style="font-size: 15px"> try</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> //check the image height against our desired image height</span></p> <p style="text-align: center"><span style="font-size: 15px"> if (Image.Height < Height)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> Height = Image.Height;</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> if (Image.Width < Width)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> Width = Image.Width;</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> //create a bitmap window for cropping</span></p> <p style="text-align: center"><span style="font-size: 15px"> Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);</span></p> <p style="text-align: center"><span style="font-size: 15px"> bmPhoto.SetResolution(72, 72);</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> //create a new graphics object from our image and set properties</span></p> <p style="text-align: center"><span style="font-size: 15px"> Graphics grPhoto = Graphics.FromImage(bmPhoto);</span></p> <p style="text-align: center"><span style="font-size: 15px"> grPhoto.SmoothingMode = SmoothingMode.AntiAlias;</span></p> <p style="text-align: center"><span style="font-size: 15px"> grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;</span></p> <p style="text-align: center"><span style="font-size: 15px"> grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> //now do the crop</span></p> <p style="text-align: center"><span style="font-size: 15px"> grPhoto.DrawImage(Image, new Rectangle(0, 0, Width, Height), StartAtX, StartAtY, Width, Height, GraphicsUnit.Pixel);</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> // Save out to memory and get an image from it to send back out the method.</span></p> <p style="text-align: center"><span style="font-size: 15px"> mm = new MemoryStream();</span></p> <p style="text-align: center"><span style="font-size: 15px"> bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg);</span></p> <p style="text-align: center"><span style="font-size: 15px"> Image.Dispose();</span></p> <p style="text-align: center"><span style="font-size: 15px"> bmPhoto.Dispose();</span></p> <p style="text-align: center"><span style="font-size: 15px"> grPhoto.Dispose();</span></p> <p style="text-align: center"><span style="font-size: 15px"> outimage = Image.FromStream(mm);</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> return outimage;</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"> catch (Exception ex)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> throw new Exception("Error cropping image, the error was: " + ex.Message);</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> //Hard resize attempts to resize as close as it can to the desired size and then crops the excess</span></p> <p style="text-align: center"><span style="font-size: 15px"> public static System.Drawing.Image HardResizeImage(int Width, int Height, System.Drawing.Image Image)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> int width = Image.Width;</span></p> <p style="text-align: center"><span style="font-size: 15px"> int height = Image.Height;</span></p> <p style="text-align: center"><span style="font-size: 15px"> Image resized = null;</span></p> <p style="text-align: center"><span style="font-size: 15px"> if (Width > Height)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> resized = ResizeImage(Width, Width, Image);</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"> else</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> resized = ResizeImage(Height, Height, Image);</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"> Image output = CropImage(resized, Height, Width);</span></p> <p style="text-align: center"><span style="font-size: 15px"> //return the original resized image</span></p> <p style="text-align: center"><span style="font-size: 15px"> return output;</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> //Image resizing</span></p> <p style="text-align: center"><span style="font-size: 15px"> public static System.Drawing.Image ResizeImage(int maxWidth, int maxHeight, System.Drawing.Image Image)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> int width = Image.Width;</span></p> <p style="text-align: center"><span style="font-size: 15px"> int height = Image.Height;</span></p> <p style="text-align: center"><span style="font-size: 15px"> if (width > maxWidth || height > maxHeight)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> //The flips are in here to prevent any embedded image thumbnails -- usually from cameras</span></p> <p style="text-align: center"><span style="font-size: 15px"> //from displaying as the thumbnail image later, in other words, we want a clean</span></p> <p style="text-align: center"><span style="font-size: 15px"> //resize, not a grainy one.</span></p> <p style="text-align: center"><span style="font-size: 15px"> Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);</span></p> <p style="text-align: center"><span style="font-size: 15px"> Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> float ratio = 0;</span></p> <p style="text-align: center"><span style="font-size: 15px"> if (width > height)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> ratio = (float)width / (float)height;</span></p> <p style="text-align: center"><span style="font-size: 15px"> width = maxWidth;</span></p> <p style="text-align: center"><span style="font-size: 15px"> height = Convert.ToInt32(Math.Round((float)width / ratio));</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"> else</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> ratio = (float)height / (float)width;</span></p> <p style="text-align: center"><span style="font-size: 15px"> height = maxHeight;</span></p> <p style="text-align: center"><span style="font-size: 15px"> width = Convert.ToInt32(Math.Round((float)height / ratio));</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> //return the resized image</span></p> <p style="text-align: center"><span style="font-size: 15px"> return Image.GetThumbnailImage(width, height, null, IntPtr.Zero);</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"> //return the original resized image</span></p> <p style="text-align: center"><span style="font-size: 15px"> return Image;</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"> public Image ResizeImage(Image FullsizeImage, int NewWidth, int MaxHeight, bool OnlyResizeIfWider = true)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> // Prevent using images internal thumbnail</span></p> <p style="text-align: center"><span style="font-size: 15px"> FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);</span></p> <p style="text-align: center"><span style="font-size: 15px"> FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> if (OnlyResizeIfWider)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> if (FullsizeImage.Width <= NewWidth)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> NewWidth = FullsizeImage.Width;</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;</span></p> <p style="text-align: center"><span style="font-size: 15px"> if (NewHeight > MaxHeight)</span></p> <p style="text-align: center"><span style="font-size: 15px"> {</span></p> <p style="text-align: center"><span style="font-size: 15px"> // Resize with height instead</span></p> <p style="text-align: center"><span style="font-size: 15px"> NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;</span></p> <p style="text-align: center"><span style="font-size: 15px"> NewHeight = MaxHeight;</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> // Clear handle to original file so that we can overwrite it if necessary</span></p> <p style="text-align: center"><span style="font-size: 15px"> FullsizeImage.Dispose();</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> // Save resized picture</span></p> <p style="text-align: center"><span style="font-size: 15px"> return NewImage;</span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px"> }</span></p> <p style="text-align: center"><span style="font-size: 15px">}[/CODE]</span></p> <p style="text-align: center"><span style="font-size: 15px"></span></p> <p style="text-align: center"><span style="font-size: 15px">System.Drawing.Imaging.image Type එකේ තමයි image එක Save වෙන කල්ම තියෙන්නෙ,. අන්තිමට කපලා කොටලා ඉවර උන Image එක Base64 encode කරලා, Bitstream එකක් විදියට SQL server එකෙ තමයි තියන්නෙ. . Image එක Image එකක් විදියට ගන්නෙ නැ කොහෙවත් .. </span></p></blockquote><p></p>
[QUOTE="K_ZONE, post: 15030827, member: 207562"] [CENTER][SIZE="4"] හ්ම්. . . මගෙ system එකේ කොහෙවත් Save වෙන්නෙ නැ බං, 3rd party Libraries use කරෙ නැති හින්දා මම කෙලින්ම Image එකම pass කරනවා, [CODE]using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.IO; using System.Drawing.Imaging; using System.Drawing.Drawing2D; namespace Skynet.ImageProsses { public class ImageProsses { //Overload for crop that default starts top left of the image. public static Image CropImage(System.Drawing.Image Image, int Height, int Width) { return CropImage(Image, Height, Width, 0, 0); } //The crop image sub public static System.Drawing.Image CropImage(System.Drawing.Image Image, int Height, int Width, int StartAtX, int StartAtY) { Image outimage; MemoryStream mm = null; try { //check the image height against our desired image height if (Image.Height < Height) { Height = Image.Height; } if (Image.Width < Width) { Width = Image.Width; } //create a bitmap window for cropping Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format24bppRgb); bmPhoto.SetResolution(72, 72); //create a new graphics object from our image and set properties Graphics grPhoto = Graphics.FromImage(bmPhoto); grPhoto.SmoothingMode = SmoothingMode.AntiAlias; grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic; grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality; //now do the crop grPhoto.DrawImage(Image, new Rectangle(0, 0, Width, Height), StartAtX, StartAtY, Width, Height, GraphicsUnit.Pixel); // Save out to memory and get an image from it to send back out the method. mm = new MemoryStream(); bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg); Image.Dispose(); bmPhoto.Dispose(); grPhoto.Dispose(); outimage = Image.FromStream(mm); return outimage; } catch (Exception ex) { throw new Exception("Error cropping image, the error was: " + ex.Message); } } //Hard resize attempts to resize as close as it can to the desired size and then crops the excess public static System.Drawing.Image HardResizeImage(int Width, int Height, System.Drawing.Image Image) { int width = Image.Width; int height = Image.Height; Image resized = null; if (Width > Height) { resized = ResizeImage(Width, Width, Image); } else { resized = ResizeImage(Height, Height, Image); } Image output = CropImage(resized, Height, Width); //return the original resized image return output; } //Image resizing public static System.Drawing.Image ResizeImage(int maxWidth, int maxHeight, System.Drawing.Image Image) { int width = Image.Width; int height = Image.Height; if (width > maxWidth || height > maxHeight) { //The flips are in here to prevent any embedded image thumbnails -- usually from cameras //from displaying as the thumbnail image later, in other words, we want a clean //resize, not a grainy one. Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX); Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX); float ratio = 0; if (width > height) { ratio = (float)width / (float)height; width = maxWidth; height = Convert.ToInt32(Math.Round((float)width / ratio)); } else { ratio = (float)height / (float)width; height = maxHeight; width = Convert.ToInt32(Math.Round((float)height / ratio)); } //return the resized image return Image.GetThumbnailImage(width, height, null, IntPtr.Zero); } //return the original resized image return Image; } public Image ResizeImage(Image FullsizeImage, int NewWidth, int MaxHeight, bool OnlyResizeIfWider = true) { // Prevent using images internal thumbnail FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone); FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone); if (OnlyResizeIfWider) { if (FullsizeImage.Width <= NewWidth) { NewWidth = FullsizeImage.Width; } } int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width; if (NewHeight > MaxHeight) { // Resize with height instead NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height; NewHeight = MaxHeight; } Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero); // Clear handle to original file so that we can overwrite it if necessary FullsizeImage.Dispose(); // Save resized picture return NewImage; } } }[/CODE] System.Drawing.Imaging.image Type එකේ තමයි image එක Save වෙන කල්ම තියෙන්නෙ,. අන්තිමට කපලා කොටලා ඉවර උන Image එක Base64 encode කරලා, Bitstream එකක් විදියට SQL server එකෙ තමයි තියන්නෙ. . Image එක Image එකක් විදියට ගන්නෙ නැ කොහෙවත් .. [/SIZE][/CENTER] [/QUOTE]
Insert quotes…
Verification
Dawasata paya keeyak thibeda?
Post reply
Top
Bottom