Syncfusion Xamarin 'Value cannot be null. Parameter name: stream' during adding image - image

I would like to load image to pdf from stream. When I try to do that I get an error
System.ArgumentNullException: 'Value cannot be null.
Parameter name: stream'
Here is my code
Stream imageStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("MyApp.Resources.drawable.image.png");
PdfImage image = PdfImage.FromStream(imageStream); <---- here is error
g.DrawImage(image, new PointF(20, 20));

Firstly , in this way you need to put the image in Forms project instead of Android project .In my demo I put the image in the folder Assets . And the code should like the following
var assembly = this.GetType().GetTypeInfo().Assembly;
Stream s = assembly.GetManifestResourceStream("MyApp.Assets.icon.png");
In addition , make sure that the build action of the image is Embeddded Resource
Right Click the image -> Properties

We have checked the issue with loading the image to pdf from stream, but it is working properly. And the images are loaded and insert into the Pdf document and make sure that the build action of the image is Embeddded Resource. Kindly please try the sample in this below documentation and let us know the result.
KB : https://www.syncfusion.com/kb/10375/how-to-insert-an-image-into-pdf-in-xamarin
UG : https://help.syncfusion.com/file-formats/pdf/working-with-images
Note: I am work for Syncfusion.

Related

`filter.applyTo is not a function` error when try to change image src using setSrc() in fabric js

Currently, I am Working on image editor that allows me to crop an image and apply a filter.
I am using fabric js version 1.7.22.
I want to implement crop functionality.
so my cropping flow is like Below :
crop image using a plugin and ger base64 of the cropped image.
generate blobUrl from base64 which help to display image in fabric js canvas.
After Cropping the image, I Just replace old image src with new One.
It works fine when an image has no filter.
but when I try to set a filter in the image first then try to replace src using setSrc() function.
It throws an error like Below
filter.applyTo is not a function
I have created one fiddle for demonstrating to replace src after the apply filter.
https://jsfiddle.net/Mark_1998/98gLhcb4/1/
And I Can't upgrade my fabric js version. If any patch Available then
Please Help Me.
The problem lies in this piece of code:
canvas.getActiveObject().setSrc('http://fabricjs.com/assets/pug_small.jpg', function(){
canvas.renderAll();
}, canvas.getActiveObject().toObject());
You're passing canvas.getActiveObject().toObject() as an options object, which is assigned to your image in setSrc() -> setElement() -> _initConfig().
toObject() serializes your fabric.Image, and filters array no longer contains the actual fabric.Filter, but rather a serialized version of it. So, it does not have a prototype with applyTo() method on it, hence the error filter.applyTo is not a function when fabric tries to reapply filters to your image after setSrc().
Instead of passing the whole serialized object as options, you'll need to pick the properties you actually want to be passed. As I'm not sure about what your requirements are, I tried replacing the above code with the following and it worked for me:
var options = canvas.getActiveObject().toObject();
delete options.filters;
options.crossOrigin = true;
canvas.getActiveObject().setSrc('http://fabricjs.com/assets/pug_small.jpg', function(){
canvas.renderAll();
}, options);
Note the options.crossOrigin = true - you won't be able to apply filters without it.

Load a PNG image file for display on a Vaadin Flow layout as a Image object

Vaadin Flow offers an Image class, representing an HTML img tag.
If I have a file named logo.png stored in the resources folder of my Vaadin 12 app, how do I load that file for display as an Image on a layout?
The example for Image in the Vaadin 8 Sampler shows code no longer relevant as I cannot find a ClassResource class in Flow.
You can put that logo under what your build tool/setup considers a root for web resources under the directory frontend/... and then reference that resource like so:
new Image("frontend/images/logo.png", "Acme Inc. Logo")
If your resource is not located inside the root for web resources, this doc page gives a hint on using a com.vaadin.flow.server.StreamResource to provide the data by an java.io.InputStream:
StreamResource res = new StreamResource("logo-image.png", () -> {
// eg. load image data from classpath (src/main/resources/images/image.png)
return MainView.class.getClassLoader().getResourceAsStream("images/image.png");
});
Image imageFromStream = new Image( res,"Alternativ text description for logo image");
add(imageFromStream);
In my case the problem was in the location of the file:
If you use: new Image("img/logo.png", "Logo") then the file location should be /src/main/resources/META-INF/resources/img/logo.png in Spring Boot project

best way to show images stored in the app from a webview in SWIFT

I have a webview and would like to show an image in the webview (html)
My HTML :
hello !img src="myimage.png" alt="myimage" height="42" width="42"!
(I used ! as tagend and tagstart, because I don't know how to add this here without be interpreted as HTML, even I pasted as code)
The myimage.png should be stored in app itself and not be loaded from a websource.
I don't know how to do that in a best practice way. Any help ?
UPDATE
I tried with referenced Article, but still not succeeded:
My Code for this:
let path:NSString = NSBundle.mainBundle().bundlePath;
var baseURL:NSURL=NSURL(fileURLWithPath: path as String)!;
var htmlString:String! = texttemp
myWebView.loadHTMLString(htmlString, baseURL: baseURL)
The same Image I can already load like the following -> works:
var image = UIImage(named: "myimage.png");
Your updated code isn't right. You are creating a path to the bundle, not to the specific file. You need to use the NSBundle method pathForResource:ofType (or one of its variants) to build a path to your file. Then use that to create the URL.
The pathForResource:ofType family of methods return nil if the file can't be found, so you should check that you are getting back a path.
EDIT:
Looking at it more closely, I see that you are using the URL as the base URL for a call to loadHTMLString. This does look like a sound approach. What is your HTML string, and where is the image in your bundle?

Embedded resource and adding images

I am developing a form application with monodevelop. I'm using gtk#.
I need to add an image to a widget in the form. I am also trying to make this image an embedded resource as well, before including it in the form.
so far this is what I have:
HBox CharacterPic = new HBox();
Image LegionnairePic = new Image('somehow load the embedded resource image here');
CharacterPic.PackStart (LegionnairePic);
In the 'Solution' section to the left, I have added .jpeg files and changed their 'build action' to 'embedded resource'. However, I cannot access/load them onto the form them as so:
Image LegionnairePic = new Image(<namespace>.<resource>);
How do I add the image resource to the form? Am I even adding the resource correctly?
I believe you have to access the embedded files with the following method:
// string resource_id is the Resource ID of the file in the sidebar “Properties”
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resource_id);
This returns the resource file as a Stream.
If this helped, thank that guy like I did :)

How to use System.Drawing.Image in RDLC Image Control?

Is it possible to use System.Drawing.Image in an RDLC Image Control?
All I have been reading were 3 methods:
database
embeded resource
external file
Thank you thank you.
EDIT:
Following up from this .NET or C# library for CGM (Computer Graphics Metafile) format? I now got the image in System.Drawing.Image format and want to display it as part of the report (as an image) --- that's what I want to do.
Not sure if this is what you are looking for, but if you have an image in code and you want to show it in the report, create a wrapper object that has a property that returns the image as a byte array and give then an instance of this wrapper-class with the valid image to the report as a ReportDataSource.
Something like:
ReportDataSource logoDataSource = new ReportDataSource();
logoDataSource.Name = "LogoDS";
logoDataSource.Value = new List<LogoWrapper>() { yourLogoWrapper };
localReport.DataSources.Add(logoDS);
In the report you then you can the image as it were from the database
=First(Fields!LogoByteArrayProperty.Value, "LogoDS")
The wrapper looks something like:
class LogoWrapper{
...
public byte[] LogoByteArrayProperty{
get{
// Return here the image data
}
}
}
I use this quite often. It has the advantage that I don't have to add the image to the db or add it as a resource of every report. And furthermore, the app can say which image should be used.
Please note, the given image format must be known from the rdlc-engine.
The last question would be, how to convert a system.drawing.image to a byte array. I work with WPF and therefore, I dont known. But I'm sure google will respond to this question very reliable.
You Can use the 'Database' Source Option along with Parameters to Dynamically set Image Source from Byte Arrays.
Code Behind:
var param2 = new ReportParameter()
{
Name = "CompanyLogo",
Values = { Convert.ToBase64String(*ByteArrayImageObject*) }
};
ReportViewer1.LocalReport.SetParameters(param2);
rdlc File:
1- Add Text Parameters 'CompanyLogo' and 'MIMEType'
2- Set the Value Property of the Image to =System.Convert.FromBase64String(Parameters!CompanyLogo.Value)
3- Set MIME Type Property to
=Parameters!MIMEType.Value
4- Use 'Database' As Source
How can I render a PNG image (as a memory stream) onto a .NET ReportViewer report surface
i am not quite sure what do you want to do with this but in general it is not possible.Image Control is just a image holder in the RDLC files.These 3 options specify the location from where the image control takes the image which to display from- database, embeded resource or external file. If you give me more info on what do you want to achieve i can give you some kind of solution.
Best Regards,
Iordan

Resources