C# facebook sdk post animated gif - c#

I'm trying to develop an application for posting animated gifs directly to a facebook wall of a logged user.
Everything works fine with static images, but when I try to upload animated gif, only first frame is shown on a user wall...
My code is:
FileInfo file = new FileInfo(System.IO.Path.GetFullPath(printfile));
FacebookMediaObject facebookUploader = new FacebookMediaObject { FileName = file.FullName, ContentType = "image/gif" };
var bytes = File.ReadAllBytes(file.FullName);
facebookUploader.SetValue(bytes);
var postInfo = new Dictionary<string, object>();
postInfo.Add("image", facebookUploader);
FBClient.Post("/me/photos", postInfo);
What am I doing wrong? I have done a little searching in this topic, I'm know that in the past it wasn't even possible to publish animated gifs on facebook, but now I can see there is a lot of animated gifs on facebook, so it's seems to me it's possible now...
Unfortunately, facebook c# sdk is a third party software and I cant find a good documentation for it. I know that it is somewhere in the internet, but I can't find it... I would be very gratefull if you could help me find a good one.
I would appreciate every clue and answer.
Thank you in advance.

Related

c# embedded images or is there another way

I'm trying to find a good way to load say 100+ small images (98px png's each) into my .net form and additionally have them all interactive in a way (click, and a name of the image/file), but without loading the images from a local predefined folder. What do I mean by that? Let me explain and demonstrate an example. Please bear with me, I'm kinda confused on the topic of building the solution and compiling the executeable's folder structure.
Example:
Imagine when creating a profile on say, here for example. Usually, you set a name and add a profile picture. Sometimes the profile picture has to be uploaded, but in my case I want to have a preset of 100 available profile pictures that the user can choose from. It may sound like a lot, but considering the purpose of the application it really is nesseary.
The problem/question:
The easy and probably not so good way is simply adding pictureboxes and assigning a click to them onto a flowlayoutpanel. This is my current temporary solution, but the big flaw is that it uses a locally stored path. This app is supposed to installed on several machines and I need this to work on whichever computer it's installed on, no matter what drive letter that is used ect.
string[] files = Directory.GetFiles("C:\\path\\folder_a", "*", SearchOption.TopDirectoryOnly);
foreach (var filename in files)
{
Bitmap bmp = null;
try
{
bmp = new Bitmap(filename);
}catch{
}
var card = new PictureBox();
card.BackgroundImage = bmp;
card.Tag = (filename.Split('\\').Last());
card.Padding = new Padding(0);
card.BackgroundImageLayout = ImageLayout.Stretch;
card.Size = normal;
card.Click += delegate
{
//something
};
flowProfileIcons.Controls.Add(card);
}
These are the options to my knownledge, but I don't really know:
Embed (in 'build action') all the images directly from a folder within solution explorer and use AssemblyDirectory to find and use the images in a similar way as displayed above. However, will this allow the users to actually access and potentionally modify/delete the files because they are exposed in the installation folder? And is this even a good way to do this?
Put all images in resources.resx and somehow use the images from there, but as far as I've seen that isn't very easy to do. I will definitely look into it though if this is the prefered way. I did try some things out and this is my progress so far, though just testing - not working.
var images = Properties.resProfileIconsDark.ResourceManager
.GetResourceSet(CultureInfo.CurrentCulture, true, true)
.Cast<DictionaryEntry>()
.Where(x => x.Value.GetType() == typeof(Bitmap))
.Select(x => new { Name = x.Key.ToString(), Image = x.Value })
.ToList();
This is where I'm at. Hopefully someone can push me in the right direction.

Resize Image (jpg) in Blazor WebAssembly?

What is the best way to resize an image that is uploaded on a Blazor client page. These are real simple images that I just wanted to have a consistent width and was hoping to use the System.Drawing, but that is not available in web assembly. I was hoping to do it on the client, but is it best to send it to a Controller for processing?
Thanks,
Mike
.NET 5 has an extension method to IBrowserFile called RequestImageFileAsync. Per the documentation, it "Attempts to convert the current image file to a new one of the specified file type and maximum file dimensions."
We use a package PhotoSauce.MagicScaler for all images uploaded from any blazor page.
https://photosauce.net/
I have no affiliation with this package / author etc. Just recommend it because it works so well.
There are lots of params that you can set in the ProcessImageSettings for width, method of resizing etc.
var settings = new ProcessImageSettings { Height = 250 };
using var outStream = new FileStream(thumbNailPathAndFile, FileMode.Create);
MagicImageProcessor.ProcessImage(pathAndFile, outStream, settings);

Cannot upload picture from hard drive to eBay sandbox with API

I tried to upload my picture but it didn't work. I know sandbox doesn't support photos but I mean inside the sandbox listing there is main photo. Other sellers have a main photo so there must be a way.
My code compiles without an error but there just isn't a photo when I go to the sandbox. Here is the code I'm using:
apiCall.PictureFileList = new StringCollection();
apiCall.PictureFileList.Add(#"C:\Users\Danny\Desktop\deleteMeBiggerEbayPic.jpg");
item.PictureDetails = new PictureDetailsType();
item.PictureDetails.GalleryType = GalleryTypeCodeType.Gallery;
Afaik you can't upload pictures from your local hard-drive using the eBay SOAP API. You need to sepcify a public URL where eBay can download the image from.
BTW: The sandbox supports photos, the only thing it doesn't support are gallery images.
I decided to try the original code again and to my surprise it worked. Maybe I did something wrong but I cant be bothered checking, its working now.
Here is the code:
//Set the Picture Server URL for Sandbox
apiContext.EPSServerUrl = "https://api.sandbox.ebay.com/ws/api.dll";
//For production use this URL
//context.EPSServerUrl = "https://api.ebay.com/ws/api.dll";
//Set file path of the picture on the local disk
apiCall.PictureFileList = new StringCollection();
apiCall.PictureFileList.Add(#"C:\Users\Danny\Desktop\MyGalleryPicOnHardDrive.jpg");
//To specify a Gallery Image
item.PictureDetails = new PictureDetailsType();
//The first picture is used for Gallery URL
item.PictureDetails.GalleryType = GalleryTypeCodeType.Gallery;
//To add more pictures
//apiCall.PictureFileList.Add(#"C:\TEMP\pic2.gif");

C# import of Adobe Illustrator (.AI) files render to Bitmap?

Anyone knows how to load a .AI file (Adobe Illustrator) and then rasterize/render the vectors into a Bitmap so I could generate eg. a JPG or PNG from it?
I would like to produce thumbnails + render the big version with transparent background in PNG if possible.
Ofcause its "possible" if you know the specs of the .AI, but has anyone any knowledge or code to share for a start? or perhaps just a link to some components?
C# .NET please :o)
Code is most interesting as I know nothing about reading vector points and drawing splines.
Well, if Gregory is right that ai files are pdf-compatible, and you are okay with using GPL code, there is a project called GhostscriptSharp on github that is a .NET interface to the Ghostscript engine that can render PDF.
With the newer AI versions, you should be able to convert from PDF to image. There are plenty of libraries that do this that are cheap, so I would choose buy over build on this one. If you need to convert the older AI files, all bets are off. I am not sure what format they were in.
private void btnGetAIThumb_Click(object sender, EventArgs e)
{
Illustrator.Application app = new Illustrator.Application();
Illustrator.Document doc = app.Open(#"F:/AI_Prog/2009Calendar.ai", Illustrator.AiDocumentColorSpace.aiDocumentRGBColor, null);
doc.Export(#"F:/AI_Prog/2009Calendar.png",Illustrator.AiExportType.aiPNG24, null);
doc.Close(Illustrator.AiSaveOptions.aiDoNotSaveChanges);
doc = null; //
}
Illustrator.AiExportType.aiPNG24 can be set as JPEG,GIF,Flash,SVG and Photoshop format.
I Have Tested that with Pdf2Png and it worked fine with both .PDF and .ai files.
But I don't know how it will work with transparents.
string pdf_filename = #"C:\test.ai";
//string pdf_filename = #"C:\test.pdf";
string png_filename = "converted.png";
List<string> errors = cs_pdf_to_image.Pdf2Image.Convert(pdf_filename, png_filename);

Reading PSD file format

I wonder if this is even possible. I have an application that adds a context menu when you right click a file. It all works fine but here is what I'd like to do:
If the file is a PSD then I want the program to extract the image. Is this possible to do without having Photoshop installed?
Basically I want the user to right click and click "image" which would save a .jpg of the file for them.
edit: will be using c#
Thanks
The ImageMagick libraries (which provide bindings for C#) also support the PSD format. They might be easier to get started with than getting into the Paint.NET code and also come with a quite free (BSD-like) license.
A simple sample (found at http://midimick.com/magicknet/magickDoc.html) using MagickNet would look like this:
using System;
static void Main(string[] args)
{
MagickNet.Magick.Init();
MagicNet.Image img = new MagicNet.Image("file.psd");
img.Resize(System.Drawing.Size(100,100));
img.Write("newFile.png");
MagickNet.Magick.Term();
}
Note: MagickNet has moved to http://www.codeproject.com/KB/dotnet/ImageMagick_in_VBNET.aspx
Well, there's a PSD plugin for Paint.NET which I think is Open-Source which you might want to take a look at for starters:
http://frankblumenberg.de/doku/doku.php?id=paintnet:psdplugin#download
This guy do it easier:
http://www.codeproject.com/KB/graphics/simplepsd.aspx
With a C# library and a sample project.
I've tried with PS2 files and works ok.
I have written a PSD parser which extracts raster format layers from all versions of PSD and PSB. http://www.telegraphics.com.au/svn/psdparse/trunk
You can use GroupDocs.Viewer for .NET API to render your PSD files as images (JPG, PNG, BMP) in your application using a few lines of code.
C#
ViewerConfig config = new ViewerConfig();
config.StoragePath = "D:\\storage\\";
// Create handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
// Guid implies that unique document name
string guid = "sample.psd";
// Get document pages as images
List<PageImage> pages = imageHandler.GetPages(guid);
foreach (PageImage page in pages)
{
// Access each image using page.Stream
}
For more details and sample code, please visit here.
Disclosure: I work as a Developer Evangelist at GroupDocs.
For people who are reading this now: the link from accepted answer doesn't seem to work anymore (at least for me). Would add a comment there, but not allowed to comment yet - hence I'm adding a new answer.
The working link where you can find the psdplugin code for Paint.Net: https://github.com/PsdPlugin/PsdPlugin
Here is my own psd parser and exporter:
http://papirosnik.info/psdsplit/.
It allows to correctly parse psd with rgb color 8, 16- and 32-bit for channel, process user masks, export selected layers into jpeg, png, jng, bmp, tiff; create xml layout of exported layers and groups and also create a texture atlas and animations set from given layers.
It's entirely written in C#. If you want its sources inform me via support link on About dialog in the application.
ImageMagick.NET - http://imagemagick.codeplex.com/ - is the later version of the link 0xA3 gave, with some slightly different syntax. (Note, this is untested):
using ImageMagickNET;
public void Test() {
MagickNet.InitializeMagick();
ImageMagickNET.Image img = new ImageMagickNET.Image("file.psd");
img.Resize(new Geometry(100, 100, 0, 0, false, false);
img.Write("newFile.png");
}
I got extraction from psd working. see my answer here
How to extract layers from a Photoshop file? C#
may help someone else.
FastStone does this pretty efficiently.
They do not have their libraries availaible, but I guess you can contact them and see if they can help.
Check out their website: http://www.faststone.org/download.htm
I've had great success with Aspose's Imaging component which can load and save PSD files without Photoshop: https://products.aspose.com/imaging/net

Categories