ImageManipulator.cs
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
//Source:
//http://drwpf.com/blog/2007/09/08/image-manipulation-using-wpf-imaging-classes/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.IO;
// 下载于www.51aspx.com
namespace DrWPF.Media.Imaging
{
public class ImageManipulator
{
public static void ResizeImage(string filename, int width, int height)
{
string extension = Path.GetExtension(filename);
string rootFilename = Path.GetDirectoryName(filename)
+ @"\" + Path.GetFileNameWithoutExtension(filename);
// load the file data
byte[] imageBytes = LoadImageData(filename);
// decode the image to the requested width and height
BitmapSource imageSource = CreateImage(imageBytes, width, height);
// encode the image using the original format
byte[] encodedBytes = GetEncodedImageData(imageSource, extension);
// save the modified image
//filename = rootFilename;// +"Resized" + extension;
SaveImageData(encodedBytes, filename);
Console.WriteLine("Resized image to {0} x {1} and saved as {2}.\n",
imageSource.PixelWidth, imageSource.PixelHeight, filename);
}
public static void CropImage(string filename)
{
string extension = Path.GetExtension(filename);
string rootFilename = Path.GetDirectoryName(filename)
+ @"\" + Path.GetFileNameWithoutExtension(filename);
// load the file data
byte[] imageBytes = LoadImageData(filename);
// decode the image to its natural size
BitmapSource imageSource = CreateImage(imageBytes, 0, 0);
// crop the image so that it is square
bool isPortrait = imageSource.Height > imageSource.Width;
int squareLength = Math.Min(imageSource.PixelWidth, imageSource.PixelHeight);
imageSource = new CroppedBitmap(imageSource,
new Int32Rect(isPortrait ? 0 : (int)((imageSource.PixelWidth - squareLength) / 2),
isPortrait ? (int)((imageSource.PixelHeight - squareLength) / 2) : 0,
squareLength, squareLength));
// encode the image using the original format
byte[] encodedBytes = GetEncodedImageData(imageSource, extension);
后面还有 154 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。