I have a React object state with google info(name, email, & profilepic). But when I use the "profilepic" in an img src, the image doesn't show cos the link to the image has been converted to a string somehow in the object.
Related
I'm using the Image class from the package image. I have to download a image from internet and save it in my local storage. Then modify this image and save the changes. I have done the first 2 steps, but when i'm saving the file, this is corrupted and the Image Viewer dont recognizit as a image file. This is the code where the image is saved after the changes.
var response = await client.get(urlToImage);
var img = await File('./network_image.jpg').writeAsBytes(response.bodyBytes);
Image image = decodeImage(img.readAsBytesSync())
var f = await File('./image.jpg').writeAsBytes(image.getBytes()); // this doesnt work
// var f = await File('./image.jpg').writeAsBytes(image.data); // this doesnt work
The File.writeAsBytes expects a List<int> bytes, and the Image.data and Image.getBytes() returns Uint32Listand Uint8List respectively.
I'm not using Flutter, only dart for a command line program.
The image object stores the image data in an unencoded format. Remember you decoded it with decodeImage. It stores the raw colors of the image. You need to re encode the image data or your image viewer needs to handle whatever image format of data getBytes returns.
The easier solution is probably to re encode. You seem to want a JpegEncoder.
var f = await File('./image.jpg').writeAsBytes(JpegEncoder().encodeImage(image));
<img src="data:image/jpeg;base64,${createLink(controller:'Photo', action:'showEncoded', id:"${PhotoInstance.id}")}" width='300' />
I'm just starting out with grails and this is my first question on Stackoverflow. My controller returns an image encoded in base64 but the above code in gsp complains that there are errors in the image.
The domain class Photo stores the JPEG image in
byte[] imagePhoto
and saved as binary
The showEncoded method is defined in my controller and encodes imagePhoto as a base64 string, returning it to the requested GSP.
def showEncoded(Photo DBPhotoInstance) {
String encoded = DBPhotoInstance.imagePhoto.encodeBase64().toString()
response.outputStream << encoded
response.outputStream.flush()
}
I've also checked to make sure the image is a JPEG file.
Any help, direction or guidance thanks!
So I'm trying to add Images to my Grid using an IndexedContainer with the following code:
//picture
String imgURL = (String)ds.child(PHOTO).getValue();//gets the image URL from the DB
System.out.println(imgURL);
ExternalResource picture = new ExternalResource(imgURL);
System.out.println(picture.getURL());
Image image = new Image(PICTURE, picture);
image.setHeight("5px");
item.getItemProperty(PICTURE).setValue(image);
Instead of getting the picture, I'm getting the toString() of the Image object. Both println print the correct URL. Also note that this works with Table but not with Grid. Any idea why?
If you want to display an image in a Vaadin Grid column, you need to set the ImageRenderer, see here paragraph ImageRenderer.
Example: Define your column like
grid.addColumn("picture", Resource.class).setRenderer(new ImageRenderer());
then add a resource as column value
grid.addRow(new ThemeResource("img/copernicus-128px.jpg"), "Nicolaus Copernicus", 1543);
In your case it is the ExternalResource. No need for the Image component.
I want to loop through this class and display in a table. what is the easiest way to display the image?
class Crop {
static hasMany = [diseases: Disease]
int id
String commonName
String scientificName
byte[] image
}
static mapping = {
table: 'Crops'
commonName length : 100
scientificName length: 100
image sqlType: "longblob"
}
You can if you don't mind the lack of browser compatablity use data: uri encoding:
<img src="data:image/png;base64,${crop.image.encodeBase64()}"/>
see the Wikipedia page on Data URI encoding scheme
#Xeon suggest the more conventional approach, ie create a controller that returns an image response with the correct mime type and the byte array as the body.
You could do the same thing as in this answer.
Or you can create controller which provide image data stream from your entity. On GSP you could write:
<img src="${request.contextPath}/imageController/actionName?id=${entity.id}" ...
But this is unusual - storing images in entities as byte[]. You should consider changing it to String which would indicate a path/filename of the image.
Can someone post an example of how to use the camera, capture the image, preview the image in an image view, compress the image in jpg and upload the bytes to a remote server? The closest I have been able to find is below. We have the camera, and image capture but we need to know how to preview, compress/resize jpg to 640/480px and around 120kb size then upload bytes to a remote server. Thanks to all of you for your help.
http://android-coding.blogspot.com/2010/12/intent-of-mediastoreactionimagecapture.html
Looking at your code there are some things i notice to be wrong:
-[ for the camera functionality ]-
Don't create a file yourself. This is not necessary. Use the ContentResolver.Insert function to give you back a file URI that will contain the picture, just like done here and also take over the isMounted if you want to check if there is external memory present.
You are checking if there's data and then checking if there is a thumbnail. If there's no thumbnail you'll get the full image. That doesn't make sense unless you want to make a thumb of the full version if the thumb is not given back?? Don't you just want to grab the full version or both but not this OR that?
You are retrieving a string value variable to get the URI to the full image? Just save the uri you get from the code in my first point as a property (let's say "myPhotoURI" in the activity class. In the OnActivityResult function that handles your camera intent result just recall that URI and use it as following (Yes, you're seeing it right; i'm not even using the data intent for this just the remembered uri):
Bitmap imageFromCam = MediaStore.Images.Media.GetBitmap(this.ContentResolver, Android.Net.Uri.Parse(myPhotoURI));
To grab an image from the gallery just use the SelectImageFromStorage() function from this question's answer and retrieve the URI of the chosen image in the OnActivityResult check just use:
Android.Net.Uri selectedImageUri = data.ToURI();
That's what worked like a charm for me.
-[sending the data to a webservice ]-
Assuming you're using a WCF or webservice that'll want to receive the image data as a byte array; the approved answer to this question gives a nice example of how to convert your image to an byte array (which is what a WCF webservice wants, anyway)
I think that these directions will get you going.
here is the closest example to date... this brings back Null data when the extra output is used. Still trying to get access to the full image/photo and not a thumbnail.
private void saveFullImage() {
Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
string file = System.IO.Path.Combine(Android.OS.Environment.DirectoryDcim.ToString(), "test.jpg");
var outputFileUri = Android.Net.Uri.Parse(file);
intent.PutExtra(Android.Provider.MediaStore.ExtraOutput, outputFileUri);
StartActivityForResult(intent, TAKE_PICTURE);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PICTURE)
{
Uri imageUri = null;
// Check if the result includes a thumbnail Bitmap
if (data != null)
{
if (data.HasExtra("data"))
{
var thumbnail = data.GetParcelableArrayExtra("data");
// TODO Do something with the thumbnail
}
}
else
{
var outputFileUri = data.GetParcelableArrayExtra("outputFileuri");
// TODO Do something with the full image stored
// in outputFileUri
}
}
}