我不能在名称空间"System.IO.Compression"中使用"Zipfile"类我的代码是:
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest,true);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:
"zipfile"这个名称在当前上下文中不存在
我怎么解决呢?
我有一个图像,我可以使用Martix读取它的所有像素颜色...如何更改任何像素的RGB如果我想将其转换为最接近的颜色(黑色,红色或白色)
我在Matrix中读取图像的代码是:
string sourceimg = @"D:\ProductionTools\Taskes\Image Processing\Test\001.jpg";
//...
Bitmap imageoriginal = new Bitmap(sourceimg);
int height = imageoriginal.Height;
int width = imageoriginal.Width;
Color[][] colormatrix = new Color[width][];
for (int i = 0; i < width; i++) {
colormatrix[i] = new Color[height];
for (int j = 0; j < height; j++) {
colormatrix[i][j] = new Color();
colormatrix[i][j] = imageoriginal.GetPixel(i, j);
}
}
Run Code Online (Sandbox Code Playgroud) 当我裁剪使用Bitmap.Clone()它创建比原始图像尺寸较大的输出的图像
的原始大小是:-5 M
和输出裁剪的图像:28男
如何在不损失质量和没有大尺寸的情况下进行裁剪?我的代码是:
private static Image cropImage(Image img, Rectangle cropArea)
{
var bmpImage = new Bitmap(img);
Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
img.Dispose();
bmpCrop.Save(@"D:\Work\CropImage\CropImage\crop.jpg",bmpImage.RawFormat );
return (Image)(bmpCrop);
}
static void Main(string[] args)
{
string sourceimg = @"D:\Work\Crop Image\CropImage\4032x5808.jpg";
Image imageoriginal = Image.FromFile(sourceimg);
int HorX,HorY,VerX,VerY;
Console.WriteLine("Enter X 1 Cor. ");
HorX=int.Parse(Console.ReadLine());
Console.WriteLine("Enter Y 1 Cor. ");
HorY=int.Parse(Console.ReadLine());
Console.WriteLine("Enter X 2 Cor. ");
VerX=int.Parse(Console.ReadLine());
Console.WriteLine("Enter Y 1 Cor. ");
VerY= int.Parse(Console.ReadLine());
Rectangle rect = new Rectangle(HorX,HorY,VerX,VerY);
cropImage(imageoriginal, rect);
}
Run Code Online (Sandbox Code Playgroud)