How can I get the image bitmap from cache in glide just like universal image loader?
Here is an Example. In universal image loader we can do this.
String mCache=MemoryCacheUtil.generateKey(uri,getImageSize(imageView));
return mImageLoader.getMemoryCache().get(mCache);
Related
I have been trying to make my image and text to scale when the forms appears, but i still cannot get the effect.
I have a "GetStarted" process with 4-5 pages that is launched when the app starts.
Each page has a Image in the middle
Title-Description after image
What Have I done.
I have given an "x:Name" to the svgcachedImage - labelTitle and LabelDescription
In the constructor of my page I have used the scale method to create the effect
Didnt work
What I am trying to create
If you go to this link https://www.syncfusion.com/blogs/post/create-a-wizard-view-in-xamarin-forms.aspx at the bottom there is gif that shows the scaling.(I have not got syncfusion)
Any suggestion on how to scale an image when loading a page?
The scarling is the simple animations in Xamarin.Forms.
You could use the ScaleTo method to animate the Scale property of an Image or Label.
await svgcachedImage.ScaleTo(2, 2000);
await svgcachedLabel.ScaleTo(2, 2000);
This code animates the Image instance by scaling up to twice its size over 2 seconds (2000 milliseconds).
Or you could use the RelScaleTo method to do the relative scaling of an Image.
await svgcachedImage.RelScaleTo(2, 2000);
For more details, you could check the MS docs: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/simple#canceling-animations
You could downlaod the source file from the NuGet for reference. https://learn.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/userinterface-animation-basic/
you can use the animation
Task.WhenAll(
await image.ScaleTo(1.5,5000);
await text.SacleTo(1.5,5000);
)
As you know you can animation the obj at the same time. not one after one
so you can use Task.WhenAll();
then you can use the code in
protected override async void OnAppearing(){}
I have an Image file that i create during runtime.
I want to set it as backgroundImage of a ContentPage (in android project)
I tried to set the path of the file to the BackgroundImage property but it doesn't work.
Is there a way to do it ?
I can't put it as resource since I create it at runtime
Put your page into Grid which first element is an Image, then set that image Source to your stream like:
Image bgImage = new Image
{
Source = ImageSource.FromStream(() => { return new MemoryStream(buffer); });
}
Grid mainGrid = new Grid
{
Children = {bgImage,yourContent}
};
yourPage.Content= mainGrid;
I think that documentation is out of date. Becuase target Android has more than one resources.
as
/drawable-hdpi
/drawable-xhdpi
etc.
So you should add your images for all folders because it will work device. It Works.
*but I think that main issue on Xamarin.Forms
Becase drawable folder have to default images source when system couldn't find special resolution must select from default folder... *
I am populating a QVariantMap with JSON data which I'm getting from a web service. This data contains, among other things, URL for images. Now I want to use these images as ImagePaint in my qml file, but in Blackberry OS 10.1, setting the imageSource to the URL doesn't load the image.
What is the way around this problem? Thanks.
You can use a WebView to display your image like the following:
Webview {
url: "link/to/your/image"
}
I can;t figure out how to do this. Someone selects and image after calling FileReference.browse(). I take that image and make a thumbnail in flash.
Then I upload that image like so:
var newFileReq:URLRequest = new URLRequest(FILE_UPLOAD_TEMP);
newFileReq.contentType = "application/octet-stream";
var fileReqVars:URLVariables = new URLVariables();
fileReqVars.image = myThumbImage;
fileReqVars.folder = "Thumbs";
newFileReq.data = fileReqVars;
newFileReq.method = URLRequestMethod.POST;
//upload the first image
fileRef.addEventListener(Event.COMPLETE, onFirstFileUp);
fileRef.upload(newFileReq, "Filedata");
All this does it upload the original image. How do I change the fileRef to upload the new thumb? I have traced out the size of the "myThumbImage" and it is correct. I have placed it visually on the stage after creating the thumb, and it seems like it works. But when I upload it to an aspx page (that basically just throws it into a folder), it uploads the original larger image.
It won't work this way. FileReference.upload can only upload the file you opened, you can not override the image for security reasons.
What you should do to achieve this is encode the thumbnail data properly using Base64 (and use something like as3corelib to encode it to jpeg or png first if your thumb is just a bare bitmap data), and then use URLLoader to post the thumb to the server.
I have a method that returns an Image.
How can I assign that Image to my ImageButton control so it has that image set?
Since you're dealing with HTML, you'll need to save the Image to a file, then use that file in the ImageButton's ImageUrl property.
I believe an ImageButton takes the path to an Image, not an actualy Image object, as the browser renders it a an tag.
What you could do is save thr image to disk, return the path to the image form your method and then have
<asp:ImgageButton id="imgButton1" runat="server" imageUrl="<%= GetImageUrl()>" />
The above syntax is not exact, it might be "<% Response.Write(GetImageUrl())>" but you get the picture
If this method returns an Image object, you will need to save out the image to a physical location on your webserver (somewhere like Server.MapPath("~/images/")). Then you will need to set the ImageUrl property of the ImageButton control to this location.
If this method returns a relative path to the image file, simply set the ImageUrl property of the ImageButton to the path returned by the method.
In short, you can't. Well not directly anyway.
You will have to write your image to file and point the image button at your image file
or you can have a web page that returns the image in the response and use that as your ImageUrl
The reason for this is that your ImageButton just renders to HTML which has no support for attaching images ATM.
You can try the following approach:
1) Firstly, get the binary data from the image:
public byte[] ImageToByteArray(System.Drawing.Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
2) Secondary use Inline Images with Data URLs idea:
Inline images use the data URI scheme
to embed images directly within web
pages. As defined by RFC 2397, data
URIs are designed to embed small data
items as "immediate" data, as if they
were referenced externally. Using
inline images saves HTTP requests over
externally referenced objects.
System.Drawing.Image image = GetImageFromSomewhere(...);
byte[] imageData = ImageToByteArray(image);
string imageBase64 = Convert.ToBase64String(imageData);
string imageSrc = string.Format("data:image/gif;base64,{0}", imageBase64);
imgButton.Src = imageSrc;
But unfortunately, this won't work for IE5-7 (should work in IE8).