I am creating a mobile app using Unity. I would like to place a photo which fills the screen and then place some 3D objects on top of this photo. The photo is created during runtime and is saved to the persistance data folder.
What is the best method to achieve this? The options I see are Raw Image/Image/Sprite. However, I have been unable to achieve the above mentioned goal using either of these component types.
What about making a panel on a canvas, setting the image as background and the canvas to fit screen size?
Then place the objects on front of it, manually or as children of said canvas but higher in the hierarchy.
I don't really understand what you intend to do, just trying to help.
editing my original answer: you need to use RawImage to be able to easily load images that are not marked as Sprite in the editor
You load images from file like this :
Texture2D texture = new Texture2D(1,1); // the following needs a non null starting poin
var path=System.IO.Path.Combine(Application.streamingAssetsPath,"your_file.jpg");
byte[] bytes=System.IO.File.ReadAllBytes(path);
texture.LoadImage(bytes);
rawImage.texture=texture;
As far as keeping it filling the screen the AspectRatioFiter component is likely to do the job
To get 3d objects rendering in front, set your canvas to 'Screen Space - Camera' and point it to your camera. This will behave similar to word space in regards to rendernig order (will get 3d sroted) but canvas size will match camera viewport, so AspectRatioFitter will be able to do its job
We're having a requirement to build an OS independent application where we need to draw Rectangles, Lines and Ellipse.
We are developing in a ASP.Net Core (MVC) application to realize the OS independence.
Our ideal situation is to prefix the drawing objects in a model class (height, width, color) and request the objects in the controller or razor view to show them on the web page.
We've searched on the internet and found several options with a BitMap of System.Drawing.Common.
The most common solution is a form application witch we want to avoid, because it isn't OS independent.
What is the best suggestion to realize our situation?
We are not afraid to try the combination of C#, JS HTML and so one, only requirement it needs to fit in the ASP.Net Core application.
Have a look at fabric.js for interacting with the html canvas.
You can develop directly with the canvas, but it will be much easier to use a library that already handles all the heavy lifting.
see: http://fabricjs.com
What about <canvas> ?
The HTML <canvas> element is used to draw graphics on a web page.
var c=document.getElementById("myCanvas");
var canvOK=1;
try {c.getContext("2d");}
catch (er) {canvOK=0;}
if (canvOK==1)
{
var ctx=c.getContext("2d");
ctx.fillStyle="#FF0000";
ctx.fillRect(20,20,100,50);
var grd=ctx.createLinearGradient(140,20,240,70);
grd.addColorStop(0,"black");
grd.addColorStop(1,"white");
ctx.fillStyle=grd;
ctx.fillRect(140,20,100,50);
var grd2=ctx.createLinearGradient(20,90,120,90);
grd2.addColorStop(0,"black");
grd2.addColorStop("0.3","magenta");
grd2.addColorStop("0.5","blue");
grd2.addColorStop("0.6","green");
grd2.addColorStop("0.8","yellow");
grd2.addColorStop(1,"red");
ctx.fillStyle=grd2;
ctx.fillRect(20,90,100,50);
ctx.font="30px Verdana";
var grd3=ctx.createLinearGradient(140,20,240,90);
grd3.addColorStop(0,"black");
grd3.addColorStop("0.3","magenta");
grd3.addColorStop("0.6","blue");
grd3.addColorStop("0.8","green");
grd3.addColorStop(1,"red");
ctx.strokeStyle=grd3;
ctx.strokeText("Smile!",140,120); }
<canvas id="myCanvas" width="270" height="160" style="border:1px solid #c3c3c3;float:left;margin-right:20px;margin-bottom:15px">
Your browser does not support the <canvas> element.
</canvas>
The graphic to the above is created with ''. It shows four elements: a red rectangle, a gradient rectangle, a multicolor rectangle, and a multicolor text.
What is HTML Canvas?
The HTML <canvas> element is used to draw graphics, on the fly, via JavaScript.
The <canvas> element is only a container for graphics. You must use JavaScript to actually draw the graphics.
Canvas has several methods for drawing paths, boxes, circles, text, and adding images.
for complete view
https://www.w3schools.com/html/html5_canvas.asp
https://stackoverflow.com/search?q=canvas
I am trying to achieve a similar objective in an asp.net core 2.0 project. From my ".cshtml" razor view, I am calling a Typescript routine to handle to GUI complexity. Within the view, I am using a HTML5 canvas on which I want to draw rectangles over a background image.
[jsFiddle][1] seems to be the best website to understanding the various interaction of these aspects (HTML, CSS, TypeScript), specifically these examples:
Creating circles with a mouse
Circle drawing in fabricjs
Currently, I not 100% sure how to include "Fabric.js" within the project "wwwroot" directory (or other locations within the project) and secondly how to maintain the background image throughout the drawing of circles, lines etc.
This seems to align with all the responses above. I do know that "System.Drawing" are not available within ".NET Core 2.0" (even via a NuGet package), so unfortunately other methods need to be pursued.
I have some x and y positions in a database table, that go to make up a design for a window.
What I would like to do is draw this onto a HTML5 canvas in my app, but I'm not sure what the best way is to pass data out of my database into the canvas object (I'm not really a JavaScript/web guy).
It will just be drawing lines, that i can do but I'm not sure the best way to get the data into the canvas so I can draw it.
A quick fiddle page for you, maybe this can get you started.
http://dotnetfiddle.net/D3OqTy
I recommend read some html5 canvas tutorial
http://www.html5canvastutorials.com/
(Sorry if this is in the wrong place. I have been bouncing around SO and Programmers SE Sites all day and I keep getting flagged. Some insight as to what I am doing wrong would be helpful). Now on to my question:
I have been following the 3D WPF C# tutorial here: http://kindohm.com/technical/WPF3DTutorial.htm all the way up to the cube demo. I am wondering if there is a way to place text on the cube either as part of the texture or as 3D text attached to the cube. If someone could point me towards a tutorial or a code snippet that would be helpful. Thanks!
Update: I forgot to mention that the one thing that I am doing differently from the tutorial is that I am embedding the WPF ViewPort control inside of a WPF UserControl inside of an ElementHost inside of a Windows Form.
The tutorial shows how to use Material, with a SolidColorBrush. Besides SolidColorBrush there are some more kinds of Brushes can be used with the Material. For example You can use VisualBrush, in which you can use any kind of Visual, including DrawingVisual and even UIElement.
Notice that if you're going to render heavy scene with a lot of texts you might encounter performance issues. UIElement performs very bad in 3D scene, so I would prefer using DrawingVisual instead. If that's still not good enough, you can rasterize your DrawingVisual using RenderTargetBitmap and then use ImageBrush instead of the VisualBrush (that's good only if the text is static - if you would like to use animations you must use the VisualBrush without rasterization).
I would like to rotate the content of a Form (WinForms). Is it possible to implement that behavior in some way?
I already known that with WPF would be easier but the form and the logic are already implemented and in addition I should work with Framework 2.0.
I also known that using video card features that would probably possible, but I need to rotate only one specific form, not all applications running on the target pc.
If you draw the content by yourself using OnPaint, you can use Graphics.Transform and feed it a rotation matrix or use Graphics.RotateTransform(float angle).
Be aware that this will not be perfect though. Some things might not rotate as expected such as text and images.
Basicly You cant do this. There are two possible way to solve the problem
Find third party controls, which can be rotated
Rewrite all controls. You should ovveride paint method of ALL controls you want to rotate, so they will owner drawed.
Can you create a wpf window with a WindowsFormHost holding your content and then apply a rotation transform to it?
At the end I solved this by cloning the form and all the controls that contains (if someone want to take a look the code just comment) and proceed to rotate them one by one.
Private Shared Sub RotateForm180(frm As Form)
For Each ctrl As Control In frm.Controls
RotateControl180(ctrl)
Next
End Sub
Private Shared Sub RotateControl180(ctrl As Control)
Dim oScreenRect As Rectangle = ctrl.Parent.RectangleToScreen(ctrl.Parent.ClientRectangle)
ctrl.Location = New Point(oScreenRect.Width - (ctrl.Location.X + ctrl.Width),
oScreenRect.Height - (ctrl.Location.Y + ctrl.Height))
For Each c As Control In ctrl.Controls
RotateControl180(c)
Next
End Sub
Form background can also by rotated.
_BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipNone)