I use AS3 flash. Can someone help me? I want that if you press the save_image button, then it saves "guy" movieclip as png. But It's not work:
import com.adobe.images.JPGEncoder;
import com.adobe.images.PNGEncoder
save_image.addEventListener(MouseEvent.CLICK, save_image_function);
function save_image_function(event:MouseEvent):void
{
var bmd:BitmapData = new BitmapData(50,50);
bmd.draw(guy);
var encorder:PNGEncoder = new PNGEncoder();
var bytes:ByteArray = encorder.encode(bmd);
var file:FileReference = new FileReference();
file.save( bytes, "Image.png" );
}
Can someone help me? The error code is this:
ReferenceError: Error #1069: Property encode not found on com.adobe.images.PNGEncoder and there is no default value.
at pr2sets_fla::MainTimeline/save_image_function()
The encode method is static, you need to call it this way.
var bytes:ByteArray = PNGEncoder.encode( bmd );
Related
I am loading an image from the camera into an Image control. That works beautifully as shown below.
var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions() { });
if (photo != null)
PhotoImageRear.Source = ImageSource.FromStream(() => { return photo.GetStream(); });
I sometime later need to take the images loaded into that PhotoImageRear control and convert it to a base64 string in order to post it to an API.
What would be the most efficient way of achieving that.
Thanks in advance for your help
From shared code ,once you get the photo, you can use the following code to convert to Base64 .
var stream = photo.GetStream();
var bytes = new byte [stream.Length];
await stream.ReadAsync(bytes, 0, (int)stream.Length);
string base64 = System.Convert.ToBase64String(bytes);
I wrote a script to add an image from my Google Drive and some custom text to a Google Doc. (I got the image insertion code from here).
The resulting document is created ok, but my image is added twice for some reason...
function myFunction(e) {
var doc = DocumentApp.create('fileTest');
var body = doc.getBody();
var matchedFiles = DriveApp.getFilesByName('logo.png');
if (matchedFiles.hasNext()) {
var image = matchedFiles.next().getBlob();
var positionedImage = body.getParagraphs()[0].addPositionedImage(image);
}
body.appendParagraph('Test line of text for testing');
doc.saveAndClose();
}
However, if I get rid of my appendParagraph code (body.appendParagraph(t1);) I only get one image (but obviously without the paragraph of text I want)
What's going on here? And how do I add both one picture and my paragraph of text?
I have not even the slightest clue as to why, but I found a way to make this work.
Switching the order of my code seemed to do the trick. I simply moved the image-insertion code to the end (i.e., after the appendParagraph code), and it worked fine. No duplicate image!
function myFunction(e) {
var doc = DocumentApp.create('fileTest');
var body = doc.getBody();
body.appendParagraph('Test line of text for testing');
var matchedFiles = DriveApp.getFilesByName('logo.png');
if (matchedFiles.hasNext()) {
var image = matchedFiles.next().getBlob();
var positionedImage = body.getParagraphs()[0].addPositionedImage(image);
}
doc.saveAndClose();
}
Could someone please point me to a tutorial/page that will explain how to view a binary image from a database (or if its simple please tell me)?
I'm using cshtml and can query the database but the image part has got me stumped.
Thank you
I found a way and hope this helps anyone with the same question.
I created a querySingle to return my image binary data in 'var=file'.
I then created the following string variables:
string imageBase64 = Convert.ToBase64String(file.FileContent);
string imageSrc = string.Format("data:image/png;base64,{0}", imageBase64);
*FileContent being my binary data.
And finally created the img:
<img src="#imageSrc" alt="#file.FileName" />
Please up-mark if you find this helpful.
I use this in foto.cshtml Razor
I have fotos and thumbnails in he database. This is for the thumbnails.
#{
// Cache the image for a minute
Response.OutputCache(60);
var fotoId = UrlData[0].AsInt();
var db = Database.Open("albums");
var foto = db.QuerySingle("SELECT * FROM Fotos WHERE Id = #0", fotoId);
if (foto == null){
Response.Redirect("~/");
}
new WebImage(foto.Mini).Write();
//Geef maximale breedte en hoogte aan
//var width = 120;
//var height = 60;
//var image = new WebImage(foto.Mini);
//image.Write();//Or image.Resize(width, height).Write();
}
I am using RadMosaicTile in my windows store application. I want to bind images with it.
I tried this
RadMosaicHubTile tile = new RadMosaicHubTile();
tile.ImageSources.Add("Image1.jpg");
tile.ImageSources.Add("Image2.jpg");
but it is not working. images are not binded.
Can anyone help me?
Thanks.
The have this code sample on the telerik forum - does this work for you?
Collection<object> imageSources = new Collection<object>();
ImageSource image = GetImageFromWeb();
imageSources.Add(image);
RadMosaicHubTile hubTile = new RadMosaicHubTile();
hubTile.CreateImageSource = (source) =>
{
return (ImageSource)source;
};
hubTile.ImageSources = imageSources;
i want to load image from remote url and synchronicity and change it width and height.
i am using the folowwing code, but it want let me change the width and highet, i think i needto convert the loader to a Bitmap object.
how can i do that, thank you very much.
var imageURLRequest:URLRequest = new URLRequest(pic);
var myImageLoader:Loader = new Loader();
myImageLoader.load(imageURLRequest);
var urlRequest:URLRequest = new URLRequest(pic);
var loader:Loader = new Loader();
loader.load(urlRequest);
trace(loader.width); // return 0
loader.width =100; //dosent work
allMC[i].img.addChild(loader);
To access what the loader loaded, use loader.content reference. If you are loading an image, you can retrieve its raw data via (loader.content as Bitmap).bitmapData, of course first check if it's so via if (loader.content is Bitmap). Also, you need to do all of this after your loader will finish loading, it'll send an event indicating this.
...
loader.load(urlRequest);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
...
private function loaderComplete(e:Event):void {
// now your image is fully loaded
trace(loader.content.width);
// etc etc, whatever you need to do with your image prior to
// addressing it from elsewhere.
}