本文整理汇总了C#中Image类的典型用法代码示例。如果您正苦于以下问题:C# Image类的具体用法?C# Image怎么用?C# Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Image类属于命名空间,在下文中一共展示了Image类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ImageToBytes
/// <summary>
/// Convert Image to Byte[]
/// Image img = Image.FromFile("c:\\hcha.jpg");
/// </summary>
/// <param name="image"></param>
/// <returns></returns>
public static byte[] ImageToBytes(Image image)
{
ImageFormat format = image.RawFormat;
using (MemoryStream ms = new MemoryStream())
{
if (format.Equals(ImageFormat.Jpeg))
{
image.Save(ms, ImageFormat.Jpeg);
}
else if (format.Equals(ImageFormat.Png))
{
image.Save(ms, ImageFormat.Png);
}
else if (format.Equals(ImageFormat.Bmp))
{
image.Save(ms, ImageFormat.Bmp);
}
else if (format.Equals(ImageFormat.Gif))
{
image.Save(ms, ImageFormat.Gif);
}
else if (format.Equals(ImageFormat.Icon))
{
image.Save(ms, ImageFormat.Icon);
}
byte[] buffer = new byte[ms.Length];
//Image.Save()会改变MemoryStream的Position,需要重新Seek到Begin
ms.Seek(0, SeekOrigin.Begin);
ms.Read(buffer, 0, buffer.Length);
return buffer;
}
}
开发者ID:crayoncode,项目名称:CrayonCode.Platform,代码行数:38,代码来源:ImageHelper.cs
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=F:\git\web-application-dev\online_album\App_Data\Database1.mdf;Integrated Security=True"); //创建连接对象
con.Open();
SqlCommand cmd = new SqlCommand("select * from [photo]", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Panel box = new Panel();
box.CssClass = "box";
Panel1.Controls.Add(box);
Image photo = new Image();
photo.CssClass = "photo";
photo.ImageUrl = "~/Images/" + dr["uid"].ToString() + "/" + dr["filename"].ToString(); ;
box.Controls.Add(photo);
box.Controls.Add(new Literal() { Text = "<br />" });
Label uid = new Label();
uid.Text = dr["uid"].ToString();
box.Controls.Add(uid);
box.Controls.Add(new Literal() { Text = "<br />" });
Label datetime = new Label();
datetime.Text = dr["datetime"].ToString();
box.Controls.Add(datetime);
}
}
开发者ID:do-you,项目名称:web-application-dev,代码行数:31,代码来源:index.aspx.cs
示例3: ShowDetail
public static void ShowDetail(Image img)
{
FileItem fileItem = img.Tag as FileItem;
if (fileItem == null) return;
MoreInfo moreInfo = new MoreInfo(fileItem.Name, fileItem.FullName, fileItem.IconAssociated);
moreInfo.ShowDialog();
}
开发者ID:pankajbhandari08,项目名称:windows-tweaker,代码行数:7,代码来源:OpenWithTask.cs
示例4: ProcessFrame
private void ProcessFrame(object sender, EventArgs arg)
{
frame = capture.QueryFrame();
if (frame != null)
{
// add cross hairs to image
int totalwidth = frame.Width;
int totalheight = frame.Height;
PointF[] linepointshor = new PointF[] {
new PointF(0, totalheight/2),
new PointF(totalwidth, totalheight/2)
};
PointF[] linepointsver = new PointF[] {
new PointF(totalwidth/2, 0),
new PointF(totalwidth/2, totalheight)
};
frame.DrawPolyline(Array.ConvertAll<PointF, System.Drawing.Point>(linepointshor, System.Drawing.Point.Round), false, new Bgr(System.Drawing.Color.AntiqueWhite), 1);
frame.DrawPolyline(Array.ConvertAll<PointF, System.Drawing.Point>(linepointsver, System.Drawing.Point.Round), false, new Bgr(System.Drawing.Color.AntiqueWhite), 1);
}
CapturedImageBox.Image = frame;
}
开发者ID:glocklueng,项目名称:ModernUI-Pick-and-Place-Controller-Software,代码行数:32,代码来源:CameraWindow.xaml.cs
示例5: Mark
public Image Mark( Image image, string waterMarkText )
{
WatermarkText = waterMarkText;
Bitmap originalBmp = (Bitmap)image;
// avoid "A Graphics object cannot be created from an image that has an indexed pixel format." exception
Bitmap tempBitmap = new Bitmap(originalBmp.Width, originalBmp.Height);
// From this bitmap, the graphics can be obtained, because it has the right PixelFormat
Graphics g = Graphics.FromImage(tempBitmap);
using (Graphics graphics = Graphics.FromImage(tempBitmap))
{
// Draw the original bitmap onto the graphics of the new bitmap
g.DrawImage(originalBmp, 0, 0);
var size =
graphics.MeasureString(WatermarkText, Font);
var brush =
new SolidBrush(Color.FromArgb(255, Color));
graphics.DrawString
(WatermarkText, Font, brush,
GetTextPosition(image, size));
}
return tempBitmap as Image;
}
开发者ID:Esri,项目名称:arcobjects-sdk-community-samples,代码行数:26,代码来源:ApplyWatermark.cs
示例6: Awake
void Awake()
{
if (this.gameObject.GetComponent<Image> () != null)
{
CanvasImage = this.gameObject.GetComponent<Image> ();
}
}
开发者ID:cuongngo90,项目名称:Unity-SpriteShader,代码行数:7,代码来源:_2dxFX_Pixel8bitsBW.cs
示例7: GetAveraging
public Image<Bgr, Byte> GetAveraging(Image<Bgr, Byte> sourceImage, int matrixWidthSize, int matrixHeightSize)
{
Image<Bgr, Byte> image = new Image<Bgr, Byte>(sourceImage.Width, sourceImage.Height);
for (int y = 0; y < sourceImage.Height; y++)
{
for (int x = 0; x < sourceImage.Width; x++)
{
int n = 0;
int[] value = new int[3];
int my = y - matrixHeightSize / 2;
my = Math.Max(my, 0);
int mx = x - matrixWidthSize / 2;
mx = Math.Max(mx, 0);
for (int i = 0; i < matrixHeightSize && my + i < sourceImage.Height; i++)
{
for (int j = 0; j < matrixWidthSize && mx + j < sourceImage.Width; j++)
{
for (int z = 0; z < sourceImage.Data.GetLength(2); z++)
{
value[z] += sourceImage.Data[my + i, mx + j, z];
}
n++;
}
}
n = Math.Max(n, 1);
for (int z = 0; z < sourceImage.Data.GetLength(2); z++)
{
image.Data[y, x, z] = (byte)(value[z] / n);
}
}
}
return image;
}
开发者ID:visualcshape,项目名称:ImageProcess,代码行数:33,代码来源:ImageProcessFunctions.cs
示例8: Show
/// <summary>
/// Shows the dialog with the specified image.
/// </summary>
/// <param name="owner">The owner.</param>
/// <param name="title">The title.</param>
/// <param name="image">The image.</param>
public void Show(IWin32Window owner, string title, Image image)
{
this.ClientSize = image.Size;
this.Text = title;
this.pictureBox.Image = image;
base.ShowDialog();
}
开发者ID:alexbikfalvi,项目名称:InetAnalytics,代码行数:13,代码来源:FormImage.cs
示例9: grdCourses_RowDataBound
protected void grdCourses_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (IsPostBack)
{
if (e.Row.RowType == DataControlRowType.Header)
{
Image SortImage = new Image();
for (int i = 0; i <= grdCourses.Columns.Count - 1; i++)
{
if (grdCourses.Columns[i].SortExpression == Session["SortColumn"].ToString())
{
if (Session["SortDirection"].ToString() == "DESC")
{
SortImage.ImageUrl = "/images/desc.jpg";
SortImage.AlternateText = "Sort Descending";
}
else
{
SortImage.ImageUrl = "/images/asc.jpg";
SortImage.AlternateText = "Sort Ascending";
}
e.Row.Cells[i].Controls.Add(SortImage);
}
}
}
}
}
开发者ID:ifotn,项目名称:comp2007-lesson10-mon,代码行数:31,代码来源:courses.aspx.cs
示例10: Photo_Post
public Photo_Post(int postId, Image photo, string photoCaption, string photoName)
{
PostId = postId;
Photo = photo;
PhotoCaption = photoCaption;
PhotoName = photoName;
}
开发者ID:Ndiya999,项目名称:Bulabula,代码行数:7,代码来源:Photo_Post.cs
示例11: Start
public void Start()
{
_image = GetComponent<Image>();
Texture2D tex = _image.sprite.texture as Texture2D;
bool isInvalid = false;
if (tex != null)
{
try
{
tex.GetPixels32();
}
catch (UnityException e)
{
Debug.LogError(e.Message);
isInvalid = true;
}
}
else
{
isInvalid = true;
}
if (isInvalid)
{
Debug.LogError("This script need an Image with a readbale Texture2D to work.");
}
}
开发者ID:JustJessTV,项目名称:GitMergeTest,代码行数:29,代码来源:AlphaButtonClickMask.cs
示例12: Render
public override void Render(Image image, double x, double y,
double w, double h)
{
x *= _zoom;
y *= _zoom;
w *= _zoom;
h *= _zoom;
int ix = _offx + (int) x;
int iy = _offy + (int) y;
int iw = (int) w;
int ih = (int) h;
if (ix + iw == _pw)
iw--;
if (iy + ih == _ph)
ih--;
_pixmap.DrawRectangle(_gc, false, ix, iy, iw, ih);
_pixmap.DrawRectangle(_gc, true, ix, iy, iw, ih);
var clone = RotateAndScale(image, w, h);
int tw = clone.Width;
int th = clone.Height;
ix += (iw - tw) / 2;
iy += (ih - th) / 2;
var pixbuf = clone.GetThumbnail(tw, th, Transparency.KeepAlpha);
pixbuf.RenderToDrawable(_pixmap, _gc, 0, 0, ix, iy, -1, -1,
RgbDither.Normal, 0, 0);
pixbuf.Dispose();
}
开发者ID:unhammer,项目名称:gimp-sharp,代码行数:34,代码来源:PreviewRenderer.cs
示例13: MenuCell
public MenuCell()
{
image = new Image {
HeightRequest = 20,
WidthRequest = 20,
};
image.Opacity = 0.5;
// image.SetBinding(Image.SourceProperty, ImageSrc);
label = new Label
{
YAlign = TextAlignment.Center,
TextColor = Color.Gray,
};
var layout = new StackLayout
{
// BackgroundColor = Color.FromHex("2C3E50"),
BackgroundColor = Color.White,
Padding = new Thickness(20, 0, 0, 0),
Orientation = StackOrientation.Horizontal,
Spacing = 20,
//HorizontalOptions = LayoutOptions.StartAndExpand,
Children = { image,label }
};
View = layout;
}
开发者ID:segmond,项目名称:CPXamarin,代码行数:30,代码来源:MenuCell.cs
示例14: Cursor
public Cursor(Image regular, Image clicked)
: base(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), regular)
{
Layer = int.MaxValue;
Regular = regular; Clicked = clicked;
Regular.Parallax = new Vector2(); Clicked.Parallax = new Vector2();
}
开发者ID:hjeldin,项目名称:XNAPunk,代码行数:7,代码来源:Cursor.cs
示例15: ImageCropper
public ImageCropper(Image image, int maxWidth, int maxHeight, CropAnchor anchor)
{
_image = image;
_maxWidth = maxWidth;
_maxHeight = maxHeight;
_anchor = anchor;
}
开发者ID:GorelH,项目名称:FluentImageResizing,代码行数:7,代码来源:ImageCropper.cs
示例16: TaskElement
public TaskElement()
{
InitializeComponent();
this.progress = this.FindName("Progress") as Image;
this.success = this.FindName("Success") as Image;
this.fail = this.FindName("Fail") as Image;
}
开发者ID:AssafShalin,项目名称:Hung,代码行数:7,代码来源:TaskElement.xaml.cs
示例17: TipSpomenika
public TipSpomenika(string sifra, string ime, string opis, Image ikonica)
{
this.SifraTipaSpomenika = sifra;
this.ImeTipa = ime;
this.Opis = opis;
this.Ikonica = ikonica;
}
开发者ID:nikolalsvk,项目名称:world-monuments-record,代码行数:7,代码来源:TipSpomenika.cs
示例18: ProcessImage
private void ProcessImage(Image<Bgr, byte> image)
{
Stopwatch watch = Stopwatch.StartNew(); // time the detection process
List<Image<Gray, Byte>> licensePlateImagesList = new List<Image<Gray, byte>>();
List<Image<Gray, Byte>> filteredLicensePlateImagesList = new List<Image<Gray, byte>>();
List<MCvBox2D> licenseBoxList = new List<MCvBox2D>();
List<List<Word>> words = _licensePlateDetector.DetectLicensePlate(
image,
licensePlateImagesList,
filteredLicensePlateImagesList,
licenseBoxList);
watch.Stop(); //stop the timer
processTimeLabel.Text = String.Format("License Plate Recognition time: {0} milli-seconds", watch.Elapsed.TotalMilliseconds);
panel1.Controls.Clear();
Point startPoint = new Point(10, 10);
for (int i = 0; i < words.Count; i++)
{
AddLabelAndImage(
ref startPoint,
String.Format("License: {0}", String.Join(" ", words[i].ConvertAll<String>(delegate(Word w) { return w.Text; }).ToArray())),
licensePlateImagesList[i].ConcateVertical(filteredLicensePlateImagesList[i]));
image.Draw(licenseBoxList[i], new Bgr(Color.Red), 2);
}
imageBox1.Image = image;
}
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:29,代码来源:LicensePlateRecognitionForm.cs
示例19: Start
void Start () {
thisImage = this.GetComponent<Image> ();
if (locked == true) {
thisImage.sprite = LockedImage;
GetComponent<Button>().interactable=false;
}
}
开发者ID:yuu416fgx8mlight,项目名称:GGJ2016_HDS,代码行数:7,代码来源:ButtonUnlock.cs
示例20: Convert
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var img = _imageConverter.Convert(value, targetType, parameter, culture) as BitmapImage;
if (img == null) return Binding.DoNothing;
var result = new Image() { Source = img };
var strParam = parameter as string;
if (strParam != null)
{
var dim = strParam.Split(',');
if (dim != null && dim.Length == 2)
{
int w, h;
if (int.TryParse(dim[0], out w))
{
result.MaxWidth = w;
}
if (int.TryParse(dim[1], out h))
{
result.MaxHeight = h;
}
}
}
return result;
}
开发者ID:daszat,项目名称:zetbox,代码行数:27,代码来源:ImageCtrlConverter.cs
注:本文中的Image类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论