Glide loading two images - android-glide

I have the following code which uses a URL to load an image into my layout's ImageView with ID image with glide:
String imageURL = "https://example.com/image.jpg"
Glide.with(mContext)
.load(imageURL)
.apply(requestOptions)
.into(imageTypeViewHolder.image);
However, my layout file also has another ImageView called image2. So far, I am achieving this with:
String imageURL = "https://example.com/image.jpg"
String image2URL = "https://example.com/image2.jpg"
Glide.with(mContext)
.load(imageURL)
.apply(requestOptions)
.into(imageTypeViewHolder.image);
Glide.with(mContext)
.load(image2URL)
.apply(requestOptions)
.into(imageTypeViewHolder.image2);
Is this the correct way to go about it, or can this be simplified into a single Glide.with?

Related

Starting with an InputStream, use PDFBox to add a text image to the PDF and finish with the original InputStream variable

I'm having some trouble understanding how PDFBox works so I'm hoping someone can help me out here. Here is my code:
InputStream content=null;
try{
content = document.getImageStream(1);
//Add image of word "Approved" at specific x and y coordinate in PDF
//Do more stuff with InputStream content
I already have a bunch of code below that uses that InputStream so what I would like to do is use PDFBox to "update" the PDF that the InputStream holds by adding a textbox at a given x and y coordinate and then still have the same InputStream at the end so I can continue doing stuff with it.
All I know so far is to create a PDDocument from the InputStream like this:
PDDocument pddocument = PDDocument.load(content);
Thank you for the help!

How to save image from rich text editor

I have a form including rich text editor in it.
While with only content in richtext editor I don't get any problem in saving it in database.
But when I attach an image in it, It always pokes me with this error-
Invalid URI: The Uri string is too long.
Yes the URI is absolutely so long, But why don't this form saves it even if I had given datatype to nvarchar(MAX) to be saved.
See in pictures-
and URI of this image -
While model type has nvarchar(MAX) datatype for this rich text editor.
I am performing simple save function and rendering rich text editor's values by
#Html.Raw() helper.
For this editor's rendering I am doing this on client side-
#Html.Raw(Model.businessDetails)
Model-
public string businessDetails{get;set;}
Why SQL SERVER doesn't save this long uri? What went wrong in my form submission?
first thing first,
you should be doing this as a POST request not as a GET!
after that you have two options
1)
set an attribute so it will allow HTML in the string and it will store the image as base64 in the html and you won't have to worry about storing it anywhere.
[AllowHtml]
public string businessDetails{ get; set; }
2)
grab the src of the image
remove the data:image/png;base64, from it
decode the result with base64 converter , the resulting is binary result
byte[] imageArr ;
//set your imageArr here---
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.CreateOptions = BitmapCreateOptions.None;
bi.CacheOption = BitmapCacheOption.Default;
bi.StreamSource = new MemoryStream(imageArr);
bi.EndInit();
Image img = new Image(); //Image control of wpf
img.Source = bi;
save image to destination. img.Save("path",ImageFormat.Jpeg)
replace the src of that image with an actual URL

Dynamics AX CompanyImage to Image File

I need to export the images stored in CompanyImage table to a image files.
How can I do it?
Reading the table I obtain a Bitmap field but how to know the type of image to build the correct extension and save it to file?
Finally I found the solution.
To export the image from CompanyImage:
// Grant clrinterop permission.
new InteropPermission(InteropKind::ClrInterop).assert();
image = new Image();
image.setData(companyImage.Image);
result = image.saveImage(#"c:\test.jpg",3);
CodeAccessPermission::revertAssert();
To know the original type:
image.saveType();
The above code wouldn't work right away. Here's the code that would run:
bindata bin = new bindata();
str content;
container image;
CompanyImage companyImage;
;
select companyImage;
image = companyImage.Image;
bin.setData(image);
content=bin.base64Encode();
AifUtil::saveBase64ToFile("c:\\temp\\test.tif", content);

ASP.NET C# Handling an Image

Similar to one of my other questions, but I need clarification.
I have a web application where multiple users will be on at the same time. In the app, an image, which is in one of the app folders, will be drawn on like below, saved, and then added to the image control on the page.
Bitmap image = new Bitmap(Server.MapPath("~") + "/Assets/img/timegrid.jpg");
Graphics graphics = Graphics.FromImage(image);
Pen p = new Pen(Color.Blue, 5);
//draw on image
graphics.DrawLine(p, aPoint, bPoint);
//save new image
image.Save(Server.MapPath("~") + "/Assets/img/newtimegrid.jpg");
imgGrid.ImageUrl = "~/Assets/img/newtimegrid.jpg";
Each user's new image will look different. However, I'm worried that User A will see User B's newtimegrid.jpg instead of his own since every user is saving to the same filename. I've heard of using a generic Image Handler and I've read some of the solutions here, but I still don't understand how to use it, or how to call it if I made one, or if this is even a solution to my problem. Any help would be appreciated.
I would suggest you to keep userID in the session and use this id in the path to uniquely identifying the path of image for each user image path.
You can first check if path already exists for user.
string strDirPath = Server.MapPath("~") + "/Assets/img/ + Session["UserID"].ToString();
if(Directory.Exists(strDirPath))
{
Bitmap image = new Bitmap(strDirPath + "\\" + timegrid.jpg");
//your code here
}
else
{
DirectoryInfo CreateDirectory(strDirPath);
Bitmap image = new Bitmap(strDirPath + "\\" + timegrid.jpg");
//your code here
}

What's the best way to show a random image in ASP.NET?

What I am talking about is like this website :
http://www.ernesthemingwaycollection.com
It has a static wallpaper and a set of images that change from page to page, I want to implement a similar way of displaying random images from a set of images using ASP.NET.
EDIT : I want the image to stay the same in a session, and change from a session to another.
The site you mentioned is not using a random set of images. They are coded into the html side of the aspx page.
You could place an asp Image control on your page. Then on the page's Page_Load function set the image to a random picture of your set.
protected void Page_Load(object sender, EventArgs e)
{
this.Image1.ImageUrl = "~/images/random3.jpg";
}
You have different options on where to store the image set data. You could use a database and store the urls in a table. This would allow to use the built-in Random function found in SQL. Or you can save a XML file to the server, load that then use the Random .Net class to pick one of your xml nodes.
Personally i would recommend the Database solution.
EDIT: Because the server session is destroyed after 20mins you may want to look at using cookies so you can see the last random image they saw.
If you just want to rotate a set number of images you could use the ASP.NET AdRotator control (at last, a use for it!).
If you want to do something fancier, considering using a jQuery slideshow such jQuery Cycle Plugin. There is also a slideshow control in the AjaxControlToolkit, which is easy to integrate.
string imageDir = "/images/banner/";
public static string chooseImage(string imageDir)
{
string[] dirs = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/images/" + imageDir + "/"), "*.*");
Random RandString = new Random();
string fileFullPath = dirs[RandString.Next(0, dirs.Length)];
// Do not show Thumbs.db ---
string fileName = string.Empty;
do
{
fileName = System.IO.Path.GetFileName(fileFullPath);
} while (fileName.Contains(".db"));
string imgPath = "/images/" + imageDir + "/" + fileName;
return imgPath;
}
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}

Resources