本文整理汇总了C#中ImageFormat类的典型用法代码示例。如果您正苦于以下问题:C# ImageFormat类的具体用法?C# ImageFormat怎么用?C# ImageFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageFormat类属于命名空间,在下文中一共展示了ImageFormat类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TakeScreenShot
public static void TakeScreenShot(IWebDriver webDriver, string screenShotFileNameWithoutExtension, ImageFormat imageFormat, string screenShotDirectoryPath) {
Screenshot screenShot = null;
var browserName = string.Empty;
if (webDriver.GetType() == typeof(InternetExplorerDriver)) {
screenShot = ((InternetExplorerDriver)webDriver).GetScreenshot();
browserName = "IE";
}
if (webDriver.GetType() == typeof(FirefoxDriver)) {
screenShot = ((FirefoxDriver)webDriver).GetScreenshot();
browserName = "Firefox";
}
if (webDriver.GetType() == typeof(ChromeDriver)) {
screenShot = ((ChromeDriver)webDriver).GetScreenshot();
browserName = "Chrome";
}
var screenShotFileName = screenShotFileNameWithoutExtension + "." + imageFormat.ToString().ToLower();
if (screenShot != null) {
if (!string.IsNullOrEmpty(screenShotDirectoryPath)) {
Directory.CreateDirectory(screenShotDirectoryPath).CreateSubdirectory(browserName);
var browserScreenShotDirectoryPath = Path.Combine(screenShotDirectoryPath, browserName);
Directory.CreateDirectory(browserScreenShotDirectoryPath);
var screenShotFileFullPath = Path.Combine(browserScreenShotDirectoryPath, screenShotFileName);
screenShot.SaveAsFile(screenShotFileFullPath, imageFormat);
}
}
}
开发者ID:tablesmit,项目名称:browserscreenshots,代码行数:31,代码来源:Screenshots.cs
示例2: JFIFThumbnail
public JFIFThumbnail(byte[] palette, byte[] data)
: this()
{
Format = ImageFormat.BMPPalette;
Palette = palette;
PixelData = data;
}
开发者ID:cschadewitz,项目名称:exiflibrary,代码行数:7,代码来源:JFIFThumbnail.cs
示例3: GenerateImage
public MemoryStream GenerateImage(Visual vsual, int widhth, int height, ImageFormat format)
{
BitmapEncoder encoder = null;
switch (format)
{
case ImageFormat.JPG :
encoder = new JpegBitmapEncoder();
break;
case ImageFormat.PNG:
encoder = new PngBitmapEncoder();
break;
case ImageFormat.BMP:
encoder = new BmpBitmapEncoder();
break;
case ImageFormat.GIF:
encoder = new GifBitmapEncoder();
break;
case ImageFormat.TIF:
encoder = new TiffBitmapEncoder();
break;
}
if (encoder == null) return null;
RenderTargetBitmap rtb = this.RenderVisaulToBitmap(vsual, widhth, height);
MemoryStream file = new MemoryStream();
encoder.Frames.Add(BitmapFrame.Create(rtb));
encoder.Save(file);
return file;
}
开发者ID:enesyteam,项目名称:EChess,代码行数:33,代码来源:Model.cs
示例4: CropImageFile
public void CropImageFile(string savePath, string sPhysicalPath, string sOrgFileName, string sThumbNailFileName, ImageFormat oFormat, int targetW, int targetH, int targetX, int targetY)
{
try
{
Size tsize = new Size(targetW, targetH);
System.Drawing.Image oImg = System.Drawing.Image.FromFile(sPhysicalPath + @"\" + sOrgFileName);
System.Drawing.Image oThumbNail = new Bitmap(tsize.Width, tsize.Height, oImg.PixelFormat);
Graphics oGraphic = Graphics.FromImage(oThumbNail);
oGraphic.CompositingQuality = CompositingQuality.HighQuality;
oGraphic.SmoothingMode = SmoothingMode.HighQuality;
oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
oGraphic.DrawImage(oImg, new Rectangle(0, 0, targetW, targetH), targetX, targetY, targetW, targetH, GraphicsUnit.Pixel);
oThumbNail.Save(savePath + @"\" + sThumbNailFileName, oFormat);
oGraphic.Dispose();
oThumbNail.Dispose();
oImg.Dispose();
drag.Visible = false;
ddFiles2.SelectedItem.Text = sThumbNailFileName;
System.Drawing.Image origImg = System.Drawing.Image.FromFile(Server.MapPath("~/App_Uploads_Img/") + ddCat3.SelectedItem.Text + "/" + sThumbNailFileName);
divimage.InnerHtml = "<img src=" + epicCMSLib.Navigation.SiteRoot + "App_Uploads_Img/" + ddCat3.SelectedItem.Text + "/" + ddFiles2.SelectedItem.Text + "></img>";
Label8.Text = "Your selected Image's Width is " + origImg.Width.ToString() + "px and Height is " + origImg.Height.ToString() + "px.";
Hidden1.Value = origImg.Width.ToString();
Hidden2.Value = origImg.Height.ToString();
UpdatePanel3.Update();
lbSuccess3.ForeColor = System.Drawing.Color.Green;
lbSuccess3.Text = "Image " + sThumbNailFileName + " created.";
}
catch (Exception e1) { errorlabelcrop.ForeColor = System.Drawing.Color.Red;
errorlabelcrop.Text = e1.Message; }
}
开发者ID:wpdildine,项目名称:wwwroot,代码行数:31,代码来源:cropping.aspx.cs
示例5: GetImageEncoder
public static ImageCodecInfo GetImageEncoder(ImageFormat format)
{
return ImageCodecInfo.GetImageEncoders().ToList().Find(delegate(ImageCodecInfo codec)
{
return codec.FormatID == format.Guid;
});
}
开发者ID:fajoy,项目名称:RTSPExample,代码行数:7,代码来源:FrameHelper.cs
示例6: Save
public static void Save(this BitmapSource image, string filePath, ImageFormat format)
{
BitmapEncoder encoder = null;
switch(format)
{
case ImageFormat.Png:
encoder = new PngBitmapEncoder();
break;
case ImageFormat.Jpeg:
encoder = new JpegBitmapEncoder();
break;
case ImageFormat.Bmp:
encoder = new BmpBitmapEncoder();
break;
}
if (encoder == null)
return;
encoder.Frames.Add(BitmapFrame.Create(BitmapFrame.Create(image)));
using (var stream = new FileStream(filePath, FileMode.Create))
encoder.Save(stream);
}
开发者ID:kaorun55,项目名称:OpenNI.Toolkit,代码行数:25,代码来源:BitmapSourceExtensions.cs
示例7: SaveFromMemory
private static void SaveFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream, ImageFormat imageFormat)
{
using (var bitmap = new Bitmap(description.Width, description.Height))
{
var sourceArea = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
// Lock System.Drawing.Bitmap
var bitmapData = bitmap.LockBits(sourceArea, ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
try
{
// Copy memory
if (description.Format == PixelFormat.R8G8B8A8_UNorm || description.Format == PixelFormat.R8G8B8A8_UNorm_SRgb)
CopyMemoryBGRA(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
else if (description.Format == PixelFormat.B8G8R8A8_UNorm || description.Format == PixelFormat.B8G8R8A8_UNorm_SRgb)
Utilities.CopyMemory(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
else
throw new NotSupportedException(string.Format("Pixel format [{0}] is not supported", description.Format));
}
finally
{
bitmap.UnlockBits(bitmapData);
}
// Save
bitmap.Save(imageStream, imageFormat);
}
}
开发者ID:joewan,项目名称:xenko,代码行数:28,代码来源:StandardImageHelper.Windows.cs
示例8: ImageBuilder
public ImageBuilder(int width, int height, ImageFormat format)
{
this.width = width;
this.height = height;
backend = handler.CreateImageBuilder (width, height, format);
ctx = new Context (handler.CreateContext (backend));
}
开发者ID:pabloescribano,项目名称:xwt,代码行数:7,代码来源:ImageBuilder.cs
示例9: CreateImageBuilder
public override object CreateImageBuilder (int width, int height, ImageFormat format)
{
return new ImageBuilder () {
Width = width,
Height = height
};
}
开发者ID:m13253,项目名称:xwt,代码行数:7,代码来源:ImageBuilderBackendHandler.cs
示例10: CreateImageBuilder
public override object CreateImageBuilder (int width, int height, ImageFormat format)
{
var flags = CGBitmapFlags.ByteOrderDefault;
int bytesPerRow;
switch (format) {
case ImageFormat.ARGB32:
bytesPerRow = width * 4;
flags |= CGBitmapFlags.PremultipliedFirst;
break;
case ImageFormat.RGB24:
bytesPerRow = width * 3;
flags |= CGBitmapFlags.None;
break;
default:
throw new NotImplementedException ("ImageFormat: " + format.ToString ());
}
var bmp = new CGBitmapContext (IntPtr.Zero, width, height, 8, bytesPerRow, Util.DeviceRGBColorSpace, flags);
bmp.TranslateCTM (0, height);
bmp.ScaleCTM (1, -1);
return new CGContextBackend {
Context = bmp,
Size = new CGSize (width, height),
InverseViewTransform = bmp.GetCTM ().Invert ()
};
}
开发者ID:m13253,项目名称:xwt,代码行数:29,代码来源:ImageBuilderBackendHandler.cs
示例11: FromFile
public static Image FromFile(string fileName, ImageFormat format)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
return FromStream(stream, format);
}
}
开发者ID:smack0007,项目名称:SharpImage,代码行数:7,代码来源:Image.cs
示例12: ConvertAsync
/// <summary>
/// Converts a dot file to the requested image format
/// </summary>
/// <param name="dotFilePath">The path to the dot file to convert</param>
/// <param name="outputFilePath">The file path of where to save the image</param>
/// <param name="imageFormat">The image format to use when converitng the dot file</param>
/// <returns>A task representing the asynchronous operation</returns>
public Task ConvertAsync(string dotFilePath, string outputFilePath, ImageFormat imageFormat)
{
if (!File.Exists(dotFilePath))
{
throw new ArgumentException("The supplied dot file does not exist", "dotFilePath");
}
return Task.Run(() =>
{
const int sixtySeconds = 60 * 1000;
var outputFormat = Enum.GetName(typeof(ImageFormat), (int)imageFormat).ToLower();
var process = new Process
{
StartInfo = new ProcessStartInfo
{
Arguments = string.Format(@"-T{0} -o ""{1}"" ""{2}""", outputFormat, outputFilePath, dotFilePath),
CreateNoWindow = true,
FileName = Path.Combine(_GraphVizBinPath, "dot.exe"),
UseShellExecute = false
}
};
process.Start();
process.WaitForExit(sixtySeconds);
});
}
开发者ID:munumafia,项目名称:DotWatcher,代码行数:34,代码来源:DotFileImageConverterService.cs
示例13: AddWatermark
public void AddWatermark(string filename, ImageFormat imageFormat, Stream outputStream, HttpContext ctx)
{
Image bitmap = Image.FromFile(filename);
Font font = new Font("Arial", 13, FontStyle.Bold, GraphicsUnit.Pixel);
Random rnd = new Random();
Color color = Color.FromArgb(200, rnd.Next(255), rnd.Next(255), rnd.Next(255)); //Adds a black watermark with a low alpha value (almost transparent).
Point atPoint = new Point(bitmap.Width / 2 - 40, bitmap.Height / 2 - 7); //The pixel point to draw the watermark at (this example puts it at 100, 100 (x, y)).
SolidBrush brush = new SolidBrush(color);
string watermarkText = "voobrazi.by";
Graphics graphics;
try
{
graphics = Graphics.FromImage(bitmap);
}
catch
{
Image temp = bitmap;
bitmap = new Bitmap(bitmap.Width, bitmap.Height);
graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(temp, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel);
temp.Dispose();
}
graphics.DrawString(watermarkText, font, brush, atPoint);
graphics.Dispose();
bitmap.Save(outputStream, imageFormat);
bitmap.Dispose();
}
开发者ID:juliakolesen,项目名称:voobrazi.by,代码行数:31,代码来源:ImageHttpHandler.cs
示例14: GenerateImage
private void GenerateImage(
HttpResponse response,
string textToInsert,
int width,
int height,
Color backgroundColor,
FontFamily fontFamily,
float emSize,
Brush brush,
float x,
float y,
string contentType,
ImageFormat imageFormat)
{
using (Bitmap bitmap = new Bitmap(width, height))
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.Clear(backgroundColor);
graphics.DrawString(textToInsert, new Font(fontFamily, emSize), brush, x, y);
response.ContentType = contentType;
bitmap.Save(response.OutputStream, imageFormat);
}
}
}
开发者ID:nikolaynikolov,项目名称:Telerik,代码行数:25,代码来源:TextToImageHttpHandler.cs
示例15: ChartToImage
/// <summary>
///
/// </summary>
/// <param name="index"></param>
/// <param name="outputFileName"></param>
/// <param name="outputformat"></param>
public void ChartToImage(int index, string outputFileName, ImageFormat outputformat)
{
try
{
//check whether file is set or not
if (FileName == "")
throw new Exception("No file name specified");
else if (WorksheetName == "")
throw new Exception("No Worksheet name specified");
//build URI
string strURI = Aspose.Cloud.Common.Product.BaseProductUri + "/cells/" + FileName;
strURI += "/worksheets/" + WorksheetName + "/charts/" + index + "?format=" + outputformat;
//sign URI
string signedURI = Utils.Sign(strURI);
//get response stream
Stream responseStream = Utils.ProcessCommand(signedURI, "GET");
using (Stream fileStream = System.IO.File.OpenWrite(outputFileName))
{
Utils.CopyStream(responseStream, fileStream);
}
responseStream.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
开发者ID:peters,项目名称:Aspose_Cloud_SDK_For_.NET,代码行数:39,代码来源:Converter.cs
示例16: Recorder
/// <summary>
/// Constructor
/// </summary>
/// <param name="imageFormat">Image Format to save images as</param>
public Recorder(ImageFormat imageFormat = null)
{
if (imageFormat == null)
return;
this.imageFormat = imageFormat;
this.imageExtension = "." + imageFormat.ToString().ToLower();
}
开发者ID:Nhowka,项目名称:WebMCam,代码行数:12,代码来源:Recorder.cs
示例17: LoadAsync
public static async Task<IControl> LoadAsync(this ImageSource source, CancellationToken cancellationToken = default(CancellationToken), ImageFormat format = ImageFormat.Unknown)
{
if (source == null)
return null;
var handler = Registrar.Registered.GetHandler<IImageSourceHandler>(source.GetType());
return await handler.GetImageAsync(source, format, cancellationToken);
}
开发者ID:powerdude,项目名称:xamarin-forms-xna,代码行数:8,代码来源:Extensions.cs
示例18: ImageBuilder
public ImageBuilder(int width, int height, ImageFormat format)
{
handler = ToolkitEngine.ImageBuilderBackendHandler;
this.width = width;
this.height = height;
backend = handler.CreateImageBuilder (width, height, format);
ctx = new Context (handler.CreateContext (backend), ToolkitEngine);
}
开发者ID:garuma,项目名称:xwt,代码行数:8,代码来源:ImageBuilder.cs
示例19: GetExtension
private string GetExtension(ImageFormat imageFormat)
{
if (imageFormat == ImageFormat.Png)
return "png";
else if (imageFormat == ImageFormat.Jpeg)
return "jpg";
else
throw new ArgumentOutOfRangeException("imageFormat");
}
开发者ID:meze,项目名称:betteamsbattle,代码行数:9,代码来源:BetScreenshotPathService.cs
示例20: GetImage
public async Task<IControl> GetImage(UriImageSource source, ImageFormat format)
{
using (var stream = await Forms.UpdateContext.Wait(source.GetStreamAsync()))
{
if (stream == null)
throw new ArgumentException("Resource not found", "source");
return await ImageFactory.CreateFromStream(stream, format, CancellationToken.None);
}
}
开发者ID:powerdude,项目名称:xamarin-forms-xna,代码行数:9,代码来源:UriImageSourceHandler.cs
注:本文中的ImageFormat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论