本文整理汇总了C#中ImageMagick.MagickImage.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Dispose方法的具体用法?C# MagickImage.Dispose怎么用?C# MagickImage.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Constructor_Bitmap
public void Test_Constructor_Bitmap()
{
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
new MagickImage((Bitmap)null);
});
using (Bitmap bitmap = new Bitmap(Files.SnakewarePNG))
{
using (MagickImage image = new MagickImage(bitmap))
{
Assert.AreEqual(286, image.Width);
Assert.AreEqual(67, image.Height);
Assert.AreEqual(MagickFormat.Png, image.Format);
}
}
using (Bitmap bitmap = new Bitmap(50, 100, PixelFormat.Format24bppRgb))
{
using (MagickImage image = new MagickImage(bitmap))
{
Assert.AreEqual(50, image.Width);
Assert.AreEqual(100, image.Height);
Assert.AreEqual(MagickFormat.Bmp3, image.Format);
image.Dispose();
}
}
}
示例2: Test_Clone
private static void Test_Clone(MagickImage first, MagickImage second)
{
Assert.AreEqual(first, second);
second.Format = MagickFormat.Jp2;
Assert.AreEqual(first.Format, MagickFormat.Png);
Assert.AreEqual(second.Format, MagickFormat.Jp2);
second.Dispose();
Assert.AreEqual(first.Format, MagickFormat.Png);
}
示例3: DownloadInstaPhotos
public IHttpActionResult DownloadInstaPhotos()
{
QpiroJSON resp = new QpiroJSON();
try
{
string[] file = Directory.GetFiles(UserProperty.Current_User, UserProperty.UserXmlInfo);
if (file.Count() != 1)
throw new Exception("Geçersiz kullanıcı bilgileri.");
string _range = "0-1000";// ilk kaç resim ?
int min = int.Parse(_range.Split('-')[0]);
int max = int.Parse(_range.Split('-')[1]);
XDocument doc = XDocument.Load(file[0]);
XElement root = doc.Elements("_" + ImageProperty.GetUserName()).First();
XElement InstagramP = root.Elements("InstagramPhotos").FirstOrDefault();
List<XElement> potos = InstagramP.Elements("Photos").ToList();
//download
List<string> imglist = InstagramProfile.UserPhotos();
ServerAsyncCallBack servers = new ServerAsyncCallBack();
servers.Execute(Api._QPR.Type.AsyncCallType.DownloadInstaPhotos, imglist);
if (imglist.Count > 0)
{
//https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/
for (int i = 0; i < imglist.Count; i++)
{
if (i >= min && i <= max)
{
//resp.Data.Add(imglist[i]);
string filname = Path.GetFileName(imglist[i]);
if (potos.FindIndex(p => Path.GetFileName(p.Value) == filname) == -1)
{
XElement photo = new XElement("Photos",
new XAttribute("useThis", true.ToString())
);
photo.Value = imglist[i];
InstagramP.Add(photo);
using (MagickImage mini = new MagickImage(InstagramProfile.DownloadImage(imglist[i])))
{
mini.Quality = 100;
mini.Resize(94, 94);
mini.Write(Path.Combine(UserProperty.Data_InstagramPhotos, filname));
mini.Dispose();
}
}
}
}
doc.Save(file[0]);
resp.Data.Add("Resimler Güncellendi");
}
else
{
throw new Exception("Instagram hesabınızda hiç fotoğrafınız bulunmuyor");
}
InstagramP = null;
potos.Clear();
imglist.Clear();
}
catch (Exception e)
{
resp.Message = e.Message;
}
return this.Json<QpiroJSON>(resp);
}
示例4: SaveAndDispose
private Task SaveAndDispose(string filename, MagickImage image) {
try {
if (File.Exists(filename)) {
FileUtils.Recycle(filename);
}
image.SetDefine(MagickFormat.Dds, "compression", "none");
image.Quality = 100;
var bytes = image.ToByteArray(MagickFormat.Dds);
return FileUtils.WriteAllBytesAsync(filename, bytes);
} finally {
image.Dispose();
}
}
示例5: Test_IEquatable
public void Test_IEquatable()
{
MagickImage first = new MagickImage(Color.Red, 10, 10);
Assert.IsFalse(first == null);
Assert.IsFalse(first.Equals(null));
Assert.IsTrue(first.Equals(first));
Assert.IsTrue(first.Equals((object)first));
MagickImage second = new MagickImage(Color.Red, 10, 10);
Assert.IsTrue(first == second);
Assert.IsTrue(first.Equals(second));
Assert.IsTrue(first.Equals((object)second));
second = new MagickImage(Color.Green, 10, 10);
Assert.IsTrue(first != second);
Assert.IsFalse(first.Equals(second));
first.Dispose();
second.Dispose();
first = null;
Assert.IsTrue(first == null);
Assert.IsFalse(first != null);
}
示例6: Test_IComparable
public void Test_IComparable()
{
MagickImage first = new MagickImage(Color.Red, 10, 5);
Assert.AreEqual(0, first.CompareTo(first));
Assert.AreEqual(1, first.CompareTo(null));
Assert.IsFalse(first < null);
Assert.IsFalse(first <= null);
Assert.IsTrue(first > null);
Assert.IsTrue(first >= null);
Assert.IsTrue(null < first);
Assert.IsTrue(null <= first);
Assert.IsFalse(null > first);
Assert.IsFalse(null >= first);
MagickImage second = new MagickImage(Color.Green, 5, 5);
Assert.AreEqual(1, first.CompareTo(second));
Assert.IsFalse(first < second);
Assert.IsFalse(first <= second);
Assert.IsTrue(first > second);
Assert.IsTrue(first >= second);
second = new MagickImage(Color.Red, 5, 10);
Assert.AreEqual(0, first.CompareTo(second));
Assert.IsFalse(first == second);
Assert.IsFalse(first < second);
Assert.IsTrue(first <= second);
Assert.IsFalse(first > second);
Assert.IsTrue(first >= second);
first.Dispose();
second.Dispose();
}
示例7: PointGenerator
//.........这里部分代码省略.........
}
string MiniPicturePath = Path.Combine(resources.Data_InstagramPhotos);
if (Directory.Exists(MiniPicturePath))
{
Bitmap btm = imagem.ToBitmap();
using (Graphics gr1 = Graphics.FromImage(btm))
{
///////////////////////////////////////////////////////////////
string[] file = Directory.GetFiles(resources.Current_User, resources.UserXmlInfo);
if (file.Count() != 1)
throw new Exception("Geçersiz kullanıcı bilgileri");
XDocument doc = XDocument.Load(file[0]);
XElement root = doc.Elements("_" + resources.UserName).First();
XElement InstagramP = root.Elements("InstagramPhotos").FirstOrDefault();
XElement[] photos = (from p in InstagramP.Elements() where p.Attribute("useThis").Value.ToLower() == "true" select p).ToArray();
///////////////////////////////////////////////////
if (photos.Count() == 0)
throw new Exception("Bu Formata Uygun Resimler Bulunamadı") { Source = "" };
List<ImgSquare> spl2 = new List<ImgSquare>();
for (int i = 0; i < photos.Count(); i++)
{
if (File.Exists(Path.Combine(MiniPicturePath, Path.GetFileName(photos[i].Value))))
{
using (MagickImage mini = new MagickImage(Path.Combine(MiniPicturePath, Path.GetFileName(photos[i].Value))))
{
mini.Quality = 100;
if (mini.Width != 94 && mini.Height != 94)
mini.Resize((int)_pixFor, (int)_pixFor);
spl2.Add(new ImgSquare(mini.ToBitmap()));
mini.Dispose();
}
}
}
photos = null;
doc = null;
root = null;
InstagramP = null;
List<ImgSquare> spl4 = new List<ImgSquare>();
spl4.AddRange(sp0);
spl4.AddRange(spl2);
spl2.Clear();
spl4 = spl4.OrderBy(p => p.GeneratedColorCode).ToList();
int qpiro_number = 432101;
int qpiro_number2 = 0;
int undefined = 0;
for (int i = 0; i < sp0.Count; i++)
{
ImgSquare item = sp0[i];
try
{
qpiro_number2 = 0;
List<ImgSquare> snc = null;
int cont = 0;
do
{
snc = spl4.Where(p =>
(p.GeneratedColorCode - (qpiro_number + qpiro_number2) < item.GeneratedColorCode &&
p.GeneratedColorCode + (qpiro_number + qpiro_number2) > item.GeneratedColorCode) &&
p.isArea == false).ToList();
qpiro_number2 += 332101;
cont++;
}
示例8: PointGenerator
//.........这里部分代码省略.........
XDocument doc = XDocument.Load(file[0]);
XElement root = doc.Elements("_" + ImageProperty.GetUserName()).First();
XElement InstagramP = root.Elements("InstagramPhotos").FirstOrDefault();
XElement[] photos = (from p in InstagramP.Elements() where p.Attribute("useThis").Value.ToLower() == "true" select p).ToArray();
//list = new string[photos.Count()];
//for (int i = 0; i < photos.Count(); i++)
// list[i] = Path.Combine(MiniPicturePath, photos[i].Value);
///////////////////////////////////////////////////
if (photos.Count() == 0)
throw new Exception("Bu Formata Uygun Resimler Bulunamadı") { Source = "" };
List<ImgSquare> spl2 = new List<ImgSquare>();
for (int i = 0; i < photos.Count(); i++)
{
if (File.Exists(Path.Combine(MiniPicturePath, Path.GetFileName(photos[i].Value))))
{
using (MagickImage mini = new MagickImage(Path.Combine(MiniPicturePath, Path.GetFileName(photos[i].Value))))
{
mini.Quality = 100;
if (mini.Width != 94 && mini.Height != 94)
mini.Resize((int)_pixFor, (int)_pixFor);
//ImgSquare imgsq = new ImgSquare(mini.ToBitmap(), new List<QuardPixAvg>() {
// new QuardPixAvg(Color.FromArgb(int.Parse(photos[i].Attribute("SolUst").Value)),QuardBolum.SagAlt),
// new QuardPixAvg(Color.FromArgb(int.Parse(photos[i].Attribute("SagUst").Value)),QuardBolum.SagAlt),
// new QuardPixAvg(Color.FromArgb(int.Parse(photos[i].Attribute("SolAlt").Value)),QuardBolum.SagAlt),
// new QuardPixAvg(Color.FromArgb(int.Parse(photos[i].Attribute("SagAlt").Value)),QuardBolum.SagAlt),
// new QuardPixAvg(Color.FromArgb(int.Parse(photos[i].Attribute("TotalAvg").Value)),QuardBolum.SagAlt)
//});
spl2.Add(new ImgSquare(mini.ToBitmap()));
mini.Dispose();
}
}
}
photos = null;
doc = null;
root = null;
InstagramP = null;
List<ImgSquare> spl4 = new List<ImgSquare>();
spl4.AddRange(sp0);
spl4.AddRange(spl2);
spl2.Clear();
spl4 = spl4.OrderBy(p => p.GeneratedColorCode).ToList();
int qpiro_number = 432101;
int qpiro_number2 = 0;
int undefined = 0;
for (int i = 0; i < sp0.Count; i++)
{
ImgSquare item = sp0[i];
//if (item.SAvgArb == 0 && item.IAvgRgb == 0)
// continue;
try
{
qpiro_number2 = 0;
List<ImgSquare> snc = null;
int cont = 0;
do
{
snc = spl4.Where(p =>
(p.GeneratedColorCode - (qpiro_number + qpiro_number2) < item.GeneratedColorCode &&
p.GeneratedColorCode + (qpiro_number + qpiro_number2) > item.GeneratedColorCode) &&
p.isArea == false).ToList();
qpiro_number2 += 332101;
示例9: Test_Dispose
public void Test_Dispose()
{
MagickImage image = new MagickImage();
image.Dispose();
image.Verbose = true;
}
示例10: Test_Read
public void Test_Read()
{
MagickImage image = new MagickImage();
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.Read(new byte[0]);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Read((byte[])null);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Read((Bitmap)null);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Read((Stream)null);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Read((string)null);
});
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.Read(Files.Missing);
});
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.Read("png:" + Files.Missing);
});
image.Read(File.ReadAllBytes(Files.SnakewarePNG));
using (Bitmap bitmap = new Bitmap(Files.SnakewarePNG))
{
image.Read(bitmap);
Assert.AreEqual(MagickFormat.Png, image.Format);
}
using (Bitmap bitmap = new Bitmap(100, 100, PixelFormat.Format24bppRgb))
{
image.Read(bitmap);
Assert.AreEqual(MagickFormat.Bmp3, image.Format);
}
using (FileStream fs = File.OpenRead(Files.SnakewarePNG))
{
image.Read(fs);
}
image.Read(Files.SnakewarePNG);
image.Read(Files.Builtin.Rose);
image.Read(Files.RoseSparkleGIF);
Assert.AreEqual("RöseSparkle.gif", Path.GetFileName(image.FileName));
image.Read("png:" + Files.SnakewarePNG);
MagickColor red = new MagickColor("red");
image.Read(red, 50, 50);
Assert.AreEqual(50, image.Width);
Assert.AreEqual(50, image.Height);
Test_Pixel_Equal(image, 10, 10, red);
image.Read("xc:red", 50, 50);
Assert.AreEqual(50, image.Width);
Assert.AreEqual(50, image.Height);
Test_Pixel_Equal(image, 5, 5, red);
image.Dispose();
ExceptionAssert.Throws<ObjectDisposedException>(delegate ()
{
image.Read(Files.Builtin.Logo);
});
}
示例11: Test_Read
public void Test_Read()
{
MagickImage image = new MagickImage();
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.Read(new byte[0]);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Read((byte[])null);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Read((Stream)null);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Read((string)null);
});
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.Read(Files.Missing);
});
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.Read("png:" + Files.Missing);
});
image.Read(File.ReadAllBytes(Files.SnakewarePNG));
Assert.AreEqual(286, image.Width);
Assert.AreEqual(67, image.Height);
using (FileStream fs = File.OpenRead(Files.SnakewarePNG))
{
image.Read(fs);
Assert.AreEqual(286, image.Width);
Assert.AreEqual(67, image.Height);
Assert.AreEqual(MagickFormat.Png, image.Format);
}
image.Read(Files.SnakewarePNG);
Assert.AreEqual(286, image.Width);
Assert.AreEqual(67, image.Height);
Assert.AreEqual(MagickFormat.Png, image.Format);
image.Read(Files.Builtin.Rose);
Assert.AreEqual(70, image.Width);
Assert.AreEqual(46, image.Height);
Assert.AreEqual(MagickFormat.Ppm, image.Format);
image.Read(Files.RoseSparkleGIF);
Assert.AreEqual("RöseSparkle.gif", Path.GetFileName(image.FileName));
Assert.AreEqual(70, image.Width);
Assert.AreEqual(46, image.Height);
Assert.AreEqual(MagickFormat.Gif, image.Format);
image.Read("png:" + Files.SnakewarePNG);
Assert.AreEqual(286, image.Width);
Assert.AreEqual(67, image.Height);
Assert.AreEqual(MagickFormat.Png, image.Format);
MagickColor red = new MagickColor("red");
image.Read(red, 50, 50);
Assert.AreEqual(50, image.Width);
Assert.AreEqual(50, image.Height);
ColorAssert.AreEqual(red, image, 10, 10);
image.Read("xc:red", 50, 50);
Assert.AreEqual(50, image.Width);
Assert.AreEqual(50, image.Height);
ColorAssert.AreEqual(red, image, 5, 5);
using (FileStream fs = File.OpenRead(Files.ImageMagickJPG))
{
image.Read(fs);
fs.Position = 0;
using (FakePartialStream fakeStream = new FakePartialStream(fs))
{
using (MagickImage testImage = new MagickImage())
{
testImage.Read(fakeStream);
Assert.AreEqual(image.Width, testImage.Width);
Assert.AreEqual(image.Height, testImage.Height);
Assert.AreEqual(image.Format, testImage.Format);
Assert.AreEqual(0.0, image.Compare(testImage, ErrorMetric.RootMeanSquared));
}
}
}
image.Dispose();
//.........这里部分代码省略.........
示例12: Test_Ping
public void Test_Ping()
{
MagickImage image = new MagickImage();
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.Ping(new byte[0]);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Ping((byte[])null);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Ping((Stream)null);
});
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
{
image.Ping((string)null);
});
ExceptionAssert.Throws<ArgumentException>(delegate ()
{
image.Ping(Files.Missing);
});
image.Ping(Files.FujiFilmFinePixS1ProJPG);
Test_Ping(image);
Assert.AreEqual(600, image.Width);
Assert.AreEqual(400, image.Height);
image.Ping(new FileInfo(Files.FujiFilmFinePixS1ProJPG));
Test_Ping(image);
Assert.AreEqual(600, image.Width);
Assert.AreEqual(400, image.Height);
image.Ping(File.ReadAllBytes(Files.FujiFilmFinePixS1ProJPG));
Test_Ping(image);
Assert.AreEqual(600, image.Width);
Assert.AreEqual(400, image.Height);
image.Read(Files.SnakewarePNG);
Assert.AreEqual(286, image.Width);
Assert.AreEqual(67, image.Height);
using (PixelCollection pixels = image.GetPixels())
{
Assert.AreEqual(38324, pixels.ToArray().Length);
}
image.Dispose();
}
示例13: Test_Dispose
public void Test_Dispose()
{
MagickImage image = new MagickImage();
image.Dispose();
ExceptionAssert.Throws<ObjectDisposedException>(delegate ()
{
image.HasAlpha = true;
});
}
示例14: Test_PreserveCorruptImage
public void Test_PreserveCorruptImage()
{
MagickReadSettings settings = new MagickReadSettings()
{
Defines = new PngReadDefines()
{
PreserveCorruptImage = false
}
};
MagickImage image = new MagickImage();
try
{
image.Read(Files.CorruptPNG, settings);
}
catch (MagickCoderErrorException)
{
Assert.AreEqual(0, image.Width);
Assert.AreEqual(0, image.Height);
}
((PngReadDefines)settings.Defines).PreserveCorruptImage = true;
try
{
image.Read(Files.CorruptPNG, settings);
}
catch (MagickCoderErrorException)
{
Assert.AreEqual(1920, image.Width);
Assert.AreEqual(1440, image.Height);
}
finally
{
image.Dispose();
}
}
示例15: Test_Gamma
public void Test_Gamma()
{
MagickImage first = new MagickImage(Files.InvitationTif);
first.GammaCorrect(2.0);
MagickImage second = new MagickImage(Files.InvitationTif);
second.GammaCorrect(2.0, 1.0, 0.5);
Assert.AreNotEqual(first, second);
first.Dispose();
second.Dispose();
}