trying to load a bitmap, but xna want´s a Texture2D - xna

I'm currently trying to load a simple bitmap using XNA but I get the following error:
Error loading "Maps\standard". File contains Microsoft.Xna.Framework.Graphics.Texture2D but trying to load as System.Drawing.Bitmap.
code:
public Bitmap map;
public void load(Game game, String image) {
path = image; //path to image
map = game.Content.Load<Bitmap>("Maps/"+path);
sizeX = map.Width;
sizeY = map.Height;
}

You want the below:
map = game.Content.Load<Texture2D>("Maps/"+path);
The way XNA works is that there is a content pipeline, which takes inputs (like your bitmap image) and produces outputs (the Texture2D), which is in a different format to the input.
XNA works with a Texture2D object when displaying images.

Now, I just use the C# standard
Bitmap bmp = (Bitmap)Bitmap.FromFile(path);

Related

Unity 3d 2017.2.1 camera feed looks zoomed in iPad

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFeed : MonoBehaviour {
// Use this for initialization
public Renderer rend;
void Start () {
WebCamDevice[] devices = WebCamTexture.devices;
// for debugging purposes, prints available devices to the console
for(int i = 0; i < devices.Length; i++)
{
print("Webcam available: " + devices[i].name);
}
Renderer rend = this.GetComponentInChildren<Renderer>();
// assuming the first available WebCam is desired
WebCamTexture tex = new WebCamTexture(devices[0].name);
rend.material.mainTexture = tex;
//rend.material.SetTextureScale("tex", new Vector2(1.2f, 1.2f));
tex.Play();
}
// Update is called once per frame
void Update () {
}
}
I use the above code to render camera feed on a plane. The code works fine but I see zoomed feed(around 1.2x) when deployed to iPad. How can I get the normal feed. Or How do I zoom out the camera feed
According to https://answers.unity.com/questions/1421387/webcamtexture-zoomed-in-on-ipad-pro.html if you insert this code it should scale properly:
rend.material.SetTextureScale("_Texture", new Vector2(1f, 1f))
Furthermore, it seems that you were trying something like this but your vector was off (by 0.2f) though you have commented out that line as well. You could reduce the scale even more though that could make the image just smaller if the camera couldn't support that zoomout :).

Staling for mobile - Graphic is cut off

Using Flashdevelop, I managed to add a a jpg in my starling project:
[Embed(source = "../../../../lib/table_org_img_retouched_900.png")]
private static const Graphic:Class;
...
// create a Bitmap object out of the embedded image
var sausageBitmap:Bitmap = new Sausage();
// create a Texture object to feed the Image object
var texture:Texture = Texture.fromBitmap(sausageBitmap);
// create a Image object with our one texture
var image:Image = new Image(texture);
//image.width = 1000;
// show it
addChild(image);
what I get at the end is this:
https://www.dropbox.com/s/wvqws29tg3sxwzv/starling.png
Why is my png cut off?
It is possible that when you started starling your stage size was not accurate ,
_starling = new Starling(Game, stage);
_starling.start();
I suggest you trace the size of the stage you pass to Starling in the creation, if it is not aligned with your device size then you should delay a bit the creation of Starling.

How do I let the user draw (like MS Paint) a picture in the given space (50x50) and saving that picture as a texture2D? XNA

I was thinking of making a windows form with a 50x50 space somewhere on it (bitmap?) and having the user draw (like MS Paint) inside the square. When the user is done, the picture can be saved by clicking on the "save" button and it will be updated in Game1 (for collision purposes of my game). I've seen some tutorials on here on how to draw on screen like MS Paint, but I can't seem to figure out how to SAVE that picture as a Texture2D/Rectangle. And how do I get a bitmap onto a windows form?
To save a bitmap as a png:
private void SaveBmpAsPNG(Bitmap bm)
{
bm.Save(#"c:\button.png", ImageFormat.Png);
}
To write a texture2d to a file:
using (Stream stream = File.OpenWrite("picture.png"))
{
texture.SaveAsPng(stream, texture.Width, texture.Height);
}
To read a .png into a texture2d:
using(Stream stream = File.OpenRead("picture.png"))
{
texture = Texture2D.FromStream(GraphicsDevice, stream);
}

MonoTouch Mapkit image overlay

I have been looking for a good tutorial on adding an image overlay for Mapkit in C# Monotouch.
I have found many overlay examples for coloured circles or polygons. But I want to load a PNG over the top of my maps. I am coming from MonoAndroid and have done it there, but need to transfer my program across to iOS.
Even a objective C example would help, but Mono would be better.
I ended up downloading some native objective C code and pretty much just converting it into C#. The function names are very similar, the Xamarin API references Documentation is very helpful.
There where some tricky bumps I ran into around the app delegate, and how it is handled differently in C# to Objective C.
Here are the two hardest functions to convert and my solution:
1) The Draw functions in the map overlay class
public override void DrawMapRect (MKMapRect mapRect, float zoomScale, CGContext ctx)
{
InvokeOnMainThread(
() =>
{
UIImage image = UIImage.FromFile(#"indigo_eiffel_blog.png");
DrawImgRotated(image, 0, ctx);
}
);
}
public void DrawImgRotated(UIImage image, float rotDegree, CGContext c)
{
c.SaveState();
CGImage imageRef = image.CGImage;
//loading and setting the image
MKMapRect theMapRect = ((MapOverlay)this.Overlay).BoundingMapRect;//MKMapRect theMapRect = [self.overlay boundingMapRect];
RectangleF theRect = RectForMapRect(theMapRect);
//we need to flip and reposition the image
c.ScaleCTM( 1.0f, -1.0f);
c.TranslateCTM(-theRect.Width/8,-theRect.Height);
// Proper rotation about a point
var m = CGAffineTransform.MakeTranslation(-theRect.Width/2,-theRect.Height/2);
m.Multiply( CGAffineTransform.MakeRotation(DegreesToRadians(rotDegree)));
m.Multiply( CGAffineTransform.MakeTranslation(theRect.Width/2,theRect.Height/2));
c.ConcatCTM( m );
c.DrawImage(theRect, imageRef);
c.RestoreState();
}
and 2) the bounding mapRect function in my mapOverlay class overriding MKOverlay.
Yes the position is hardcoded, I am working on unit conversion atm but those are the correct coordinates to draw the image same as in the sample obejctive c code I used.
public MKMapRect BoundingMapRect
{
[Export("boundingMapRect")]
get
{
var bounds = new MKMapRect(1.35928e+08, 9.23456e+07,17890.57, 26860.05);
return bounds;
}
}
The source code for the Objective C project I converted is here: https://github.com/indigotech/Blog-MKMapOverlayView
Xamarin API reference documentation: http://iosapi.xamarin.com/
The way you want to go about this will depend on the kind of image you want to overlay. If it’s just pretty small, you should be able to get away with just using a single image. However, if it covers a larger area that uses expect to be able to zoom in on, you may have to split it up into separate tiles for better performance.
Here’s some other questions on Stack Overflow that might answer it for you:
How do I create an image overlay and add to MKMapView?
iPhone - Image overlay MapKit framework?
See Apple’s WWDC2010 sample code TileMap
https://github.com/klokantech/Apple-WWDC10-TileMap (posted to GitHub by someone)
None of this has anything to do with Mono, but you should be able to convert it…

How to apply Smooth Shading to dae models rendered with Three.js ColladaLoader

Here is a model which is rendered using the collada loader example in threejs. I believe it is using a Flat Shading. (Thus the blocky nose)
Now here is the model using a Smooth Shader in meshlab
I already know how to apply smooth-shading on an obj/js file using MeshFaceMaterial. My question is how can I apply smooth-shading on a dae file which has been rendered using the collada loader? Is this supported in threejs?
Thanks
Have you tried:
var loader = new THREE.ColladaLoader();
callBack = function colladaReady( collada ) {
var dae = collada.scene;
var skin = collada.skins[ 0 ];
dae.scale.x = dae.scale.y = dae.scale.z = 0.002;
dae.updateMatrix();
dae.material = new THREE.MeshLambertMaterial({ shading: THREE.SmoothShading});
// or something of this sort....
scene.add(dae);
};
loader.load(modelPath, callBack);
I don't know if it would help, but here is another example from the source: http://mrdoob.github.com/three.js/examples/webgl_loader_collada.html

Resources