本文整理汇总了C#中Gdk.Pixbuf.SaveToBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Gdk.Pixbuf.SaveToBuffer方法的具体用法?C# Gdk.Pixbuf.SaveToBuffer怎么用?C# Gdk.Pixbuf.SaveToBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdk.Pixbuf
的用法示例。
在下文中一共展示了Gdk.Pixbuf.SaveToBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnButtonLoadPhotoClicked
protected void OnButtonLoadPhotoClicked(object sender, EventArgs e)
{
FileChooserDialog Chooser = new FileChooserDialog ("Выберите фото для загрузки...",
(Window)this.Toplevel,
FileChooserAction.Open,
"Отмена", ResponseType.Cancel,
"Загрузить", ResponseType.Accept);
FileFilter Filter = new FileFilter ();
Filter.AddPixbufFormats ();
Filter.Name = "Все изображения";
Chooser.AddFilter (Filter);
if ((ResponseType)Chooser.Run () == ResponseType.Accept) {
Chooser.Hide ();
logger.Info ("Загрузка фотографии...");
FileStream fs = new FileStream (Chooser.Filename, FileMode.Open, FileAccess.Read);
if (Chooser.Filename.ToLower ().EndsWith (".jpg")) {
using (MemoryStream ms = new MemoryStream ()) {
fs.CopyTo (ms);
ImageFile = ms.ToArray ();
}
} else {
logger.Info ("Конвертация в jpg ...");
Gdk.Pixbuf image = new Gdk.Pixbuf (fs);
ImageFile = image.SaveToBuffer ("jpeg");
}
fs.Close ();
buttonSavePhoto.Sensitive = true;
logger.Info ("Ok");
}
Chooser.Destroy ();
}
示例2: GtkGetImageFromText
/// <summary>Get the image from a file name on the clipboard</summary>
private static System.Drawing.Image GtkGetImageFromText()
{
var stringSeparators = new string[] { Environment.NewLine };
var paths = GetText().Split(stringSeparators, StringSplitOptions.None);
foreach (var path in paths)
{
if (File.Exists(path))
{
try
{
var bytes = File.ReadAllBytes(path);
var buff = new Gdk.Pixbuf(bytes);
TypeConverter tc = TypeDescriptor.GetConverter(typeof(System.Drawing.Bitmap));
return (System.Drawing.Image)tc.ConvertFrom(buff.SaveToBuffer("png"));
}
catch (Exception e)
{
Console.Out.WriteLine("{0} is not an image file ({1}).", path, e.Message);
}
}
}
return null;
}