/// <summary> /// Draw this image to the current OpenVG drawing surface. /// </summary> public void Draw() { if (handle == null) { throw new ObjectDisposedException("Some Image"); } VG.vgDrawImage(handle); VG.DetectError("Draw Image failed"); draws.Add(1.0); }
internal void Draw() { if (handle == null) { throw new ObjectDisposedException("Some Path"); } VG.vgDrawPath(handle); VG.DetectError("Draw Path failed"); draws.Add(1.0); }
/// <summary> /// Sets the image contents /// </summary> /// <param name="data">The pixel data</param> /// <param name="scanlinestride">Offset for consecutive scan lines of the image in data.</param> /// <param name="destination">The rectangle of the image to fill</param> /// <remarks> /// The pixels should be packed into data with the pixel format used to construct this image. /// There is no offset between pixels on a line. Consecutive lines are placed at scanlinestride intervals, measured /// from line start to line start. /// </remarks> public void SetImageData(byte[] data, int scanlinestride, Rect destination) { if (handle == null) { throw new ObjectDisposedException("Some Image"); } int lastbyte = (scanlinestride * ((int)destination.size.y - 1)) + (int)destination.size.x; if (data == null || lastbyte < 0 || data.Length < lastbyte) { throw new ArgumentException("Expected " + lastbyte + " bytes, got " + (data == null ? "null" : data.Length.ToString())); } VG.vgImageSubData(handle, data, scanlinestride, Format, destination.pos.x, destination.pos.y, destination.size.x, destination.size.y); VG.DetectError("Set image data failed"); }
protected override void Load() { IntPtr hnd = VG.vgCreatePath(0, 3, 1, 0, 0, 0, 6); if (hnd == IntPtr.Zero) { throw new Exception("Error creating Path " + VG.vgGetError()); } handle = new Handle("OpenVG Path", hnd, delegate(IntPtr h) { VG.vgDestroyPath(h); }); List <byte> segments = new List <byte>(); List <float> data = new List <float>(); foreach (Segment s in source()) { segments.Add((byte)s.type); data.AddRange(s.data); } VG.vgAppendPathData(handle, segments.Count, segments.ToArray(), data.ToArray()); VG.DetectError("Unable to append path data"); }
protected override void Load() { if (handle != null) { return; } IntPtr hnd = VG.vgCreateImage(Format, (int)Size.x, (int)Size.y, ImageRenderQuality.Better | ImageRenderQuality.Faster); if (hnd == IntPtr.Zero) { throw new Exception("Error creating Image " + VG.vgGetError()); } handle = new Handle("OpenVG Image", hnd, delegate(IntPtr h) { VG.vgDestroyImage(h); }); if (DataSource != null) { byte[] data = DataSource(); SetImageData(data, data.Length / (int)Size.y, new Rect(Vector2.Zero, Size)); } }
public void DumpParameters() { Console.WriteLine("Parameters for Image " + ((IntPtr)handle).ToString("X")); VG.DumpContext(handle); }
public static object Get(Parameter p, IntPtr handle) { object[] attrs = typeof(Parameter).GetField(typeof(Parameter).GetEnumName(p)).GetCustomAttributes(typeof(ParameterInfoAttribute), false); ParameterInfoAttribute item; if (attrs.Length > 0) { item = (ParameterInfoAttribute)attrs[0]; } else { item = new ParameterInfoAttribute(ParameterAccessor.Int); } int size; object ret; switch (item.Access) { case ParameterAccessor.Int: if (handle == IntPtr.Zero) { ret = VG.vgGeti(p); } else { ret = VG.vgGeti(handle, p); } break; case ParameterAccessor.Float: if (handle == IntPtr.Zero) { ret = VG.vgGetf(p); } else { ret = VG.vgGetf(handle, p); } break; case ParameterAccessor.IntArray: if (handle == IntPtr.Zero) { size = VG.vgGetArraySize(p); } else { size = VG.vgGetArraySize(handle, p); } if (VG.vgGetError() == ErrorCode.NoError) { ret = new int[size]; if (size > 0) { if (handle == IntPtr.Zero) { VG.vgGet(p, size, (int[])ret); } else { VG.vgGet(handle, p, size, (int[])ret); } } } else { ret = null; } break; case ParameterAccessor.FloatArray: if (handle == IntPtr.Zero) { size = VG.vgGetArraySize(p); } else { size = VG.vgGetArraySize(handle, p); } if (VG.vgGetError() == ErrorCode.NoError) { ret = new float[size]; if (size > 0) { if (handle == IntPtr.Zero) { VG.vgGet(p, size, (float[])ret); } else { VG.vgGet(handle, p, size, (float[])ret); } } } else { ret = null; } break; default: return(null); } if (VG.vgGetError() != ErrorCode.NoError) { ret = null; } if (ret != null && ret.GetType() != item.Type) { if (item.Type.IsEnum) { ret = Enum.ToObject(item.Type, ret); } else { ret = Convert.ChangeType(ret, item.Type); } } return(ret); }