本文整理汇总了C#中Image类的典型用法代码示例。如果您正苦于以下问题:C# Image类的具体用法?C# Image怎么用?C# Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Image类属于命名空间,在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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);
}
}
示例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();
}
示例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;
}
示例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;
}
示例6: Awake
void Awake()
{
if (this.gameObject.GetComponent<Image> () != null)
{
CanvasImage = this.gameObject.GetComponent<Image> ();
}
}
示例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;
}
示例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();
}
示例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);
}
}
}
}
}
示例10: Photo_Post
public Photo_Post(int postId, Image photo, string photoCaption, string photoName)
{
PostId = postId;
Photo = photo;
PhotoCaption = photoCaption;
PhotoName = photoName;
}
示例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.");
}
}
示例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();
}
示例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;
}
示例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();
}
示例15: ImageCropper
public ImageCropper(Image image, int maxWidth, int maxHeight, CropAnchor anchor)
{
_image = image;
_maxWidth = maxWidth;
_maxHeight = maxHeight;
_anchor = anchor;
}