本文整理汇总了C#中System.Drawing.Bitmap.ResizeImage方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.ResizeImage方法的具体用法?C# Bitmap.ResizeImage怎么用?C# Bitmap.ResizeImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.ResizeImage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImageImport
public static bool ImageImport(this DeviceModel deviceModel, Stream ImageStream)
{
try
{
using (Bitmap inputBitmap = new Bitmap(ImageStream))
{
using (Image outputBitmap = inputBitmap.ResizeImage(256, 256))
{
using (MemoryStream ms = new MemoryStream())
{
outputBitmap.SavePng(ms);
ms.Position = 0;
var deviceModelImagePath = deviceModel.ImageFilePath();
using (var storeStream = new FileStream(deviceModelImagePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
ms.CopyTo(storeStream);
}
//deviceModel.Image = ms.ToArray();
}
}
}
return true;
}
catch (Exception)
{
return false;
}
}
示例2: TestResizeImageToMaximumDimension
public void TestResizeImageToMaximumDimension()
{
using (var image = new Bitmap(ImageLocation))
{
var resizedImage = image.ResizeImage(90);
Assert.AreEqual(90, resizedImage.Width);
resizedImage.Dispose();
}
}
示例3: TestResizeImage
public void TestResizeImage()
{
using (var image = new Bitmap(ImageLocation))
{
var resizedImage = image.ResizeImage(320, 200);
Assert.AreEqual(320, resizedImage.Width);
Assert.AreEqual(200, resizedImage.Height);
resizedImage.Dispose();
}
}
示例4: ResizeImage
public static byte[] ResizeImage(this byte[] imageBytes, int width, int height)
{
try
{
using (MemoryStream streamInput = new MemoryStream(imageBytes))
{
System.Drawing.Image image = new Bitmap(streamInput);
ImageFormat oldFormat = image.RawFormat;
image = image.ResizeImage(width, height);
byte[] result = image.GetBytes(oldFormat);
return result;
}
}
catch (Exception ex)
{
return imageBytes;
}
}
示例5: Image
public ActionResult Image(string imageFile, int? width, int? height, int? id)
{
var memoryStream = new MemoryStream();
var image = new Bitmap(ObjectsRepository.CatalogFolder + imageFile.Replace("___", "/"));
if (width != null && height != null)
{
image = image.Clip10X15();
image = image.ResizeImage(width.Value, height.Value);
}
if (id != null)
{
image = image.AddBluredRect(30);
var htmlText = ObjectsRepository.GetObjectDescription(id.Value);
if (!string.IsNullOrEmpty(htmlText))
{
image = image.AddText(30, 0, htmlText);
}
//var backImage = new Bitmap(Server.MapPath("~\\Content\\images\\keyend.png"));
//image = image.AddBackBitmap(backImage);
}
image.Save(memoryStream, ImageFormat.Jpeg);
memoryStream.Seek(0, SeekOrigin.Begin);
return File(memoryStream, "image/jpeg");
}
示例6: PasteScaledBitmapImageToTileByLatLon
void PasteScaledBitmapImageToTileByLatLon(int zoom, double Lon, double Lat, int xTile, int yTile, double scale, Bitmap iconImage)
{
int width = iconImage.Width;
int height = iconImage.Height;
if (scale != 1.0)
{
width = (int)(width * scale);
height = (int)(height * scale);
}
CopyRegionIntoImage(iconImage.ResizeImage((width), (height )), new Rectangle(0, 0, width, height), GetTargetBound(zoom, Lon, Lat, xTile, yTile, width, height));
}
示例7: PasteIcon
void PasteIcon(Bitmap icon, int x, int y, double scale)
{
int width = icon.Width;
int height = icon.Height;
if (scale != 1.0)
{
icon.ResizeImage((int)(width * scale), (int)(height * scale));
width = (int)(width * scale);
height = (int)(height * scale);
}
CopyRegionIntoImage(icon, new Rectangle(0, 0, width, height), new Rectangle(x, y, width, width));
}
示例8: LoadExternalMugshots
/// <summary>
/// Load all external mugshots into the cache.
/// </summary>
private static void LoadExternalMugshots()
{
string mugshotFolder = Path.Combine(CIX.HomeFolder, "Mugshots");
if (Directory.Exists(mugshotFolder))
{
string[] allFiles = Directory.GetFiles(mugshotFolder);
foreach (string filename in allFiles)
{
try
{
string username = Path.GetFileNameWithoutExtension(filename);
Image mugshotImage = new Bitmap(filename);
mugshotImage = mugshotImage.ResizeImage(MaxMugshotWidth, MaxMugshotHeight);
if (username != null && mugshotImage != null)
{
Mugshot mugshot = new Mugshot();
ImageConverter converter = new ImageConverter();
mugshot.Image = (byte[])converter.ConvertTo(mugshotImage, typeof(byte[]));
mugshot.Username = username;
Cache[username] = mugshot;
}
}
catch (Exception e)
{
LogFile.WriteLine("Error loading {0} : {1}", filename, e.Message);
}
}
}
}