how do you create a bitmap from a gradient stop collection c# - c#

I am trying to get a bitmap from a GradientStopCollection, so far I have been able to create a the GradientStopCollection with the following code.
public GradientStopCollection GradientColor(Color SelectedColor)
{
GradientStopCollection CGbrush = new GradientStopCollection(2);
CGbrush.Add(new GradientStop(SelectedColor, 0));
CGbrush.Add(new GradientStop(Colors.Black, 1));
return CGbrush;
}
I have tried to create a bit a copple time but so far none are successful.
If anyone has any ideas I would be happy to hear them,
Thanks :)

Related

Draw text on a 3D plane sharpDX

I searched and didn't find a way to do that.
I want to attach labels to 3D objects using sharpDX in HoloLens app.
anyone knows how?
thanks
edit:
so I decided to convert the text to image and then put it as texture on a plane made of 2 triangles mesh.
so now I tried this code:
https://gist.github.com/naveedmurtuza/6600103
but can't include the references, how do I fix that?
thanks
I wrote a game using SharpDx a few years ago, here's a video of it:
https://www.youtube.com/watch?v=tDRmIY6-8Z4
If I understand you correctly, you want 3D-texts just as the ones I'm using to explain the game elements? If so, you might get some ideas from this source code:
protected override bool draw(Camera camera, DrawingReason drawingReason, ShadowMap shadowMap)
{
if (drawingReason != DrawingReason.Normal)
return true;
camera.UpdateEffect(Effect);
foreach (var item in Items)
{
Effect.World = Matrix.BillboardRH(item.Target.Position + item.GetOffset(item), camera.Position, -camera.Up, camera.Front);
Effect.DiffuseColor = item.GetColor(item);
SpriteBatch.Begin(SpriteSortMode.Deferred, Effect.GraphicsDevice.BlendStates.NonPremultiplied, null, Effect.GraphicsDevice.DepthStencilStates.DepthRead, null, Effect.Effect);
SpriteBatch.DrawString(Font, item.Text, Vector2.Zero, Color.Black, 0, Font.MeasureString(item.Text) / 2, item.GetSize(item), 0, 0);
SpriteBatch.End();
}
Effect.GraphicsDevice.SetDepthStencilState(Effect.GraphicsDevice.DepthStencilStates.Default);
Effect.GraphicsDevice.SetBlendState(Effect.GraphicsDevice.BlendStates.Opaque);
return true;
}
Full game code is open source and available here:
https://github.com/danbystrom/Larv/blob/master/src/factor10.VisionThing/FloatingText/FloatingTexts.cs#L32

Directx.Capture How to set resolution

So, I was redding a article(this one : https://dashingquill.wordpress.com/2012/06/27/capturing-webcam-using-directshow-net-library/ ) and i download it to study the code.
Im trying to implemente this changes(to make video in 1920x1080) :
capture.FrameRate = 29.997;
capture.FrameSize = new Size(1920, 1080);
capture.AudioSamplingRate = 44100;
capture.AudioSampleSize = 16;
But my ask to you is where in code do i apply this codes?
I try to apply here :
void preview()
{
try
{
capture = new Capture(filters.VideoInputDevices[0], filters.AudioInputDevices[0]);
capture.FrameRate = 29.997;
capture.FrameSize = new Size(1920, 1080);
capture.AudioSamplingRate = 44100;
capture.AudioSampleSize = 16;
capture.PreviewWindow = panel1;
but when i do that something funny happens, my video is in (1920x1080) only when i click on "stop" anything different make the preview video "weird"(not in 192x1080).
Can you help me on that?
Aa, another question. If i want to capture a sigle frame,like a picture,how can i do that with that code?
Thank you and osrry for my bad english . Its not my natural language.
I found by myself the solution.
Well, apparently what i was doing is correct, but i was running on debug mode. When a change to realese thats works fine and the framesize was set correct.

Google Map Marker wrongly change position while drag drop

I know we have some similar questions already but all of them can not help me solve my issue (because of the difference platform). So I put my question here with a hope that someone can help me.
I am working on a xamarin project and using Google Map API ver 2 to make a map.
When I touch on the map, I will add a new marker by using this code.
public void AddPoint(LatLng pointPossition)
{
MarkerOptions markerPoint = new MarkerOptions();
markerPoint.Anchor (0.5f, 1.0f);//The same issue occur when I remove this line
markerPoint.InvokeIcon(m_PointMoveableIcon);
markerPoint.SetPosition (pointPossition);
markerPoint.Draggable (true);
Marker marker = m_Map.AddMarker(markerPoint);//m_Map is the Google Map
m_Markers.Add(marker);//m_Markers is a list to store all created markers
}
By that way, I can create some makers on the map
All markers are draggable, so I can long click on any marker and drag it to another position, but unfortunately, the dragged marker change position suddenly, and this behavior is really bad.
I tried many solutions but not work. So, I hope someone can help me.
Thank in advance.
I had this quest now. And it's my solution is code below.
Why first number is it, i don't know, but it's works for my debugger. And 0.5 probably is half marker position.
private void Map_PinDragging(object sender, PinDragEventArgs e)
{
int m = map.Pins.IndexOf(e.Pin);
map.Pins.ElementAt(m).Position = new Xamarin.Forms.GoogleMaps.Position(e.Pin.Position.Latitude - (0.001347153801 * 0.5), e.Pin.Position.Longitude);
}
private void Map_PinDragStart(object sender, PinDragEventArgs e)
{
int m = map.Pins.IndexOf(e.Pin);
map.Pins.ElementAt(m).Position = new Xamarin.Forms.GoogleMaps.Position(e.Pin.Position.Latitude - (0.001347153801 * 0.5), e.Pin.Position.Longitude);
}
Pin DragPin;
private void Map_PinDragEnd(object sender, PinDragEventArgs e)
{
int m = map.Pins.IndexOf(e.Pin);
map.Pins.ElementAt(m).Position = new Xamarin.Forms.GoogleMaps.Position(e.Pin.Position.Latitude - (0.001347153801*0.5), e.Pin.Position.Longitude);
}
And...
This value change with my map Zoom. Needs some math there.

XNA weird terrain tearing

Let me post the images first...
Solid shot where tearing occurs
And wireframe shot of that place
I am mostly using mostly using Riemers tutorial while the render code is..
Main render
public void Render()
{
device.Clear(Color.CornflowerBlue);
RasterizerState rs = new RasterizerState();
rs.CullMode = cullmode;
rs.FillMode = fillmode;
device.RasterizerState = rs;
effect.Parameters["xView"].SetValue(camera.ViewMatrix);
effect.Parameters["xProjection"].SetValue(camera.ProjectionMatrix);
effect.Parameters["xWorld"].SetValue(Matrix.Identity);
effect.Parameters["xEnableLighting"].SetValue(true);
effect.Parameters["xLightDirection"].SetValue(lightDirection);
effect.Parameters["xAmbient"].SetValue(0.5f);
globals.game.terrain.Render();
globals.game.spriteBatch.Begin();
globals.console.Render();
globals.game.spriteBatch.End();
}
Terrain.Render()
public void Render()
{
globals.game.graphics.effect.CurrentTechnique = globals.game.graphics.effect.Techniques["Colored"];
globals.game.graphics.effect.Parameters["xWorld"].SetValue(worldMatrix);
foreach (EffectPass pass in globals.game.graphics.effect.CurrentTechnique.Passes)
{
pass.Apply();
globals.game.graphics.device.Indices = indexBuffer;
globals.game.graphics.device.SetVertexBuffer(vertexBuffer);
globals.game.graphics.device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
}
}
I was stuck with this problem for pretty long now (not knowing if it is caused by my coding skills, xna or some g-card configuration...) so i wonder if someone have some ideas what might cause it?
Temporarily comment out the spritebatch begin, draw, & end code and see if that makes a difference. It may or may not depending on the vertex order in the buffer.
If it does help, your solution can be found here: http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx

Weird shape resizing behavior in WPF

I am making a WPF application that will let the user draw and resize shapes.
The resizing part is done using adorners, and the shapes are my own classes derived from Shape.
For example I have a Polyline, and for each of it's points I am adorning a Thumb with a handler on it's DragDelta event:
void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
{
PolylineEx polyline = this.AdornedElement as PolylineEx;
ResizingThumb thumb = sender as ResizingThumb;
int index = (int)thumb.Tag;
Point newPoint = new Point(
polyline.Points[index].X + e.HorizontalChange,
polyline.Points[index].Y + e.VerticalChange);
Trace.WriteLine(String.Format("Arranging point {0}:{1},{2}", index, newPoint.X, newPoint.Y));
polyline.Points[index] = newPoint;
}
Well, the problem is that sometimes (often), dragging a thumb is not smooth at all. First I thought it was a performance issue, because of a new Point being created every time (and other things), but then I noticed that sometimes the point is set up at weird coordinates that have nothing to do with the position of the mouse.
I've also uploaded a sample project HERE, could someone who knows his way around wpf take a look and enlighten me of what is happening?
Also, if anyone thinks of a better way for doing this, any feedback would be highly appreciated.
Thank you.
Edit: HERE is a new link to the project files.
I'm ending up answering my own question :)
I think the problem was here:
protected override System.Windows.Media.Geometry DefiningGeometry
{
get
{
StreamGeometry geometry = new StreamGeometry();
using (StreamGeometryContext context = geometry.Open())
{
context.BeginFigure(Points[0], false, true);
foreach (Point pt in Points)
{
context.LineTo(pt, true, true);
}
geometry.Freeze();
return geometry;
}
}
}
I switched to using PathGeometry & LineSegments and it works fine now.

Categories