I've been playing around with the resco API for windows mobile 6: http://www.resco.net/ and one thing they do is serialize bitmap images and base64 encode them in the .resx file, for example like this:
<data name="buttonCell2.ImagePressed" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAEMAAAAaCAMAAADblRF+AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAYZQTFRFtgAA////
wAAAygAA2wAA2AAA0gAAuQAAvQAAsQAAwwAAzgAAxgAA1QAA3wAA4gAAswAArgAA5QAA5wAArAAA6gAA
nQAA2QAAgAAA/wD/5AAApwAAxwAAugAA4AAAoQAAlQAAqgAAqAAAmgAAwgAAsAAAzQAA6AAA1wAA3gAA
dQAAfAAAogAAvgAAsgAA/fTprQAAzwAAqwAAfwAAzAAAxAAAkQAAxQAAtAAAtQAA9M6Rz4SEsSoq+PDw
agAAggAApAAAtDAw//36ZgAAewAAyX5+67uCbgAAdAAAyQkJjAAA+uO8qQYGoRsXtCwqeAAAYwAA1pld
fCQWZQcEkwAA2qlqtWU/dRgP/fXmnCcnqGU/+d24mwAApQAAqicnjgAA/Pn5/fTneCQVigAA4qtxhx0b
bAAA/fLkgCYY//38rB4edAcEp2E6owAAjx8UlwAA/ffucgAAcwAA0X94dgAAuXp2cAAAhQAAZQAAngAA
aAAAnwAAxzAwgiQejQAA6s/PrGpDfx8Ulyx+wgAAASBJREFUOE+l1dVWw1AUBNBzkhYIUigUuUnapO7u
WHF3d3d31z8nXYsvuGe/zzzOAGNs7fchnG7jkL5aMuIM2OJyWFck4CIpkwfljrlSj5AMtHIJJIWpdgY/
05G8SfY3c/HLpvw9g5Ntu1lu4iabP8bh/F21yI3cZMfoCowoGUc9gSPTByGnL2ghCPoQQopoIhER7jZV
M4mKcHuZrSPJIjxpngoSD8Lwa7SGJIpw5LaLJHaE7muoJQGEN71QTVJA6F+QBBIJ4SVnrSKxIsx8OStJ
nAjz+0qRa8P+Q8UJhL1nLdZAEOs9hYsBd8IrcfMmOo6BfY5FbFZuts4dY5NnD3OaK2XjknKdfe8aHWzo
cVXfaOGyNdh1U/4Gw3ocOcXL8T+dxW1D92ffagAAAABJRU5ErkJggg==
</value>
</data>
And it gets loaded up like so:
this.buttonCell1.ImagePressed = ((System.Drawing.Image)(resources.GetObject("buttonCell1.ImagePressed")));
When I base 64 decode the value I get a .bin which I can load in paint and it looks like the button image.
My quesiton is: how do I serialize a bitmap image (or any image really) into text and then base64 encode it so I can add it to the resx file in a Windows Mobile project.
You could do something like this. Substitute the first row for a more valid one :)
var myImage = new Bitmap(50,50);
var ms = new MemoryStream();
myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] data = new byte[ms.Length];
ms.Read(data, 0, data.Length);
var base64ConvertedString = Convert.ToBase64String(data);
public BitmapImage Base64ToImage(string base64String)
{
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0,imageBytes.Length);
BitmapImage image2 = new BitmapImage();
image2.SetSource(ms);
ms.Close();
return image2;
}
call the function like this,
BitmapImage test = new BitmapImage();
test = Base64ToImage(split[3].ToString());
ImageBrush berriesBrush = new ImageBrush();
berriesBrush.ImageSource = test;
button1.Backgroud=berriesBrush;
Related
I am trying to convert base64 string to image in .net core but the resulted image is corrupted
Following is my code
if (!String.IsNullOrEmpty(model.Image))
{
string filePath = Path.Combine(_hostingEnvironment.ContentRootPath+"/Image" , model.ImageName);
System.IO.File.WriteAllBytes(filePath, Convert.FromBase64String(model.Image));
}
is there any other method to create image from base64 string and save to server in asp.net core?
I have tried your code and it works well.You could try below correct base64string to have a test and check whether you have a correct base64string
var image = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC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tO5vMGCzLzZ1Lgt2WMQOvjGMfv+C6nvh7nzMyfxzE7mSeEsWJOdDMmf4PDw3q5jUrOgcdahATwLZJY7go+ZHFpf7frjzNv15ZksSTMYsYmd8puSZ+LFiTEljUEmZMyYmeGeUyJ7TP7ZfrvxaRx6gz7E2Z2d2AxZvNnd5t5jn4zj+n9V/4/weWep9uPMzKTZxwkzJbsb4xYg4e5JsSe3Dz5vNns56MDGie/HlzZvwZfWepuuG0dt4cXz5k+3hYscJJy9z/Bn+Kzvlnbxj0nCTc7tyTMzYk4xZwz3kmWWzp/vqLnsnXi2nq3wWqfcL4i/sP+2LHDCZme+Xh4ec44ePM8dTJJJddTE4Y2ye0nDGIOI0+n92ruA95zm24OLzBPcMxzke0s+QH9cY4ZMycM8+JmScZ5ZJ5xy92Jksbv/9k=";
var bytes = Convert.FromBase64String(image);
string filePath = Path.Combine(_hostingEnvironment.ContentRootPath + "/Image" , "testImage.jpeg");
using (var imageFile = new FileStream(filePath, FileMode.Create))
{
imageFile.Write(bytes, 0, bytes.Length);
imageFile.Flush();
}
I am trying to figure out if its possible to convert PDF document into a series of images.
Currently looking to migrate from ASP.NET 4.6 to ASP.CORE and this is so far the roadbloack to it.
I cannot seem to find any working examples for ASP Core of this currently.
Appreciate any help i can get.
You can use Docnet,
Here is an example code from project:
private static byte[] GetModifiedImage(IPageReader pageReader)
{
var rawBytes = pageReader.GetImage();
var width = pageReader.GetPageWidth();
var height = pageReader.GetPageHeight();
var characters = pageReader.GetCharacters();
using (var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb))
{
bmp.AddBytes(rawBytes);
bmp.DrawRectangles(characters);
using (var stream = new MemoryStream())
{
bmp.Save(stream, ImageFormat.Png);
return stream.ToArray();
}
}
}
Hope it helps
Cheers
I used QrEncoder (NuGet Package QrCode.Net) for generating QR Code in MVC 4. Now my question is how can I show this QR code in my RDLC Report dynamically. I searched through many websites but didn't got any feasible Solution.
One way would be to:
Create a handler in .net to dynamically generate the QR code based on querystring parameters and return it as a png.
setup the rdlc to have an image that is externally referenced.
when generating the report you will need to set it to allow external references
pass the url to the handler/image in the dataset being sent to the report and have that be the path for the image in the report.
When the report is generated it will then generate and show the QR code.
var data = db.spMemberDetailByMembership(CompanyId, BranchId, Convert.ToInt32(MemRegId)).Select(x => new SPMemberRegisterModel
{
ID = x.ID,
BookingPrice = x.BookingPrice,
MailingAddress = MailingAddress(x.ID),
BarCode = GenerateQrCode(x.UUID),
}).ToList();
reportdatasource.Value = data;
localReport.DataSources.Add(reportdatasource);
private byte[] GenerateQrCode(string qrmsg)
{
QRCoder.QRCodeGenerator qRCodeGenerator = new QRCoder.QRCodeGenerator();
QRCoder.QRCodeData qRCodeData = qRCodeGenerator.CreateQrCode(qrmsg, QRCoder.QRCodeGenerator.ECCLevel.Q);
QRCoder.QRCode qRCode = new QRCoder.QRCode(qRCodeData);
Bitmap bmp = qRCode.GetGraphic(5);
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
imgBarCode.Height = 150;
imgBarCode.Width = 150;
using (Bitmap bitMap = qRCode.GetGraphic(5))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
return byteImage;
}
}
}
I am currently trying to use the WebView to display encrypted data (using DPP). The issue is that I am not able to get the WebView to show anything if the stream is manipulated in any way after reading the StorageFile into an IRandomAccessStream (ie. unencrypt the data).
This issue can easily be reproduced by using the source provided by Microsoft: http://code.msdn.microsoft.com/windowsapps/XAML-WebView-control-sample-58ad63f7
and altering the "StreamUriWinRTResolver" class to convert the IRandomAccessStream to a memory stream and then back again. Basically, in S4_NavToStream.xaml.cs at line 128, change this:
StorageFile f = item as StorageFile;
IRandomAccessStream stream = await f.OpenAsync(FileAccessMode.Read);
return stream.GetInputStreamAt(0);
With this:
StorageFile f = item as StorageFile;
IRandomAccessStream randStream = await f.OpenAsync(FileAccessMode.Read);
var stream = randStream.AsStream();
MemoryStream ms = new MemoryStream();
stream.CopyTo(ms);
return ms.AsInputStream();
This will show a blank page when run. I'm starting to think this is a bug, unless of course I'm using the stream conversions incorrectly. Has anybody tried anything similar?
Thomas Huber has very graciously answered my question over on social.msdn.microsoft.com. Full answer here:
http://social.msdn.microsoft.com/Forums/en-US/f51ab699-66c3-4961-8952-fbe341bf3e23/windows-81-webviewnavigatetostream-does-not-work-when-altering-the-stream
In summary, the issue is around the conversion of the memory stream to an input stream. This is the correct working code:
StorageFile f = item as StorageFile;
IRandomAccessStream randStream = await f.OpenAsync(FileAccessMode.Read);
var stream = randStream.AsStream();
var ms = new MemoryStream();
stream.CopyTo(ms);
InMemoryRandomAccessStream msras = new InMemoryRandomAccessStream();
DataWriter dw = new DataWriter(msras);
dw.WriteBytes(ms.ToArray());
await dw.StoreAsync();
var inputStream= msras.GetInputStreamAt(0);
return inputStream;
I am working on Asp.Net MVC application with Azure. When I upload the PDF document to Azure blob storage it will uploaded perfectly by using below code.
var filename = Document.FileName;
var contenttype = Document.ContentType;
int pdfocument = Request.ContentLength;
//uploading document in to azure blob
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount(FromConfigurationSetting("Connection"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("containername");
container.CreateIfNotExists();
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
container.SetPermissions(permissions);
string uniqueBlobName = string.Format(filename );
CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
blob.Properties.ContentType = ;
blob.UploadFromStream(Request.InputStream);
after uploading the document to blob trying to to read the pdf document getting an error "PDF header signature not found." that erorr code is
byte[] pdf = new byte[pdfocument];
HttpContext.Request.InputStream.Read(pdf, 0, pdfocument);
PdfReader pdfReader = new PdfReader(pdf); //error getting here
and one more thing I forgot i.e if we comment the above code(uploading document in to Azure blob) then am not getting that error.
In your combined use case you try to read Request.InputStream twice, once during upload and once later when trying to read it into your byte[] pdf --- when you read it first, you read it until its end, so the second read most likely did not get any data at all.
As you anyways intend to read the PDF into memory (the afore mentioned byte[] pdf), you could in your combined use case
first read the data into that array
int pdfocument = Request.ContentLength;
byte[] pdf = new byte[pdfocument];
HttpContext.Request.InputStream.Read(pdf, 0, pdfocument);
then upload that array using CloudBlob.UploadByteArray
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount(FromConfigurationSetting("Connection"));
[...]
CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
blob.Properties.ContentType = ; // <--- something missing in your code...
blob.UploadByteArray(pdf); // <--- upload byte[] instead of stream
and then feed your PDF reader
PdfReader pdfReader = new PdfReader(pdf);
This way you read the stream only once, and a byte[] should be re-usable...