I've been developing a mobile app using React Native and deploying it onto a Samsung Galaxy S6 Edge for testing purposes via Expo. So far, everything has worked fine and all of the images I'm using have displayed correctly.
However, when I've tried to deploy it onto other devices, certain images have failed to display. On the Huawei MediaPad, the header image (encased in an <Image> tag) fails to display and on the Samsung Galaxy S8 and the OnePlus 6, the background image (encased in an <ImageBackground> tag) fails to display.
I've attempted running a compiled APK file of the app, believing that these issues could be related to streaming the images over Wi-Fi, but to no avail. Interestingly though, the background image displayed fine across all devices until I swapped it out for a new image (as the predecessor was merely a placeholder). Both images are 4K (3840 x 2160), with the only difference being the storage size of the image. As a debugging measure, I compressed the new image in Photoshop with the strongest setting but, again, to no avail.
Below is the code I am using to render the two Images (not a complete paste of course, but I'm happy to do so on request):
<ImageBackground
source={require('./../../assets/images/bg_portrait_dots.png')}
style={{width: '100%', height: '100%', position: 'absolute'}}
>
<View style={styles.parentView}>
<View style={styles.elementSpacer}>
<Image
source={require('./../../assets/images/iview_learning_logo.png')}
style={styles.headerImage}
/>
</View>
Below are the Stylesheet arguments which control the elements listed above:
parentView: {
flex: 1,
flexDirection: 'column',
padding: 30,
justifyContent: 'center',
},
headerImage: {
width: null,
resizeMode: 'contain',
height: 120,
position: 'relative',
},
elementSpacer: {
flex: 1,
},
Related
I have implemented the QuaggaJS library to scan barcodes from a mobile device in my laravel application but e.g. for my mobile phone which has multiple backcameras the chosen camera has a weird "fish eye" effect so i guess it is not the main/standard camera. The only setting i know about is to set the facingMode either 'environment' or 'user' as shown in my codesnippet below.
constraints: {
width: 640,
height: 480,
facingMode: 'environment', }
I would like to know if there is an option to specify the camera used?
Thanks in advance.
I have developed my own maptile server and I want to use it as my raster source in react-native-mapbox-gl
this is my code:
const rasterSourceProps = {
id: 'iranMap',
tileUrlTemplates: ['http://.../{z}/{x}/{y}.png'],
tileSize: 256,
};
<MapboxGL.MapView
style={styles.map}
rotateEnabled>
<MapboxGL.RasterSource {...rasterSourceProps} >
<MapboxGL.BackgroundLayer id="background" sourceLayerID="iranMap" style={{ backgroundColor:"#f2efea"} } />
<MapboxGL.RasterLayer
id="iranMapLayer"
sourceLayerID="iranMap"
minZoomLevel= {1}
maxZoomLevel= {19}
style={{rasterOpacity: 1, rasterFadeDuration: 100}}
/>
</MapboxGL.RasterSource>
<MapboxGL.Camera zoomLevel={3} centerCoordinate={coordinates} />
<MapboxGL.PointAnnotation coordinate={coordinates} id="Test" />
</MapboxGL.MapView>
I can view my map with my own tiles, but the problem is that in high zoom levels, some tiles are loaded in night mode as the picture below:
https://drive.google.com/file/d/1O_OQdMI-7SKCC3E5HSnuR_vwOzwseVOY/view?usp=sharing
any solutions?
You just need to develop the app in release version and view the map in real device! For me the problem is solved
The purpose of this question is to find the best way to display a lot of images (20 or more) from the gallery.
I need to display all the photos on the on the device. As you can see there could be a lot of images to be displayed, and when I try to display them all using different Image.file() widget, My phone (LG G2) gets slow and then the app completely crashes.
I think the Problem Is that I am Loading a lot of 4K Images (More Than 100) on a 5 years old Device. The Images actually displayed on the Screen at the same time are actually around 15, but I need to have something like a gallery, so all the images in a GridView.
So, I don't think it's the best option, maybe there is a function to downscale the image to like 100x100 px. But looking online I couldn't find anything. So, Is there a better way?
I get all the Image Paths and their folder using a Platform Channel to Android.
I get them all in a list like this:
[["Camera", "storage/emulated/0/downloads/1.png"], etc]
This is The UI I got: (Sorry For the Awful design)
There Are three Main components on the Screen, The IconButton With The Two Arrows:
The DropDownMenu and The GridView.
The IconButton requeries all the paths from android. in the List as stated above.
The DropDown Menu has a function on onChanged which creates all the Cards in the List used by gridView.
This is The Funciton:
void _onChanged(String value) {
setState(() {
_currFolder = value;
_photoCards = calculatePhotoCards();
});
}
And the calculatePhotoCards is this:
List<Widget> calculatePhotoCards() {
List<Widget> list = new List();
for (int v = 0; v < _foldersAndPaths.length; v++) {
if (_foldersAndPaths[v][0] == _currFolder) {
list.add(Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: new ClipRRect(
borderRadius: new BorderRadius.circular(8.0),
child: Image.file(
File(_foldersAndPaths[v][1]),
fit: BoxFit.cover,
),
),
),
));
}
}
print(list);
return list;
}
Where _foldersAndPaths is the List containing all the paths which their respective folders (as stated above), while _currFolder is the Selected Folder in DropDownMenu.
You need to add cacheWidth and cacheHeight
example:
Image.network(
shop.shopPic,
width: 46,
height: 46,
cacheWidth: 46,
cacheHeight: 46,
)
I decided to implement this to see if it was something to do with image sizing etc, as there have been a few questions about that in the past for remote images.
When I implemented it, I ran into the exact same problem as you. I thought that flutter did caching of images scaled to a reasonable size but that doesn't seem to be the case. It's actually loading up each image into memory, which is why you're getting a crash. It doesn't take that many images to run out of memory as by the time they're decoded into pixels they're pretty huge.
Here and here are bugs about this (I raised one myself) against flutter.
So unfortunately, I don't think there's a pure flutter way of doing this at the moment. There is a image package on pub that can scale down images but it does it directly in dart code so isn't all that performant.
Until those bugs have been fixed, you may have to look for an android-specific (and iOS-specific if you're interested in that) solution to this. That would entail using the android thumbnail creator to create a bitmap, then either saving that bitmap and passing it's URL back to flutter, or passing the bitmap's bytes directly.
Sorry I don't have a better answer than that!
I'm using CachedNetworkImage and I had an issue with loading multiple Images and the app got to over 3GB ram because of it the solution was
CachedNetworkImage(
height: height,
width: width,
memCacheHeight: height, //add this line
memCacheWidth: width, //add this line
imageUrl: imageUrl,
),
It reduced the memory usage from3GB to 60MB
I'm back with tales of frustrating adventures. This time concerning images on the android side of titanium.
Long story short, I can't get any images to show up for android whatsoever, whether it be a background image or a plain image in an imageView object.
I will provide code I'm trying and keep it extremely small and simple so that it can be easily replicated for all of our testing purposes.
The Code:
Attempt #1 programatically creating view and image:
index.js
var header = Ti.UI.createImageView({
width: 300,
image: '/images/header.png',
width: 300
});
var win = Ti.UI.createWindow({
backgroundColor: 'white',
height: Ti.UI.FILL,
title: 'test',
width: Ti.UI.FILL
});
win.add(header);
win.open();
Attempt #2 plain jane .xml and .tss styling:
index.js:
$.index.open();
index.xml:
<Alloy>
<Window class="container">
<Label id="label">Hello World!!</Label>
<ImageView id='img1'></ImageView>
</Window>
</Alloy>
index.tss:
".container": {
backgroundColor: 'white'
}
"#img1": {
width: 300,
image: '/header.png',
width: 300,
top: 0,
left: 0
}
file locations (i copied the same image to 3 different locations to try and get something):
app/assets/header.png
app/assets/android/header.png
app/assets/android/images/header.png
IMPORTANT, What I have tried:
using "/images/header.png
using "images/header.png"
using "header.png"
using "/header.png"
First thing, in the ImageView property you have mentioned the width twice, so you can remove one declaration and put the height of the image, like 300 (you can put Ti.UI.SIZE to maintain the aspect ratio)
Second, put the images inside app/asset/android/images/res-<density> respectively. Replace <density> with for example mdpi / hdpi / xhdpi. (you can put this in res-hdpi for testing)
Do a clean build and then check if it is getting reflected or not.
Very Simple!
Alloy example:
Put your image at app/assets/images for example app/assets/images/header.png .
Now your code is
<ImageView id='img1' image='/images/header.png' ></ImageView>
Or in .tss file
"#img1": {
width: 300,
image: '/images/header.png',
width: 300,
top: 0,
left: 0
}
End !
put your image :
app/assets/images/header.png
then access it with
<ImageView id='img1' image="/images/header.png"></ImageView>
important : try to clean your project first for every changes you made at assets folder before you run the app!
Recently I tried kivy, but I meet several problems. Thanks for help.
First, my kivy program always rotates screen when running on android. Usually the status bar on android is on the top, when I run kivy it goes to the right side.
Screen rotation is enabled on my android, but when I rotate my phone, the direction of kivy program doesn't change.
And I also try to rotate window by Window.rotation = 90, but the position of status bar didn't change.
The program is very simple:
main.py:
from kivy.app import App
from kivy.uix.widget import Widget
class PongGame(Widget):
pass
class PongApp(App):
def build(self):
return PongGame()
if __name__ == '__main__':
PongApp().run()
pong.kv:
<PongGame>:
canvas:
Rectangle:
pos: self.center_x - 5, 0
size: 10, self.height
Label:
font_size: 70
center_x: root.width / 4
top: root.top - 50
text: "0"
Label:
font_size: 70
center_x: root.width * 3 / 4
top: root.top - 50
text: "0"
Thanks.
First, my kivy program always rotates screen when running on android. Usually the status bar on android is on the top, when I run kivy it goes to the right side.
This is an option in the buildozer.spec, just change the orientation line to orientation = all. You can also read the comments on all the other lines to see the other options.
You can also set many more orientation options (including e.g. optionally obeying the user's system settings etc) by calling the android api directly with pyjnius. I have some example code for this here. Something similar will probably go in plyer.
If you're using python-for-android directly, the orientation option is one of the command line arguments you can pass to build.py. I don't remember offhand but you can check the documentation - though I recommend using buildozer anyway.