RSS feed in flex mobile project - apache-flex

I am working on accessing RSS feed using Flex mobile project. But i dont get image in that RSS feed,how to get image from RSS feed in Flex mobile project and how to convert an image into byte stream in Flex mobile project

But i dont get image in that RSS feed
RSS is xml. You need to looking for image elements, get url and load images separately
http://www.w3schools.com/rss/rss_tag_image.asp
how to convert an image into byte stream
In order to load image as ByteArray you need to use URLLoader for image loading:
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, loader_completeHandler);
function loader_completeHandler(event:Event):void
{
//here you can get loaded image as ByteArray
var imageData:ByteArray = loader.data;
}
If after this you need to show image in display list then:
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, loader_completeHandler);
var imageBytesLoader:Loader = new Loader();
imageBytesLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageBytesLoader_completeHandler);
function loader_completeHandler(event:Event):void
{
//here you can get loaded image as ByteArray
var imageData:ByteArray = loader.data;
imageBytesLoader.loadBytes(imageData);
}
function imageBytesLoader_completeHandler(event:Event):void
{
//here you can get loaded image as Bitmap
var bitmap:Bitmap = Bitmap(imageBytesLoader.content);
}

Related

Local Image not displayed in Skia.WPF Uno Platform project

I save images relative to the workingdirectory and then want to display them in a uno Skia.WPF app.
However they never appear.
This is how I create the ImageSource:
public static async Task<ImageSource> GenerateSource()
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.FileTypeFilter.Add(".png");
var pickerResult = await picker.PickSingleFileAsync("tileset");
if (pickerResult is null)
return null;
using var stream = await pickerResult.OpenReadAsync();
string imagePath = Path.GetFullPath(Path.Combine("cache", "image.png"));
Directory.CreateDirectory(Path.GetDirectoryName(imagePath));
using (var bitmapImageStream = File.Open(imagePath,
FileMode.Create,
FileAccess.Write,
FileShare.None))
{
await stream.AsStreamForRead().CopyToAsync(bitmapImageStream);
bitmapImageStream.Flush(true);
}
var imgSrc = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
imgSrc.UriSource = new Uri($"file://{imagePath}");
var width = imgSrc.PixelHeight;
return imgSrc;
}
But when I use the path directly in the Xaml it also not working.
<Image Source="file://cache/image.png" Width="32" Height="32" />
Using an image from the Internet using an http url works.
Sample Repo
file: URIs are currently not supported in Uno, however, you can still show local images by copying to the appropriate folder using ms-appdata scheme. If you copy the file into ApplicationData.Current.TemporaryFolder, you will the be able to reference that path by ms-appdata:///temp/{imageName} URI.

How to set the stream as ImageSource in Xamarin UWP?

I am having the stream and I trying to set the Image Source as a stream. My code is
var contentPage = new ContentPage();
var image = new Image();
Stream stream = args.Stream;
stream.Position = 0;
image.Source = ImageSource.FromStream(() => stream);
contentPage.Content = image;
Navigation.PushModalAsync(contentPage);
Image rendered in android and iOS but it not worked in UWP. Please suggest me, how to render the image via stream.
Thanks,
Santhiya A
I experienced this also in UWP and have found that you should do this work in the OnAppearing() method of the contentPage.

Pass generated barcode to an html tag

I've got my function:
protected void Button1_Click(object sender, EventArgs e)
{
var barcodeWriter = new BarcodeWriter();
var encOptions = new ZXing.Common.EncodingOptions() { Width = 200, Height = 200, Margin = 0 };
barcodeWriter.Options = encOptions;
barcodeWriter.Format = BarcodeFormat.CODE_128;
var resultBitmap = new Bitmap(barcodeWriter.Write("hello"));
resultBitmap.Save(#"C:\Users\lrusin\Documents\Visual Studio 2015\Projects\prova_eti\asd.bmp");
}
that generates a barcode image and by now saves it to some folder in my file system.
I was wondering if there is a way to put the generated image (not the one saved in C:\...) into an HTML container like a div or a list.
In my example i will have a button that when is clicked loads into a div the image generated by the code written above.
The easiest way would be to load the generated bitmap into a MemoryStream to get the Byte Array. Then convert the array to Base64 for displaying in HTML. In the snippet below I generate the bitmap for demo purposes.
//create a new empty bitmap
Bitmap resultBitmap = new Bitmap(100, 100);
//fill the bitmap with a red cirle
using (Graphics g = Graphics.FromImage(resultBitmap))
{
g.FillEllipse(Brushes.Red, 10, 10, 80, 80);
}
//no explanation needed here
string base64Image = string.Empty;
//load the bitmap into the memorystream
using (MemoryStream ms = new MemoryStream())
{
resultBitmap.Save(ms, ImageFormat.Bmp);
//get the byte array from the stream and convert to Base64
base64Image = Convert.ToBase64String(ms.ToArray());
}
//display the result
Image1.ImageUrl = "data:image/jpeg;base64," + base64Image;
However it could be that BarcodeWriter has some build-in functions to do this directly...

How to convert Image to ByteArray in Flex 4

I would like to write an image in pdf. I use AlivePDF and the method is pdf.addImageStream(image,...). The image is a ByteAray and I do not know how to convert my Image object in an ByteArray. I would appreciate if you can give me a suggestion.
1.load the image:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, beginDraw);
loader.load(new URLRequest(imgURL));
2.get the bitmapData and convert to ByteArray:
private function beginDraw(event:Event):void{
var bitmap:Bitmap = loader.content as Bitmap;
var rect:Rectangle = new Rectangle(0,0,bitmap.width. bitmap.height);
var result:ByteArray = bitmap.bitmapData.getPixels(rect);
}

PDF export to local using AlivePDF with flex

I need to export charts and data tables to pdf file in flex application.
For this we can user AlivePDF but i need to export to local not server.
Can we export to local system prompting user to select the location to export?
Thanks in advance.
Since FP10 the FileReference Class should support this via the save() function. The code to do this in Flash Player 10 or better is shown below:
var bytes:ByteArray = pdf.save(Method.LOCAL);
var file:FileReference = new FileReference();
file.save(bytes, "myPDF.pdf");
Try this
var pdfFile:PDF = new PDF();
var pdfByteArray:ByteArray = new ByteArray ();
pdfByteArray = pdfFile.save(Method.LOCAL);
With the latest version of AlivePDF (0.1.5 RC), you can do this:
var element:IBitmapDrawable; // Chart to export
var pdf:PDF = new UnicodePDF();
pdf.addPage();
var bitmapData:BitmapData = new BitmapData(element.width, element.height, false, 0xffffff);
try{
bitmapData.draw(element as IBitmapDrawable);
}catch(e:*)
{
throw new Error("bitmap draw failed");
}
var jpegencoder:JPEGEncoder = new JPEGEncoder(100);
var byteArray:ByteArray = jpegencoder.encode(bitmapData);
pdf.addImageStream(byteArray);
var file : FileReference = new FileReference()
file.save(pdf.save(Method.LOCAL),"my.pdf");

Resources