I'm trying to add images from a folder and their names below each image. In master slide[0] there should be Title. My problem is that my code is generating single PowerPoint file for each image instead of adding all images to one PowerPoint file. Can someone help me with my come or simar code that can work out
I've attached an image of what I'm trying to achieve.
Here's the code I'm working with using C# and GemBoxPresentation API:
//Create new powerpoint presentation
var presentation = new PresentationDocument();
//change the path format
string dir = txtPath.Text.Replace("/", "\\");
fontRootFolder = dir.Replace(Path.GetDirectoryName(dir) + Path.DirectorySeparatorChar, "");
string workingPath = Application.StartupPath + #"\Zip Extracts\" + fontRootFolder + "\\png";
if (Directory.Exists(workingPath))
{
// Get the directory
DirectoryInfo ImagePath = new DirectoryInfo(workingPath);
// Using GetFiles() method to get list of all png files present in the png folder
FileInfo[] Files = ImagePath.GetFiles();
foreach (FileInfo fi in Files)
{
for (int i = 0; i < fi.Length; i++)
{
Cursor = Cursors.WaitCursor;
// Get slide size.
var size = presentation.SlideSize;
// Set slide size.
size.SizedFor = SlideSizeType.OnscreenShow16X10;
size.Orientation = GemBox.Presentation.Orientation.Landscape;
size.NumberSlidesFrom = 1;
// Create new presentation slide.
var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);
// Create first picture from path.
Picture picture = null;
using (var stream = File.OpenRead(fi.FullName))
picture = slide.Content.AddPicture(PictureContentType.Png, stream, 1.45, 1.35, 1.45, 1.35, LengthUnit.Centimeter);
var textBox = slide.Content.AddTextBox(ShapeGeometryType.Rectangle, 1.03, 1.03, 6, 6, LengthUnit.Centimeter);
var paragraph = textBox.AddParagraph();
paragraph.Format.Alignment = GemBox.Presentation.HorizontalAlignment.Center;
paragraph.AddRun(fi.Name);
SaveFileDialog sfd = new SaveFileDialog();
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
sfd.Title = "Save PowerPoint Icons";
sfd.CheckFileExists = false;
sfd.CheckPathExists = true;
sfd.DefaultExt = "pptx";
sfd.Filter = "Powerpoint Files (*.pptx) | *.pptx";
sfd.FilterIndex = 1;
sfd.RestoreDirectory = true;
if (sfd.ShowDialog() == DialogResult.OK)
{
//string file = sfd.FileName;
presentation.Save(sfd.FileName);
Cursor = Cursors.Default;
}
Cursor = Cursors.Default;
}
}
}
Expected PowerPoint output
I developed a similar tool.
The base class:
using System;
using System.Collections.Generic;
namespace akGraphics2Pptx
{
class GraphicsConverter
{
static string[] usageText =
{
"akGraphics2Pptx - Graphics to Powerpoint/PDF Converter",
"------------------------------------------------------",
"",
"Usage:",
"",
"akGraphics2Pptx graphics_file [graphics_file ...] output_file",
"",
"Enter more than one graphics file name to get more than one slide.",
"Type of output file can be .pptx or .pdf",
""
};
protected IEnumerable<string> getFileNames(string[] args, string[] extensions)
{
List<string> names = new List<string>();
foreach (string arg in args)
{
foreach (string ext in extensions)
{
if (arg.ToLower().EndsWith("." + ext))
{
names.Add(arg);
break;
}
}
}
return names;
}
/// <summary>
/// Create a Powerpoint file with one slide per graphics file argument.
/// The arguments can have any order. The files are distinguished by their extensions.
/// </summary>
/// <param name="args">The arguments</param>
public virtual void convert(string[] args)
{
}
protected void usage()
{
foreach (string s in usageText)
{
Console.WriteLine(s);
}
}
}
}
The specific converter for PowerPoint output (I also have a PDF output):
using System;
using System.Collections.Generic;
using System.Linq;
using Ppt = Microsoft.Office.Interop.PowerPoint;
using static Microsoft.Office.Core.MsoTriState;
using System.IO;
namespace akGraphics2Pptx
{
class Graphics2PptxConverter : GraphicsConverter
{
private static string[] knownGraphicsFileExtensions = { "gif", "jpg", "png", "tif", "bmp", "wmf", "emf" };
private static string[] powerpointFileExtensions = { "ppt", "pptx" };
private IEnumerable<string> getGraphicsFileNames(string[] args)
{
return getFileNames(args, knownGraphicsFileExtensions);
}
private IEnumerable<string> getPowerpointFileNames(string[] args)
{
return getFileNames(args, powerpointFileExtensions);
}
/// <summary>
/// Create a Powerpoint file with one slide per graphics file argument.
/// The arguments can have any order. The files are distinguished by their extensions.
/// </summary>
/// <param name="args">The arguments</param>
public void convert(string[] args)
{
var graphicsFileNames = getGraphicsFileNames(args);
var powerpointFileNames = getPowerpointFileNames(args);
if (!graphicsFileNames.Any() || (powerpointFileNames.Count() != 1))
{
usage();
}
else
{
// inspired by http://stackoverflow.com/a/26372266/1911064
Ppt.Application pptApplication = new Ppt.Application();
// Create the Presentation File
Ppt.Presentation pptPresentation =
pptApplication.Presentations.Add(WithWindow: msoFalse);
Ppt.CustomLayout customLayout =
pptPresentation.SlideMaster.CustomLayouts[Ppt.PpSlideLayout.ppLayoutText];
foreach (string graphicsFileName in graphicsFileNames)
{
if (!File.Exists(graphicsFileName))
{
Console.WriteLine($"Graphics file {graphicsFileName} not found!");
}
else
{
// Create new Slide
Ppt.Slides slides = pptPresentation.Slides;
Ppt._Slide slide =
slides.AddSlide(Index: slides.Count + 1, pCustomLayout: customLayout);
// Add title
Ppt.TextRange objText = slide.Shapes[1].TextFrame.TextRange;
objText.Text = Path.GetFileName(graphicsFileName);
objText.Font.Name = "Arial";
objText.Font.Size = 32;
Ppt.Shape shape = slide.Shapes[2];
objText = shape.TextFrame.TextRange;
objText.Text = "Content goes here\nYou can add text";
string fullName = Path.GetFullPath(graphicsFileName);
slide.Shapes.AddPicture(fullName, msoFalse, msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = graphicsFileName;
}
}
string pptFullName = Path.GetFullPath(powerpointFileNames.First());
Console.WriteLine("Powerpoint file created: " + pptFullName);
Console.WriteLine("Graphics slides: " + pptPresentation.Slides.Count);
Console.WriteLine("");
pptPresentation.SaveAs(pptFullName, Ppt.PpSaveAsFileType.ppSaveAsDefault, msoTrue);
pptPresentation.Close();
pptApplication.Quit();
}
}
}
}
Aspose.Slides for .NET is a Presentation Processing API for PowerPoint and OpenOffice formats. Aspose.Slides enable applications to read, write, protect, modify and convert presentations in .NET C#. Manage presentation text, shapes, charts, tables & animations, add audio & video to slides and preview slides.
More Link: https://products.aspose.com/slides/net/
internal class Program
{
static void Main(string[] args)
{
string[] filesindirectory = Directory.GetFiles(#"C:\\IMG");// file folder
string NameOfPPT = "_PPT_" + DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss");
//////////// var workbook = new Workbook(img);
//////////// workbook.Save(img);
using (Presentation pres = new Presentation())
{
int SlideIndex = 0;
foreach (string img in filesindirectory)
{
int alpha = 200, red = 200, green = 200, blue = 200;
pres.Slides.AddEmptySlide(pres.LayoutSlides[SlideIndex]);
// Get the first slide
ISlide slide = pres.Slides[SlideIndex];
//Add an AutoShape of Rectangle type
IAutoShape ashp = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 5, 5, 700, 30);
//Add ITextFrame to the Rectangle
string Header = "Store: Name of Store |"+ SlideIndex.ToString() + " Visite Date: 2022-Sep-20 |" + "Category: ABC" + SlideIndex.ToString();
ashp.AddTextFrame(Header);
//Change the text color to Black (which is White by default)
ashp.TextFrame.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillType.Solid;
ashp.TextFrame.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
//Change the line color of the rectangle to White
ashp.ShapeStyle.LineColor.Color = System.Drawing.Color.DarkGoldenrod;
pres.HeaderFooterManager.SetAllHeadersText("Adding Header");
pres.HeaderFooterManager.SetAllHeadersVisibility(true);
pres.HeaderFooterManager.SetAllFootersText("System Auto generated");
pres.HeaderFooterManager.SetAllFootersVisibility(true);
// pres.HeaderFooterManager.SetAllDateTimesText(DateTime.Now.ToString("dd/MM/yyyy"));
// pres.HeaderFooterManager.SetAllDateTimesVisibility(true);
SlideIndex++;
// Instantiate the ImageEx class
System.Drawing.Image imgs = (System.Drawing.Image)new Bitmap(img);
IPPImage imgx = pres.Images.AddImage(imgs);
// Add Picture Frame with height and width equivalent of Picture
//IPictureFrame pf = slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 5, 5, 707, 525, imgx);// full placed image
IPictureFrame pf = slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 60,100, 600, 400, imgx);
// Apply some formatting to PictureFrameEx
pf.LineFormat.FillFormat.FillType = FillType.Gradient;
pf.LineFormat.FillFormat.SolidFillColor.Color = Color.Black;
pf.LineFormat.Width = 5;
pf.Rotation = 0;
// Get the center of the slide and calculate watermark's position
PointF center = new PointF(pres.SlideSize.Size.Width / 2, pres.SlideSize.Size.Height / 2);
float width = 100;
float height = 50;
float x = center.X - width / 2;
float y = center.Y - height / 2;
// Add watermark shape
IAutoShape watermarkShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, x, y, width, height);
// Set fill type
watermarkShape.FillFormat.FillType = FillType.NoFill;
watermarkShape.LineFormat.FillFormat.FillType = FillType.NoFill;
// Set rotation angle
watermarkShape.Rotation = -45;
// Set text
ITextFrame watermarkTextFrame = watermarkShape.AddTextFrame("OOOOOOPPPPP");
IPortion watermarkPortion = watermarkTextFrame.Paragraphs[0].Portions[0];
// Set font size and fill type of the watermark
watermarkPortion.PortionFormat.FontHeight = 20;
watermarkPortion.PortionFormat.FillFormat.FillType = FillType.Solid;
watermarkPortion.PortionFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.FromArgb(alpha, red, green, blue);
// Lock Shapes from modifying
watermarkShape.ShapeLock.SelectLocked = false;
watermarkShape.ShapeLock.SizeLocked = false;
watermarkShape.ShapeLock.TextLocked = false;
watermarkShape.ShapeLock.PositionLocked = false;
watermarkShape.ShapeLock.GroupingLocked = false;
}
pres.Save(#"C:\\IMG\\PPT\\" + NameOfPPT + ".pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
}
}
Using free plugin
public bool createPPT()
{
var data = DbWORKINGDbContext.AMR_IMG_TO_PPT_POC.Where(c => c.PPTSlideInserted == false && c.Downloaded == true).ToList();
// var data = DbWORKINGDbContext.AMR_IMG_TO_PPT_POC.Take(10).ToList();
if (data.Count > 0)
{
Application pptApplication = new Application();
Microsoft.Office.Interop.PowerPoint.Slides slides;
Microsoft.Office.Interop.PowerPoint._Slide slide;
Microsoft.Office.Interop.PowerPoint.TextRange objText;
// Microsoft.Office.Interop.PowerPoint.TextRange objText2;
// Create the Presentation File
Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);
Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
int SlideIndex = 1;
foreach (AMR_IMG_TO_PPT_POC POCdata in data)
{
var pictureFileName = ImageToPptApp.Util.Constant.ImageStorePath + POCdata.Id + ".jpg";
var StoreName = POCdata.StoreName;
var Url = POCdata.FileCloudUrl;
var Filename = POCdata.Id;
var Titile = POCdata.Title;
var PictureTime = POCdata.PictureTimeStamp;
string Header = "Store: " + StoreName.ToString() + " | Date Time:" + PictureTime.ToString() + " | Titile: " + Titile.ToString();
// Create new Slide
slides = pptPresentation.Slides;
slide = slides.AddSlide(SlideIndex, customLayout);
// Add title
objText = slide.Shapes[1].TextFrame.TextRange;
objText.Text = Header;
objText.Font.Name = "Arial";
objText.Font.Size = 20;
//objText2 = slide.Shapes[2].TextFrame.TextRange;
//objText2.Text = "test";
//objText2.Font.Name = "Arial";
//objText2.Font.Size = 10;
//objText = slide.Shapes[2].TextFrame.TextRange;
//objText.Text = "pp";
Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
slide.Shapes.AddPicture(pictureFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 100, 100, 600, 400);
slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "MintPlus";
SlideIndex++;
}
pptPresentation.SaveAs(ImageToPptApp.Util.Constant.PptStorePath + "ppp"+ ".pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
pptPresentation.Close();
pptApplication.Quit();
}
return true;
}
I want to add labels both inside and outside of a pie chart.
I have tried adding values to it, it works either inside or outside.
I want to display both VALX and VALY on my chart
How can I do this?
I want my chart to appear like this.
XmlNodeList xnList = xml.SelectNodes("/Report/Parameters/Parameter");
var chart = new Chart();
chart.Height = 600;
chart.Width = 900;
ArrayList xAxisData = new ArrayList();
ArrayList yAxisData = new ArrayList();
string title = "Motility";
chart.Titles.Add(title);
var chartArea1 = new ChartArea();
chart.ChartAreas.Add(chartArea1);
chart.ChartAreas[0].AlignmentStyle = AreaAlignmentStyles.All;
Series series1;
xAxisData.Clear();
yAxisData.Clear();
string seriesName1 = " ";
byte ColorIndex = 0;
series1 = new Series();
seriesName1 = "Pie Chart";
series1.Name = seriesName1;
series1.ChartType = SeriesChartType.Pie;
chart.Series.Add(series1);
chart.ChartAreas[0].Area3DStyle.Enable3D = true;
chart.ChartAreas[0].Area3DStyle.Inclination = 40;
chart.ChartAreas[0].BorderColor = Color.Black;
chart.ChartAreas[0].Area3DStyle.WallWidth = 20;
chart.Series[seriesName1]["3DLabelLineSize"] = "30";
chart.Series[seriesName1].IsVisibleInLegend = false;
foreach (KeyValuePair<string, ReportParameter> pair in T_NewChart.parameters)
{
chart.Series[seriesName1].Points.AddXY((pair.Value.Name), pair.Value.Values[0]));
if (ColorIndex == 0)
{
chart.Series[seriesName1].Points[0].Color = Color.Green;
chart.Series[seriesName1].Label = "#VALX";
chart.Series[seriesName1]["PieLabelStyle"] = "Outside";
chart.Series[seriesName1].BorderColor = Color.Black;
chart.Series[seriesName1].Points[0].Label = "Total";
chart.Series[0].Font = new System.Drawing.Font("Arial", 15F);
}
else if (ColorIndex == 1)
{
chart.Series[seriesName1].Points[1].Color = Color.Yellow;
chart.Series[seriesName1].Points[1].Label = "Non";
}
else if (ColorIndex == 2)
{
chart.Series[seriesName1].Points[2].Color = Color.Red;
chart.Series[seriesName1].Points[2].Label = "Few";
}
ColorIndex++;
}
chart.SaveImage("C:\\NewPie_chart.png", ChartImageFormat.Png);
I can only display the "Name", but I want to display the "Name" (VALX) outside the chart and the "Value" (VALY) inside the chart.
When I press the x keyboard button, my player sprite won't attack for some reason. Is there anything I can do to help my sprite player to do an attack?
/// Obj_player Create Event
/// set fixed rotation for object player
event_inherited();
hp = 20;
spd = 4;
hspd = 0;
vspd = 0;
len = 0;
xaxis = 0;
yaxis = 0;
dir = 0;
attacked = false;
image_speed = 0;
scr_get_input();
state = scr_move_state;
/// Obj_player Alarm 0
/// This alarm is for the dash state
state = scr_dash_state;
state = scr_attack_state;
///Obj_player Step Event
/// move the player in the step event
event_inherited();
script_execute(state);
state = scr_move_state;
scr_get_input();
/// Obj_Animation End
/// Change back to move state
if (state == scr_attack_state) {
state = scr_move_state;
attacked = false;
}
/// scr_get_input
right_key = keyboard_check(vk_right);
left_key = keyboard_check(vk_left);
up_key = keyboard_check(vk_up);
down_key = keyboard_check(vk_down);
dash_key = keyboard_check_pressed(ord('C'));
attack_key = keyboard_check_pressed(ord('X'));
// Get the axis
xaxis = (right_key - left_key);
yaxis = (down_key - up_key);
/// scr_move_state
scr_get_input();
if (dash_key) {
state = scr_dash_state;
alarm[0] = room_speed/7;
}
if (attack_key) {
image_index = 0;
state = scr_attack_state;
}
// get direction
dir = point_direction(0,0, xaxis, yaxis);
// Get the length
if (xaxis == 0 and yaxis = 0) {
len = 0;
} else {
len = spd;
}
// Get the hspd and vspd
hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);
// move
phy_position_x += hspd;
phy_position_y += vspd;
// Control the sprite
image_speed = sign(len)*.2;
if (len == 0) image_index = 0;
// Vertical sprites
if (vspd > 0) {
sprite_index = spr_player_down;
} else if (vspd < 0) {
sprite_index = spr_player_up;
}
// Horizontal sprites
if (hspd > 0) {
sprite_index = spr_player_right;
} else if (hspd < 0) {
sprite_index = spr_player_left;
}
/// scr_attack_state
image_speed = .5;
switch (sprite_index) {
case spr_player_down:
sprite_index = spr_player_attack_down;
break;
case spr_player_up:
sprite_index = spr_player_attack_up;
break;
case spr_player_right:
sprite_index = spr_player_attack_right;
break;
case spr_player_left:
sprite_index = spr_player_attack_left;
break;
}
It is because in this line:
attack_key = keyboard_check_pressed(ord('X'));
You assigned attack_key to X, which is different from x. It should be:
attack_key = keyboard_check_pressed(ord('x'));
i want to use the neodynamic image draw sdk and keep getting this error on build i have searched for solutions but none work i have this is my current code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevPro.Data.Enums;
using YGOPro_Launcher.CardDatabase;
using System.IO;
using System.Reflection;
using System.Data.SQLite;
using DevPro_CardManager.Properties;
using Neodynamic.SDK;
namespace Outlaws_CardManager
{
public partial class cardmaker : Form
{
public cardmaker()
{
InitializeComponent();
TopLevel = false;
Dock = DockStyle.Fill;
Visible = true;
}
private void GenerateCard()
{
//Get the info to create the card
string cardname = "";
string cardid = "";
string level = "";
string race = "";
string attribute = "";
string atk = "";
string def = "";
string type1 = "";
string type2 = "";
string stype = "";
string traptype = "";
string mainpicture = "";
string layout = "Left";
if (!String.IsNullOrEmpty(CardName.Text))
{
cardname = CardName.Text;
}
if (!String.IsNullOrEmpty(CardID.Text))
{
cardid = CardID.Text;
}
if (!String.IsNullOrEmpty(ATK.Text))
{
atk = ATK.Text;
}
if (!String.IsNullOrEmpty(DEF.Text))
{
def = DEF.Text;
}
ImageDraw imgDraw = new ImageDraw();
//Basic settings for Card
imgDraw.Canvas.AutoSize = false;
imgDraw.ImageFormat = ImageDrawFormat.Png;
//Set card size
imgDraw.Canvas.Width = 400;
imgDraw.Canvas.Height = 250;
//Create main decorative shape element
RectangleShapeElement rect1 = new RectangleShapeElement();
rect1.X = 10;
rect1.Y = 10;
rect1.Width = 380;
rect1.Height = 230;
rect1.Roundness = 20;
rect1.StrokeWidth = 0;
//Set background
rect1.Fill.BackgroundColor = Color.Black;
//Add element to output image
imgDraw.Elements.Add(rect1);
//Create top decorative shape element
RectangleShapeElement rect2 = new RectangleShapeElement();
rect2.X = 20;
rect2.Y = 20;
rect2.Width = 360;
rect2.Height = 170;
rect2.Roundness = 10;
rect2.StrokeWidth = 0;
rect2.Fill.BackgroundColor = Color.White;
//Add element to output image
imgDraw.Elements.Add(rect2);
//Create bottom decorative shape element
RectangleShapeElement rect3 = new RectangleShapeElement();
rect3.X = 30;
rect3.Y = 130;
rect3.Width = 340;
rect3.Height = 100;
rect3.Roundness = 10;
rect3.StrokeWidth = 1;
rect3.StrokeFill.BackgroundColor = Color.Black;
rect3.Fill.BackgroundColor = Color.White;
//Add element to output image
imgDraw.Elements.Add(rect3);
//Create an ImageElement to wrap the user logo
if (mainpicture.Length > 0 && System.IO.File.Exists(mainpicture))
{
ImageElement imgElemLogo = new ImageElement();
//Get user logo from disk
imgElemLogo.Source = ImageSource.File;
imgElemLogo.SourceFile = mainpicture;
//Logo Layout
if (layout == "Right")
{
imgElemLogo.X = 40;
imgElemLogo.Y = 40;
}
else
{
imgElemLogo.X = 400 - (50 + 40); //Canvas Width - (Logo Width + X Margin)
imgElemLogo.Y = 40;
}
//Apply Resize logo
Resize resizeLogo = new Resize();
resizeLogo.Width = 50;
resizeLogo.LockAspectRatio = LockAspectRatio.WidthBased;
imgElemLogo.Actions.Clear();
imgElemLogo.Actions.Add(resizeLogo);
//Add element to output image
imgDraw.Elements.Add(imgElemLogo);
}
//Create TextElement objects for each fields
if (cardname.Length > 0)
{
TextElement txtElemName = new TextElement();
txtElemName.AutoSize = false;
txtElemName.Font.Name = "Arial";
txtElemName.Font.Size = 14f;
txtElemName.Font.Unit = FontUnit.Point;
txtElemName.Font.Bold = true;
txtElemName.ForeColor = System.Drawing.Color.Black;
txtElemName.Text = cardname;
txtElemName.TextQuality = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
txtElemName.X = 40;
txtElemName.Y = 40;
txtElemName.Width = 320;
txtElemName.Height = 20;
if (layout == "Left")
{
txtElemName.TextAlignment = ContentAlignment.MiddleLeft;
}
else
{
txtElemName.TextAlignment = ContentAlignment.MiddleRight;
}
//Add element to output image
imgDraw.Elements.Add(txtElemName);
}
if (cardid.Length > 0)
{
TextElement txtElemJob = new TextElement();
txtElemJob.AutoSize = false;
txtElemJob.Font.Name = "Arial";
txtElemJob.Font.Size = 10f;
txtElemJob.Font.Unit = FontUnit.Point;
txtElemJob.ForeColor = System.Drawing.Color.Black;
txtElemJob.Text = cardid;
txtElemJob.TextQuality = System.Drawing.Text.TextRenderingHint.AntiAlias;
txtElemJob.X = 40;
txtElemJob.Y = 64;
txtElemJob.Width = 320;
txtElemJob.Height = 14;
if (layout == "Left")
{
txtElemJob.TextAlignment = ContentAlignment.MiddleLeft;
}
else
{
txtElemJob.TextAlignment = ContentAlignment.MiddleRight;
}
//Add element to output image
imgDraw.Elements.Add(txtElemJob);
}
if (atk.Length > 0)
{
TextElement txtElemAddress = new TextElement();
txtElemAddress.AutoSize = false;
txtElemAddress.Font.Name = "Times New Roman";
txtElemAddress.Font.Italic = true;
txtElemAddress.Font.Size = 11f;
txtElemAddress.Font.Unit = FontUnit.Point;
txtElemAddress.ForeColor = System.Drawing.Color.Black;
txtElemAddress.Text = atk + "\n" + race;
txtElemAddress.TextQuality = System.Drawing.Text.TextRenderingHint.AntiAlias;
txtElemAddress.X = 40;
txtElemAddress.Y = 130;
txtElemAddress.Width = 160;
txtElemAddress.Height = 50;
if (layout == "Left")
{
txtElemAddress.TextAlignment = ContentAlignment.MiddleLeft;
}
else
{
txtElemAddress.TextAlignment = ContentAlignment.MiddleRight;
}
//Add element to output image
imgDraw.Elements.Add(txtElemAddress);
}
if (attribute.Length > 0 || atk.Length > 0)
{
TextElement txtElemPhone = new TextElement();
txtElemPhone.AutoSize = false;
txtElemPhone.Font.Name = "Georgia";
txtElemPhone.Font.Size = 10f;
txtElemPhone.Font.Unit = FontUnit.Point;
txtElemPhone.ForeColor = System.Drawing.Color.Black;
txtElemPhone.Text = "Phone: " + attribute + "\n" + atk;
txtElemPhone.TextQuality = System.Drawing.Text.TextRenderingHint.AntiAlias;
txtElemPhone.X = 200;
txtElemPhone.Y = 180;
txtElemPhone.Width = 160;
txtElemPhone.Height = 50;
if (layout == "Right")
{
txtElemPhone.TextAlignment = ContentAlignment.MiddleLeft;
}
else
{
txtElemPhone.TextAlignment = ContentAlignment.MiddleRight;
}
//Add element to output image
imgDraw.Elements.Add(txtElemPhone);
}
//generate image card and preview it
CardImg.Image = imgDraw.GetOutputImage();
}
}
}
has anyone had a problem like this before please explain how fixed.
Such problems might occur if your Project's Target-Framework and your referenced assembly framework version are incompatible.
So as I may presume, you should take the following steps:
Right-Click on your Project -> Properties -> Target Framework -> Make Sure it is not set on Client Profile and if it does than choose .NET Framework 4 or 4.5 (according to the referenced-assembly targeted FW).
Update: Here is a snapshot of the settings
How can I use Luxand API to get to work in visual studio 2010? I need to detect points of chin in a given face, can I do it with any other API?
I have tried this sample code:
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
FSDK.CImage image = new FSDK.CImage(openFileDialog1.FileName);
// resize image to fit the window width
double ratio = System.Math.Min((pictureBox1.Width + 0.4) / image.Width,
(pictureBox1.Height + 0.4) / image.Height);
image = image.Resize(ratio);
Image frameImage = image.ToCLRImage();
Graphics gr = Graphics.FromImage(frameImage);
FSDK.TFacePosition facePosition = image.DetectFace();
if (0 == facePosition.w)
MessageBox.Show("No faces detected", "Face Detection");
else
{
int left = facePosition.xc - facePosition.w / 2;
int top = facePosition.yc - facePosition.w / 2;
gr.DrawRectangle(Pens.LightGreen, left, top, facePosition.w, facePosition.w);
FSDK.TPoint[] facialFeatures = image.DetectFacialFeaturesInRegion(ref facePosition);
int i = 0;
foreach (FSDK.TPoint point in facialFeatures)
gr.DrawEllipse((++i > 2) ? Pens.LightGreen : Pens.Blue, point.x, point.y, 3, 3);
gr.Flush();
}
// display image
pictureBox1.Image = frameImage;
pictureBox1.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception");
}
}
I get this error:
Could not load file or assembly 'xquisite.application.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
what is your settings for your target? Any CPU ? Try x86 for Runtime !
have you add to your app.config <startup useLegacyV2RuntimeActivationPolicy="true"/>
?
These two thinks i forgot, were the reason of my errors which was the same as yours.
here is a piece of my code:
private void DetectFace()
{
var failerCounter = 0;
var cameraHandler = 0;
try
{
const int failerLimit = 2;
int failerLimitFaceDetection = Properties.Settings.Default.NotDetectedLimit;
float similarityMinimum = Properties.Settings.Default.SimilarityLimit;
var r = FSDKCam.OpenVideoCamera(ref CameraName, ref cameraHandler);
if (r != FSDK.FSDKE_OK)
{
MessageBox.Show(StringHelper.ErrorCamera);
}
FSDK.SetFaceDetectionParameters(
Properties.Settings.Default.DetectionHandleArbitaryRotations,
Properties.Settings.Default.DetectionDetermineFaceRotationAngle,
Properties.Settings.Default.DetectionInternalResizeWidth);
FSDK.SetFaceDetectionThreshold(Properties.Settings.Default.DetectionFaceDetectionThreshold);
while (IsFaceDetectionActive)
{
var imageHandle = 0;
if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandler, ref imageHandle))
{
Application.Current.Dispatcher.Invoke(delegate { }, DispatcherPriority.Background);
continue;
}
var image = new FSDK.CImage(imageHandle);
var frameImage = image.ToCLRImage();
FaceContent = frameImage;
var gr = Graphics.FromImage(frameImage);
var facePosition = image.DetectFace();
IsFaceDetected = facePosition.w != 0;
if (!IsFaceDetected)
{
if (failerCounter++ > failerLimitFaceDetection)
{
failerCounter = 0;
OnFaceNotDetected();
}
}
// if a face is detected, we detect facial features
if (IsFaceDetected)
{
var facialFeatures = image.DetectFacialFeaturesInRegion(ref facePosition);
SmoothFacialFeatures(ref facialFeatures);
FaceTemplate = image.GetFaceTemplate();
// Similarity = 0.5f -> fin the right value ....
IsFaceRecognized = FaceMetricHandler.LooksLike(FaceTemplate, similarityMinimum).Any();
if (IsFaceRecognized)
{
foreach (var match in FaceMetricHandler.LooksLike(FaceTemplate, similarityMinimum))
{
failerCounter = 0;
GreetingMessage = match.Name;
IsFaceDetectionActive = false;
OnFaceRecognized();
break;
}
}
else
{
if (failerCounter++ > failerLimit)
{
failerCounter = 0;
IsFaceDetectionActive = false;
OnFaceNotRecognized();
}
}
if (IsFaceFrameActive)
{
gr.DrawRectangle(Pens.Red, facePosition.xc - 2*facePosition.w/3,
facePosition.yc - facePosition.w/2,
4*facePosition.w/3, 4*facePosition.w/3);
}
}
else
{
ResetSmoothing();
}
FaceContent = frameImage;
GC.Collect();
Application.Current.Dispatcher.Invoke(delegate { }, DispatcherPriority.Background);
}
}
catch(Exception e)
{
logger.Fatal(e.Message);
InitializeCamera();
}
finally
{
FSDKCam.CloseVideoCamera(cameraHandler);
FSDKCam.FinalizeCapturing();
}
}
BTW, you can use x64 with win64\FaceSDK.NET.dll