get base64 in javascript to silverlight image - c#

I have a javascript function that get base64 string then I need to pass this value to a silverlight object within my page to render the base64 as jpeg image
Now I use AJAX to build the image and rerender it on the page but it take alot of time I believe that with silverlight it won't take that much of time
So any resources on this issue?

You can just set the image src to the base64 string, both on tags and in CSS. So you don't have to convert the base64 string, you can just render it in place. This will give you a faster user experience.
Replace the underscores in the following examples with your base64 string:
<img src="data:image/png;base64,______________">
Or, using CSS:
background-image: url(data:image/png;base64,_____________);
If you want to send something from JavaScript to Silverlight (1) to process it (2), and then maybe back from Silverlight to JavaScript (3), check out the below links. When I say "process it", this probably means saving the image and sending back an image URL. But if you want to display it using Silverlight, this is of course unnecessary.
JavaScript/Silverlight Interop (includes passing JS parameter to Silverlight)
C#: Base64 string to Bitmap
Pass parameters from Silverlight to JavaScript

Related

C# Selenium - Can't access image url in another tag

I'm trying to validate image on website however can't access the url of the image.
Most websites will have the image with a "src" tag however this website has the url imbedded in another tag.
Iv used return driver.FindElement(By.ClassName("p-image__image--contain")); to access the element and used GetAttribute("style"); to access the image url. However the only information given was background-position: center center;
html format
When you use GetAttribute("style"), it will only return whatever was in the actual style attribute on the element, but many CSS attributes are actually applied using class stylesheets or other ways. So instead you should use the GetCssValue method, like so:
element.GetCssValue("background-image")
getCssValue(); will help in this case
WebElement img = driver.findElement(By.className('imgClass'));
String imgPath = img.getCssValue("background-image");
you will got full values in imgPath, Value like url("imageURL") then you need to use regex OR get values by slip function
I hope this scenario will help

Is it possible to append a string in code to a Base64 string and create a new Image with the string?

I am using the QR Coder library in C# to generate QR codes that will go to a URL with a Token in the Query String.
https://github.com/codebude/QRCoder
Currently, I can Print Preview all the QR Codes, but without a Token showing beneath it.
I need to display a string below the QR Code image with a Token Code when I click on the Print Preview button. This will fetch all the QR Code images and show them on the Print Preview window.
The Print Preview button will fetch all the Tokens generated, append them to a link and finally generate the base64 string for the QR Image that is sent to a JavaScript Print method.
I am using Print JS: https://printjs.crabbly.com/
Below is my JavaScript method below with the following code (Multiple Image Mode):
function printAllQRCodesForProduct(base64, printwidth) {
printJS({ printable: **base64**, type: 'image', imageStyle: 'width:' + printwidth + '%;margin-
bottom:10px; float:left; margin-right:10px;' });
}
It does not seem that Print JS can allow you to have multiple image captions. If this was the case, that would work. Perhaps I can modify the Print JS code or perhaps is it possible to somehow take the generated Base64 image QR code and append a string with the Token text just below it without having to render the image on a Canvas tag and then re-saving it as a Base64 string? Can all this be done on the Code-Behind in C#?
So in summary, is it possible to modify a base64 generated image with another image and combine them, or is there a way to add text and get a new base64 image string?
I see that it is possible to add text to a generated Bitmap in C#.
Found the answer on this post: c# write text on bitmap

Adding images to RadioButtonList causes error on postback

I have RadioButtonList, in which I am adding images dynamically:
this.RlCredtiCardTypes.Items.Add(new ListItem(String.Format("<img src='{0}'>", GetImageUrl(item.Code), item.Code)));
This will render fine, but on post back I get the following error:
A potentially dangerous Request.Form value was detected from the client
I understand the error. The question is; how do I dynamical add images to my RadioButtonList without causing this error?
I have also tried to HttpContext.Current.Server.HtmlEncode the img string, but that renders the literal text and not the image.
As a note, I do not want to set EnableEventValidation="false", as this will leave my page open to nefarious activity.
This question seems to related to this question, but its not marked as answered.
message A potentially dangerous Request.Form value was detected from the client comes whenever you try to pass html string via post in asp.net
Your best way to do is encode string into base64 and than decode it while showing into form and while posting form's data back just convert all html related data into base64 string via jquery or javascript.
The reason this occurs is the html code for the image is being sent across in the post back. You can disable validation on the RadioButtonList by adding ValidateRequestMode="Disabled" validaterequestmode(v=vs.110)
<asp:RadioButtonList ID="RlCredtiCardTypes" runat="server" ValidateRequestMode="Disabled"></asp:RadioButtonList>
This will leave the rest of your form securely checking against evil code.

taking a screenshot of some element in the html

So I was wondering, if I have a div which contains a maps of google maps rendered with some makers and I want to take a picture of that element how can I do this?.I found this solutions it's a approach of what I need but the problem it's that sending a url doesn't help me, I need the specific Div with all the markers. For the server side i'm using C# and for the cliente, asp.net with jquery. Also the google maps apiV3 to handle the maps
Take a look at the Canvas2Image library by Nihilogic Labs:
http://www.nihilogic.dk/labs/canvas2image/
Here's an example of how to take a screenshot of an element through JavaScript:
var oCanvas = document.getElementById("thecanvas");
Canvas2Image.saveAsPNG(oCanvas);
EDIT
You might also take a look at Html2Canvas and FlashCanvas too. I believe one of them has support for earlier browsers (those which don't support HTML5).
Use the method in the link you mentioned and crop the resulting image to the dimensions of your div. You can use myDiv.getBoundingClientRect() in JavaScript to get the dimensions of your div.
Using the WebBrowser control, you can manipulate the document using html or JavaScript to get the page in the state you need to take your screenshot.
Have you considered using the Google Maps Static API - this will render a map image, with markers on it, as a PNG.

how to grab an image out of a DIV with C#

is it possible to grab an image that is embedded in a div via C# and attach it to an email?
I've got the code for attaching and sending images via email, I just don't know how to get it to grab the specific item out of the div and email it.
The image varies with a previous user selection so I can't just apply a static address of an image.
any ideas?
You need to grab image from inbound email?
Read more about MIME format: all images in email message are encriped in base64 format in MIME message. To grab your image you need to parse your emailmessage, read base64 string, wich encript your image, and decoding this string like this:
var byties = Convert.FromBase64String(Body)
I would look at using the microsoft html control, read the document and use the DOM to get the url of the image, download it using the http and then attach it to your email
for reference
How to download the image
Reading the Dom from visual studio
Use HtmlAgilityPack and HttpWebRequest.

Categories