I'm trying to simply read an image from file into a byte array. The problem is that I am using Xamarin and I want to decouple my Data Access code completely from Xamarin Forms. The problem is that my version of .Net (.NetPortable 4.5) does not contain System.IO.File so I don't know what to do now.
Can somebody point me in the right direction or recommend a lightweight package from Nuget? I want to achieve the follow without the use of Xamarin Forms and ideally load an image into a byte array with .NetPortable 4.5 or another light-weight mobile framework
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing; //Doesn't Exist in this .Net Framework!
using System.IO.File; //Doesn't Exist in this .Net Framework!
//using Xamarin.Forms; //I don't want to use Xamarin in this class
namespace EmployeeApp.DAT
{
public class EmployeeImageDAT
{
private ImageSource _employeeImageSource = ImageSource.FromFile("placeholder_image.png");
public EmployeeImageDAT() {
}
public ImageSource EmployeeImageSource
{
get
{
return _employeeImageSource;
}
set
{
_employeeImageSource = (value == null ? ImageSource.FromFile("placeholder_image.png") : value);
}
}
}
}
Related
I am currently working on a small program, that loads an image file into the Console and print it out as an asci image. I am using the ".Net Console application framework 4". My Problem is, that I do not know how to create a Bitmap. After browsing for a while, I found many answers to my question, that suggested the "System.Drawing.Bitmap" class. When I try to refer to this class, visual studio does not even know System.Drawing.Bitmap. I have a class "AsciArt" which should convert the picture in the method ConvertToAsci. Does anybody know what my mistake is?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Bitmap;
namespace consoleGrafix
{
class AsciArt
{
private string ImgLink;
public AsciArt(string imageLocation)
{
this.ImgLink = imageLocation;
}
public void ConvertToAsci(string saveLocation)
{
var bm = Bitmap(saveLocation);
}
}
}
The solution was to set up my class by inheriting from image class. Also, in the ConvertTo Asci method, there was a "new". https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bitmap?view=netframework-4.0 . This really helped. Thank you!
I have been trying to create a custom control on Xamarin.Forms.
My solution builds just fine on UWP but with android I always get the same error :
Impossible to evaluate the expression "[System.Version]::Parse('')". String is either too long or too short.
How Can I solve this ???
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using App2;
using App2.UWP;
using Xamarin.Forms.Platform.UWP;
using Windows.UI.Xaml.Controls;
[assembly: ExportRenderer(typeof(NavigationPannel), typeof(NavigationPannelRenderer))]
namespace App2.UWP
{
class NavigationPannelRenderer : ViewRenderer<NavigationPannel, NavigationView>
{
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPannel> args)
{
base.OnElementChanged(args);
if (Control == null)
{
NavigationView nav_view = new NavigationView();
nav_view.MenuItems.Add(new NavigationViewItem
{
Content = "My content",
Icon = new SymbolIcon(Symbol.Folder),
Tag = "content"
});
SetNativeControl(nav_view);
}
}
}
}
EDIT :
I made another solution and tried to redo everything step by step, my android project compiled just fine at first, but when I Added my UWP custom renderer, and after compiling it on Windows, it started showing the same error
Okay so I made it step by step again copy/pasting line by line for a third time and this time no error occurs.
I really don't know what happened here so if anyone has any idea i would still gladly accept it.
I have created a class library to be used in a other project (which is not a .Net project), i have built the solution the dll file was generated, but when i try to explor my dll using dllexp i foud that it's empty.
My class is declared public as you can see bellow:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PCLImportCLin.ServiceReference1;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
namespace PCLImportCLin
{
public class ImportCL
{
public int geTroupeau()
{
// Rest of the code
}
}
}
What you are looking for, I guess, is this:
(Assuming you are using Visual Studio) In your project, right-click 'References', go to 'Browse' and then click the 'Browse...' button. Go to your dll path, select it. There you go. Now you can use it like this using Your.Dll.Namespace;
To avoid requiring a Dll be registered for all users of a spreadsheet, I'm trying to use late binding so that users do not need to add a reference to the Dll.
I've created the Dll in C# with Visual Studio, and even though I've included "using RGiesecke.DllExport;" and used DllExport on a function to return an object containing the functions I need to access in VBA, I still get the error "Run-time error '453': Can't Find DLL entry point CreateDotNetObject in C:\temp\MyFunctions.dll."
The DLL code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System.Data;
using System.Text.RegularExpressions;
using Microsoft.TeamFoundation.Client;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Collections;
using System.Collections.ObjectModel;
using System.Threading;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework;
using Microsoft.TeamFoundation.Common;
using Microsoft.VisualBasic;
using System.Diagnostics;
using RGiesecke.DllExport;
namespace MyFunctions
{
public interface IMyFunctions
{
string GetWorkItemLinkList(string WIIDs);
}
[CLSCompliant(true), ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual)]
public class MyFunctions : IMyFunctions
{
TfsConfigurationServer server;
WorkItemStore store;
private void TFSconnect()
{
//Code to connect
}
[CLSCompliant(true), ComVisible(true), Description("GetWorkItemLink func")]
public string GetWorkItemLink(int WIID)
{
TFSconnect();
//Code to build return string "message"
return message;
}
[CLSCompliant(true), ComVisible(true), Description("GetWorkItemLinkList func")]
public string GetWorkItemLinkList(string WIIDs)
{
TFSconnect();
//Code to build return string "returnStr"
return returnStr;
}
}
static class UnmanagedExports
{
[DllExport]
[return: MarshalAs(UnmanagedType.IDispatch)]
static Object CreateDotNetObject()
{
return new MyFunctions();
}
}
}
and the declaration in VBA is as follows:
Private Declare Function CreateDotNetObject Lib "c:\temp\MyFunctions.dll" () As Object
But when I try to instantiate an object, I get the error I mentioned above.
Sub test()
Dim o As Object
Set o = CreateDotNetObject()
End Sub
This is my first time attempting to use custom dll functions in Excel without adding a reference in the VBA. The functions do work if I add a reference (early binding), but the DLL is not going to be propogated to everyone who uses the spreadsheet, and I need it to not crash when they run normal functions.
EDIT: Additional info. I just noticed that in addition to the DLL, when I build the solution in Visual Studio I also get an " Object FileLibrary" and an "Exports Library File". When I register the DLL is there anything I should be doing with either the .exp or .lib?
Thanks,
Mike
I was building the solution with the Platform Target in the class library properties set to "Any PC", which apparently does not allow exports. When I switch it to "x86" it totally works.
I'm making a new Project which is a class library.
my problem is I always got this error:
The type or namespace name 'Drawing'
does not exist in the namespace 'System' (are you missing an assembly reference?)
this is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace ClassLibrary1
{
public class Class1
{
public void ReturnImage(object imageStream)
{
try
{
byte[] data = (byte[])imageStream;
MemoryStream ms = new MemoryStream(data);
return Image.FromStream(ms);
}
catch
{
}
}
}
}
I'm planning to use this class to serve as a repository of common methods that I will be reusing in my program. In the above code, I have a public method ReturnImage which supposedly will accept an object and returns an Image.
But why I get that error? Please help...
Add reference to System.Drawing
From VS menu: Project > Add Reference
And to save you from incessant typing of: using namespacehere;
Press Ctrl+. (Control and .), it will automatically insert using namespacehere; on top of your code based on the classes you use. Example, place the cursor on any character inside Image of Image.FromStream, then press Ctrl+., it will automatically insert using System.Drawing; on top of your code. Likewise, do the same(pressing Ctrl+.) on FromStream of Image.FromStream, it will automatically insert using System.IO; on top of your code