I'm running Ubuntu 16.04. And on Android Studio when I try to run my application in the emulator I get the following error:
FATAL EXCEPTION: main
Process: project name here, PID: 2528
java.lang.RuntimeException: Canvas: trying to draw too large(216090000bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:528)
at android.widget.ImageView.onDraw(ImageView.java:1316)
at android.view.View.draw(View.java:17185)
at android.view.View.updateDisplayListIfDirty(View.java:16167)
at android.view.View.draw(View.java:16951)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
at android.view.View.updateDisplayListIfDirty(View.java:16162)
at android.view.View.draw(View.java:16951)
at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513) at
etc...
I did have to run through some hoops to get my emulator working however, needed to create a sym-link so I can run the emulator on AMD. Not sure if this is part of the problem. And for the life of me I cannot figure why it continues to do this. In my group there are others who emulate the project just fine on the same emulated phone and SDK.
Move your image in the (hi-res) drawable to drawable-xxhdpi. But in app development, you do not need to use large image. It will increase your APK file size.
The solution is to move the image from drawable/ folder to drawable-xxhdpi/ folder, as also others have mentioned.
But it is important to also understand why this somewhat weird suggestion actually helps:
The reason is that the drawable/ folder exists from early versions of android and is equivalent to drawable-mdpi. When an image that is only in drawable/ folder is used on xxhdpi device, the potentially already big image is upscaled by a factor of 3, which can then in some cases cause the image's memory footprint to explode.
This solution worked for me.
Add these lines in your Manifest application tag
android:largeHeap="true"
android:hardwareAccelerated="false"
I had the same problem.
If you try to upload an image that is too large on some low resolution devices, the app will collapse.
You can make several images of different sizes (hdpi, xxdpi and more) or simply use an external library to load images that solve the problem quickly and efficiently.
I used Glide library (you can use another library like Picasso).
panel_IMG_back = (ImageView) findViewById(R.id.panel_IMG_back);
Glide
.with(this)
.load(MyViewUtils.getImage(R.drawable.wallpaper)
.into(panel_IMG_back);
This issue can be resolved by 3 methods as follows:
Method 1:
By adding image into a res/drawable-nodpi folder (By doing this it will not pre-scale your image).
Method 2:
Generate all dpi(hdpi,ldpi,mdpi,xhdpi,xxhdpi,xxxhdpi) of image and add to drawable folder. (This process will increase APK size).
Method 3:
Add image to drawable/drawable-xxhdpi folder.
All these methods are verified.
Turns out the problem was the main image that we used on our app at the time. The actual size of the image was too large, so we compressed it. Then it worked like a charm, no loss in quality and the app ran fine on the emulator.
For this error was like others said a big image(1800px X 900px) which was in drawable directory, I edited the image and reduced the size proportionally using photoshop and it worked...!!
If you don't want your image to be pre-scaled you can move it to the res/drawable-nodpi/ folder.
More info: https://developer.android.com/training/multiscreen/screendensities#DensityConsiderations
if you use Picasso change to Glide like this.
Remove picasso
Picasso.get().load(Uri.parse("url")).into(imageView)
Change Glide
Glide.with(context).load("url").into(imageView)
More efficient Glide than Picasso draw to large bitmap
I also had this issue when i was trying to add a splash screen to the android app through the launch_backgrgound.xml . the issue was the resolution. it was too high so the images memory footprint exploded and caused the app to crash hence the reason for this error. so just resize your image using a site called nativescript image builder so i got the ldpi,mdpi and all the rest and it worked fine for me.
I just created directory drawable-xhdpi(You can change it according to your need) and copy pasted all the images to that directory.
This can be an issue with Glide. Use this while you are trying to load to many images and some of them are very large:
Glide.load("your image path")
.transform(
new MultiTransformation<>(
new CenterCrop(),
new RoundedCorners(
holder.imgCompanyLogo.getResources()
.getDimensionPixelSize(R.dimen._2sdp)
)
)
)
.error(R.drawable.ic_nfs_default)
.into(holder.imgCompanyLogo);
}
Try using an xml or a vector asset instead of a jpg or png.
The reason is quite obvious in the exception name itself i.e. the resolution of the resource is too large to render.
You can png to xml using online tools like https://svg2vector.com/ OR add your image to drawable-xxhdpi folder.
Solution for Picasso is add Transformation for resize image.
class ResizeTransformation(private val maxSize: Int) : Transformation {
override fun transform(source: Bitmap?): Bitmap? {
var result:Bitmap? = null
if (source != null) {
var width = source.width
var height = source.height
val bitmapRatio = width.toFloat() / height.toFloat()
if (bitmapRatio > 1) {
width = maxSize;
height = (width / bitmapRatio).toInt()
} else {
height = maxSize;
width = (height * bitmapRatio).toInt()
}
result = Bitmap.createScaledBitmap(source, width, height, true)
source.recycle()
}
return result
}
override fun key() = "resize()"
}
Use:
Picasso.get()
.load(url)
.transform(ResizeTransformation(2400)) //FHD+ resolution
.into(view)
Convert your all png formats into webs format. You can do it by Android Studio.
I'm using laravel-mix withe vueJS and I'm having issue on how to properly set-up the image directory.
Here's my initial mix set-up
mix
.js("resources/js/app.js", "public/js")
.sass("resources/sass/app.scss", "public/css")
.copy("resources/assets", "public/images/" );
as you can see, I'm copying all the content of resources/assets folder to public/images/ folder
so this image assets/svg/logo-white.svg will be on images/svg/logo-white.svg
Now here's where I'm lost.
//using this
src="/assets/svg/logo-white.svg"
//result is obviously same (wrong url)
src="/assets/svg/logo-white.svg"
//using this
src="#/assets/svg/logo-white.svg"
// the result is (wrong url it lacks svg folder)
src="/images/logo-white.svg?c381d0781c93aa7ea138a64f7ea3f17d"
//using this
:src="'#/assets/svg/logo-white.svg'"
//result (another wrong)
src="#/assets/svg/logo-white.svg"
if I add .setResourceRoot("") to my mix config
//using this
src="#/assets/svg/logo-white.svg"
//results to this,
src="http://localhost:8080/images/logo-white.svg?c381d0781c93aa7ea138a64f7ea3f17d"
//which supposedly a wrong URL but its weirdly working
//I have no idea why its showing the images when the image is on /images/svg/ folder not in /images/
So as you can see, using src="#/assets/blabla.jpg" only work if all my images are inside the root of images folder, but doesn't work inside child folder of the images folder.
and adding .setResourceRoot("") works in a mysterious way which I dont really want to gamble as I'm not sure what will happen with this on production
would appreciate any help on this and clarification on how I can properly get the image url and why its behaving this way
I am having an issue with PDF's in the latest Typo3 release. If I add PDF to the Image content element, I get this:
The file info looks like this:
Checking the Image Processing Test of Typo3, no errors are returned. PDF/AI also seems to be fine.
I tested several PDF's and AI files as well, they won't show dimensions either.
I have the suspicion that the command 'identify' does not work within Typo3, it still returns perfect results from shell.
Any idea where to look?
multiple reasons possible:
you just need to reimport metadata (scheduler task)
your PDF is coded in an unsual format (there is more then one option in PDF to include the title image)
missing/wrong rights:
maybe another program is executed from commandline than from PHP.
maybe the file can't be accessed correctly from ghostscript started from web
I've encountered a weird issue with Phantomjs when converting an html file to pdf. My html, resulting pdf, and rasterize.js files are below:
http://401web.com/_pub/2TRTI8E.html
http://401web.com/_pub/2TRTI8E.pdf
http://401web.com/_pub/rasterize.js
You will notice that in the PDF file, at page 6, the content gets cut off and then on page 7, the content is repeated and is then correct all the way to the end of the document.
The html file contains a series of tags with their src attributes set as data:image/png;base64...
The application call to the phantom library is as follows:
phantomJS.Run("C:\path\to\directory\rasterize.js"),
new[] { webpath, outFilePdf, "A4", "1", "portrait"}, null, null);
Note that sometimes the rendered pdf file will exhibit the break/repeat behavior in different locations within the document eg: page 7 instead of 6) but the same issue always occurs.
Also, I am using phantomjs throughout my application (with the same rasterize.js script) with no other issues. This only happens on this export and only if there are a number of images.
My theory is that there is something going on with the image.onload event, specifically with base64 data but I have no idea how to troubleshoot this.
This is all within a .Net MVC application. I am using the PhantomJS nuget package found here: https://www.nuget.org/packages/PhantomJS/
Help is greatly appreciated.
Update: when running phantomjs locally via command line I was receiving the error below:
[CRITICAL] QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written
libpng error: Read Error
I solved this (though I have no idea how/why) by replacing the cdn references in the html file to font-awesome.css and weather-icons.css files with locally hosted versions. After that, no more error and no more duplicate content.
Adobe Flex 3: can I get TTF/OTF system fonts and embed at runtime?
Hi,
I'm a Stack Overflow noob so please go easy on me.
I've searched all day and found dozens of tutorial/examples on how to use [Embed] metadata or
Flash SWF files but they all tell me to either use a path in the source attrib or a text string in the systemFont attrib. What I want to do is; at runtime get all installed fonts on a given machine, determine which are TTF/OTF, embed them all and offer them in a comboBox. Something along these lines;
public function embedFonts():void{
try{
//get all device and embedded fonts
availableFonts = Font.enumerateFonts(true);
availableFonts.sortOn("fontName", Array.CASEINSENSITIVE);
for each(var thisFont:Font in availableFonts)
{
[Embed(systemFont=thisFont.fontName,
fontName=thisFont.fontName,
mimeType='application/x-font')]
//this bit need to create a unique variable name on each loop
var thisfont:Class;
}
}
catch(error:Error){
//if cant embed it's likely not to be TTF or OTF
//so move on to the next font.
}
}
Does anyone know a way?
Many, many thanks
You can't embed fonts at runtime.
And what would be the point?
Your swf runs on my machine, enumerates fonts on my machine, then embeds them
and offer them back to me? They are installed, use them directly, no need to embed.
So not only that is it not possible, but probably nobody will ever implement such a feature.