In other platforms i could just use something like [Embed(source="logo.gif")] or #:bitmap, but it seems there is no option for that for Windows/Other Cpp platforms.
I tried to use the EmbedAssets lib but it's outdated.
I also tried using the nmml file resource tag. With this i could get the image as haxe.sys.io.Bytes, but to use i need to convert haxe.sys.io.Bytes to nme.utils.ByteArray. I have not found a way to do this.
So, what can i do to embed images on a haxe/nme project when deploying to Windows?
In addition to openfl.Assets, OpenFL supports #:bitmap, #:sound, #:font and #:file embed tags.
The former requires <assets path="to/assets" /> in your project XML file, and on Windows, will copy the files alongside your executable.
The embed tags require that your asset files are in your source path based on the way they are embedded, so use <source path="to/assets" /> in the project file.
Here is an example that uses the #:bitmap tag:
package;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
#:bitmap("nme.png") class Image extends BitmapData {}
class Main extends Sprite {
public function new () {
super ();
var bitmap = new Bitmap (new Image (0, 0));
addChild (bitmap);
bitmap.x = (stage.stageWidth - bitmap.width) / 2;
bitmap.y = (stage.stageHeight - bitmap.height) / 2;
}
}
Using embed tags, the asset will be inside your executable.
With NME or OpenFL you should just be able to call Assets.getBitmapData("assets/myImg.png"); without needing to add the assets to the NMML file (though you may need to add <assets path="Assets" rename="assets"/> or rename the assets directory). You should then be able to add this bitmapData to a bitmap object on the display list.
For example:
var bd:BitmapData = Assets.getBitmapData("assets/myImg.png");
var bitmap:Bitmap = new Bitmap(bd);
addChild(bitmap);
Related
i am trying to set an image in to a razor page in MAUI Blazor.
In MAUI (only), there was the aproach, that you have a .svg image in the folder Resources/Images. MAUI then converts the .svg image in a .png image which you can use in the XAML file. like so:
Now i have the same picture in a MAUI Blazor app and i hoped that i can put my picture in the same way expect that i have to use the HTML style like so:
<img src="one_list2.png">
But this doesn't work at all. I tryed with or witout path, path with slashes, backslashes etc. nothing works.
Trying to put a .png image into the wwwroot folder works. But this isn't the goal. I found it very nice to put a svg image which is then converted into a png depending of its size. This way all pictures would be converted exactly in the perfect size you will need lossless.
Thanks
First, Add the image to Resources\Raw and set it to MauiAsset compilation type
Second, Check the project file to avoid setting the image in the other folder.
In razor component HTML:
<img src="#imageSource">
In the code part:
private string? imageSource;
protected override async Task OnInitializedAsync()
{
try
{
using var stream =
await FileSystem.OpenAppPackageFileAsync("testimage.png");
using var reader = new StreamReader(stream);
byte[] result;
using (var streamReader = new MemoryStream())
{
stream.CopyTo(streamReader);
result = streamReader.ToArray();
}
imageSource = Convert.ToBase64String(result);
imageSource = string.Format("data:image/png;base64,{0}", imageSource);
}
catch (Exception ex)
{
//error
}
}
More information you can refer to ASP.NET Core Blazor Hybrid static files.
I basically want to show an image that I have in the assets folder onto the canvas.
import 'package:flutter/material.dart' as ui;
...
ui.Image img = ui.Image.asset("images/some_image.png");
ui.paintImage(canvas: canvas, image: img);
And have got the following error message when I tried to assign img to paintImage's image.
The argument type 'Image (C:\ABC\flutter\packages\flutter\lib\src\widgets\image.dart)' can't be assigned to the parameter type 'Image (C:\ABC\flutter\bin\cache\pkg\sky_engine\lib\ui\painting.dart)'.
I don't really know what could go wrong, I have seen other codes that had a similar approach with ui.Image.
Please advise.
There are two classes called Image in flutter, in different packages.
There's the Widget, which behaves like a widget and can be instantiated from an asset, from memory or from the network through its named constructors.
There's also the ui package Image which is used when painting at a lower level, for example in a CustomPainter. Since this version is in the ui package it's normally imported with the ui prefix like this:
import 'dart:ui' as ui;
Don't import material as ui! That will lead to a lot of confusion.
To make a widget, use the Image.asset constructor, passing the asset name.
To make a ui.Image from an asset use this snippet:
Future<ui.Image> load(String asset) async {
ByteData data = await rootBundle.load(asset);
ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List());
ui.FrameInfo fi = await codec.getNextFrame();
return fi.image;
}
I m trying to upload and show images.
I get the file, write it to docroot of glassfish application server, then
Image image = new Image("myimage","images/task.gif");
But i get <img wicket:id="myimage" src="resources/wickcat.MyPage/images/task.gif" />
Is there any way that wicket wont rewrite my src path? Even when i use an http://.... starting src, it writes resources/wickcat.MyPage/http://... which makes no sense at all.
I just need it to write "images/task.gif".
Any ideas?
There is two ways to do this.
Use <img src="images/task.gif" />. This is if you don't need reference to the component in the class.
Use ContextImage image = new ContextImage("myimage", "images/task.gif");. If you use the ContextImage component, the source will be relative to the Context root, you can even input a model as the relative path to the image.
The Image class assumes the image is a resource located in the classpath.
You could use a WebMarkupContainer with a SimpleAttributeModifier:
WebMarkupContainer img = new WebMarkupContainer("myimage")
.add(new SimpleAttributeModifier("src", "/images/task.gif"));
It will output the string as is, so you have complete control.
If it is used several times across the application, I'd recommend you to create a component encapsulating this behavior. Something like
public class MyImage extends WebMarkupContainer {
public MyImage(String id, String path) {
add(new SimpleAttributeModifier("src", path));
}
}
I am trying to embed an animated GIF image into a wxWidgets C++ program. I am able to load the image from file and display it like so:
wxAnimationCtrl *an = new wxAnimationCtrl(this, wxID_ANY, wxAnimation(wxT("image.gif"), wxANIMATION_TYPE_ANY), wxPoint(150,0));
an->Play();
But I would rather have the GIF image in my resource.rc file, so that it is compiled into the executable. How would I do this?
You can try to use wxMSWResources or wxLoadUserResource function, load GIF resource to memory, then obtain wxMemoryInputStream and then use wxAnimation::Load() and pass that input stream to that function
m_ani = new wxAnimationCtrl();
const void* data = NULL;
size_t outLen = 0;
// load the icon directory resource
if ( !wxLoadUserResource(&data, &outLen, "ID_WAIT", RT_RCDATA) )
{
wxLogError(_("Failed to load icons from resource"));
}
else
{
wxMemoryInputStream stream(data, outLen);
if (m_ani->Load(stream)) m_ani->Play();
}
Is there a way to add an image in my main app, so that it is on top off a popWindow? The equivalent of the Z-index should render it on top.
So, I've got a popWindow and I want to add an image on top of the popWindow.
If in my main app I use:
var floatingImage:Image = new Image;
floatingImage.source = image_path;
floatingImage.y = 200;
floatingImage.x = 200;
addChild(floatingImage);
Then the image is on top of main App, but it is still below my popWindow.
I would add the image directly to the popWindow, but I'm using FlashEff 2, and for some reason the effect won't work if I have an image in the popUp. So, I thought that I would add the image in the main app and have it float above the popWindow.
Another possibility might be to check somehow if the popWindow is open and then add the image directly to the popWindow.
If anyone has any suggestions, I'd love to hear them.
Thank you.
-Laxmidi
Not really recommended but here is the code. This won't work well with UIComponents just DisplayObjects.
[Embed(source="assets/MyImage.png")]
private var MyImage:Class;
protected function button1_clickHandler(event:MouseEvent):void
{
var image:DisplayObject = new MyImage();
stage.addChild(image);
}