本文整理汇总了C#中System.Drawing.Imaging.ImageFormat类的典型用法代码示例。如果您正苦于以下问题:C# ImageFormat类的具体用法?C# ImageFormat怎么用?C# ImageFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageFormat类属于System.Drawing.Imaging命名空间,在下文中一共展示了ImageFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
/// <summary>
/// Saves the specified render target as an image with the specified format.
/// </summary>
/// <param name="renderTarget">The render target to save.</param>
/// <param name="stream">The stream to which to save the render target data.</param>
/// <param name="format">The format with which to save the image.</param>
private void Save(RenderTarget2D renderTarget, Stream stream, ImageFormat format)
{
var data = new Color[renderTarget.Width * renderTarget.Height];
renderTarget.GetData(data);
Save(data, renderTarget.Width, renderTarget.Height, stream, format);
}
示例2: SaveImage
public void SaveImage(string filename, ImageFormat format)
{
if (bitmap != null)
{
bitmap.Save(filename, format);
}
}
示例3: CompressImage
public static MemoryStream CompressImage(ImageFormat format, Stream stream, Size size, bool isbig)
{
using (var image = Image.FromStream(stream))
{
Image bitmap = new Bitmap(size.Width, size.Height);
Graphics g = Graphics.FromImage(bitmap);
g.InterpolationMode = InterpolationMode.High;
g.SmoothingMode = SmoothingMode.HighQuality;
g.Clear(Color.Transparent);
//按指定面积缩小
if (!isbig)
{
g.DrawImage(image,
new Rectangle(0, 0, size.Width, size.Height),
ImageCutSize(image, size),
GraphicsUnit.Pixel);
}
//按等比例缩小
else
{
g.DrawImage(image,
new Rectangle(0, 0, size.Width, size.Height),
new Rectangle(0, 0, image.Width, image.Height),
GraphicsUnit.Pixel);
}
var compressedImageStream = new MemoryStream();
bitmap.Save(compressedImageStream, format);
g.Dispose();
bitmap.Dispose();
return compressedImageStream;
}
}
示例4: CreateImageFrom
public static ImageResult CreateImageFrom(byte[] bytes, ImageFormat format)
{
byte[] nonIndexedImageBytes;
using (var memoryStream = new MemoryStream(bytes))
using (var image = Image.FromStream(memoryStream))
using (var temporaryBitmap = new Bitmap(image.Width, image.Height))
{
using (var graphics = Graphics.FromImage(temporaryBitmap))
{
graphics.DrawImage(image, new Rectangle(0, 0, temporaryBitmap.Width, temporaryBitmap.Height),
0, 0, temporaryBitmap.Width, temporaryBitmap.Height, GraphicsUnit.Pixel);
}
ImagePropertyItems.Copy(image, temporaryBitmap);
using (var saveStream = new MemoryStream())
{
temporaryBitmap.Save(saveStream, format);
nonIndexedImageBytes = saveStream.ToArray();
}
}
return new ImageResult(nonIndexedImageBytes, format);
}
示例5: ReturnImage
protected void ReturnImage(HttpContextBase context, string file, ImageFormat imageFormat, string contentType)
{
var buffer = GetImage(file, imageFormat);
context.Response.ContentType = "image/png";
context.Response.BinaryWrite(buffer);
context.Response.Flush();
}
示例6: frmFondo
/// <summary>
/// Constructor por defecto.
/// </summary>
public frmFondo(string ruta, ImageFormat formato, bool original, int width, int height)
{
InitializeComponent();
this.original = original;
this.width = width;
this.height = height;
//Establecemos el ancho de la forma a la resolución actual de pantalla
this.Bounds = Screen.GetBounds(this.ClientRectangle);
//Inicializamos las variables
origen = new Point(0, 0);
destino = new Point(0, 0);
actual = new Point(0, 0);
//De momento nuestro gráfico es nulo
areaSeleccionada = this.CreateGraphics();
//El estilo de línea del lápiz serán puntos
lapizActual.DashStyle = DashStyle.Solid;
//Establecemos falsa la variable que nos indica si el boton presionado fue el boton izquierdo
BotonIzq = false;
//Delegados para manejar los eventos del mouse y poder dibujar el rectangulo del área que deseamos copiar
this.MouseDown += new MouseEventHandler(mouse_Click);
this.MouseUp += new MouseEventHandler(mouse_Up);
this.MouseMove += new MouseEventHandler(mouse_Move);
this.ruta = ruta;
this.formato = formato;
}
示例7: GetResizedImage
byte[] GetResizedImage(Stream originalStream, ImageFormat imageFormat, int width, int height)
{
Bitmap imgIn = new Bitmap(originalStream);
double y = imgIn.Height;
double x = imgIn.Width;
double factor = 1;
if (width > 0)
{
factor = width / x;
}
else if (height > 0)
{
factor = height / y;
}
System.IO.MemoryStream outStream = new System.IO.MemoryStream();
Bitmap imgOut = new Bitmap((int)(x * factor), (int)(y * factor));
// Set DPI of image (xDpi, yDpi)
imgOut.SetResolution(72, 72);
Graphics g = Graphics.FromImage(imgOut);
g.Clear(Color.White);
g.DrawImage(imgIn, new Rectangle(0, 0, (int)(factor * x), (int)(factor * y)),
new Rectangle(0, 0, (int)x, (int)y), GraphicsUnit.Pixel);
imgOut.Save(outStream, imageFormat);
return outStream.ToArray();
}
示例8: Set
public static void Set(Uri uri, Style style, ImageFormat format)
{
Stream stream = new WebClient().OpenRead(uri.ToString());
if (stream == null) return;
Image img = Image.FromStream(stream);
string tempPath = Path.Combine(Path.GetTempPath(), "img." + format.ToString());
img.Save(tempPath, format);
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
if (style == Style.Stretched)
{
key.SetValue(@"WallpaperStyle", 2.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Centered)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
}
if (style == Style.Tiled)
{
key.SetValue(@"WallpaperStyle", 1.ToString());
key.SetValue(@"TileWallpaper", 1.ToString());
}
SystemParametersInfo(SpiSetdeskwallpaper,
0,
tempPath,
SpifUpdateinifile | SpifSendwininichange);
}
示例9: Save
public static void Save(Stream imageStream, string fullImagePath, ImageFormat format)
{
using (Bitmap ImageBitmap = new Bitmap(imageStream))
{
Save(ImageBitmap, fullImagePath, format);
}
}
示例10: ResizeImage
public static Stream ResizeImage(Image image, ImageFormat format, int width, int height, bool preserveAspectRatio = true)
{
ImageHelper.ImageRotation(image);
int newWidth;
int newHeight;
if (preserveAspectRatio)
{
int originalWidth = image.Width;
int originalHeight = image.Height;
float percentWidth = (float)width / (float)originalWidth;
float percentHeight = (float)height / (float)originalHeight;
float percent = percentHeight < percentWidth ? percentHeight : percentWidth;
newWidth = (int)(originalWidth * percent);
newHeight = (int)(originalHeight * percent);
}
else
{
newWidth = width;
newHeight = height;
}
Image newImage = new Bitmap(newWidth, newHeight);
using (Graphics graphicsHandle = Graphics.FromImage(newImage))
{
graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphicsHandle.DrawImage(image, 0, 0, newWidth, newHeight);
}
//return newImage;
var stream = new MemoryStream();
newImage.Save(stream, format);
stream.Position = 0;
return stream;
}
示例11: Save
public static Stream Save(this Bitmap bitmap, ImageFormat format)
{
var stream = new MemoryStream();
bitmap.Save(stream, format);
stream.Position = 0;
return stream;
}
示例12: ScanImage
public Image ScanImage(ImageFormat outputFormat, string fileName)
{
if (outputFormat == null)
throw new ArgumentNullException("outputFormat");
FileIOPermission filePerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, fileName);
filePerm.Demand();
ImageFile imageObject = null;
try
{
if (WiaManager == null)
WiaManager = new CommonDialogClass();
imageObject =
WiaManager.ShowAcquireImage(WiaDeviceType.ScannerDeviceType,
WiaImageIntent.GrayscaleIntent, WiaImageBias.MaximizeQuality,
outputFormat.Guid.ToString("B"), false, true, true);
imageObject.SaveFile(fileName);
return Image.FromFile(fileName);
}
catch (COMException ex)
{
string message = "Error scanning image";
throw new WiaOperationException(message, ex);
}
finally
{
if (imageObject != null)
Marshal.ReleaseComObject(imageObject);
}
}
示例13: ToBitmapSource
/// <summary>
/// To the bitmap source.
/// </summary>
/// <param name="bitmap">The bitmap.</param>
/// <param name="format">The format.</param>
/// <param name="creationOptions">The creation options.</param>
/// <param name="cacheOptions">The cache options.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">bitmap</exception>
public static BitmapSource ToBitmapSource(this Bitmap bitmap, ImageFormat format, BitmapCreateOptions creationOptions = BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption cacheOptions = BitmapCacheOption.OnLoad)
{
if (bitmap == null)
throw new ArgumentNullException("bitmap");
using (MemoryStream memoryStream = new MemoryStream())
{
try
{
// You need to specify the image format to fill the stream.
// I'm assuming it is PNG
bitmap.Save(memoryStream, format);
memoryStream.Seek(0, SeekOrigin.Begin);
BitmapDecoder bitmapDecoder = BitmapDecoder.Create(
memoryStream,
creationOptions,
cacheOptions);
// This will disconnect the stream from the image completely...
WriteableBitmap writable =
new WriteableBitmap(bitmapDecoder.Frames.Single());
writable.Freeze();
return writable;
}
catch (Exception)
{
return null;
}
}
}
示例14: SaveImageAs
private void SaveImageAs(int bitmap, string fileName, ImageFormat imageFormat)
{
Bitmap image = new Bitmap(Image.FromHbitmap(new IntPtr(bitmap)),
Image.FromHbitmap(new IntPtr(bitmap)).Width,
Image.FromHbitmap(new IntPtr(bitmap)).Height);
image.Save(fileName, imageFormat);
}
示例15: 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);
}
}
}