MuPDF fit to screen issue android - android

I am creating an application where I need to show PDFs rendering.
For that purpose I successfully installed the MuPDF library and I'm able to see PDFs successfully.
Now I am facing an issue.
I am not able to see PDFs fit to screen.
I followed this also, but no success.
I think I need to do some thing with this method.
private void measureView(View v) {}
Can anyone guide me?
How can I achieve this?

I would have called what the Android app does by default "fit to screen", so I'm not sure what you are trying to achieve, but if you want (say) the page to fit the width of the screen, you could try replacing, within measureView,
float scale = Math.min((float)getWidth()/(float)v.getMeasuredWidth(),
(float)getHeight()/(float)v.getMeasuredHeight());
by
float scale = (float)getWidth()/(float)v.getMeasuredWidth();

Related

Android: Animated gif image resize in kmagick

I am using kmagick for resizing gif images in android. It works fine for static but gives incorretc output for gif or animated webp files.
Magick.initialize().use {
val wand = MagickWand()
// getting image
wand.readImage(src)
// resizing image
wand.resizeImage(512,512,FilterType.UndefinedFilter)
// Saving image
wand.writeImage(dst)
promise.resolve("Done at ${dst}")
}
Input: (animated gif having multiple frames)
Output: I think its single frame and that also messed up but resizes according to input for height width.
Whats happening here. How to fix it?
Just want to reference for future, this was already answered in
https://github.com/cherryleafroad/kmagick/issues/3#issuecomment-1068044815
Anyways, to sum up what's going on,
Gifs are able to save the difference between frames to save space.
It's due to the way gif images work. Because the cli uses the api in a certain way, and kmagick bindings are only direct bindings to the c api, if you want to achieve the same results that the cli does, you have to use the api in the same way. (kmagick isn't doing anything to the image, it's imagemagick that's doing it; so it's more relevant to check imagemagick api docs / ask them so you can do it in the same way and get the same results).
I'm not sure what imagemagick api they're using off the top of my head however to achieve those results, but I think that doing something like extracting each frame individually then resizing them one by one would solve it.

ImageView slow when setImageResource

since ShowCaseView development is discontinued, i chose for another way to make the First Tour in my Application, the way is:
i took 7 screen shots from my Galaxy G4 for each screen and made some text in it and display it in a imageView in the first run.
But when i change the image (the user click in a next tip button), it take ages to change and buggy the app, in the tablet(10.1) it work well(i dont know why since the tablet has low processor than the g4)
the images are in a good quality(HD), size is 720:1280, if i change the size to something like 500x600 or smaller, it change faster, but in the tablet the image looks horrible ugly
im using this to change;
btnNextTip.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
tipImages.setImageResource(bImage);
}
});
is there any way to do this? or another good library to do a first tour? or change the images but it not look VGA screenshots ?
thanks
setImageResource() method is bit slow because it does decoding on UI thread, We can solve this problem using worker thread or AsyncTaks, but a simple and ready made solution is available for that. Which is Glide library. You just need to add it's dependency to your gradle file as:
compile 'com.github.bumptech.glide:glide:3.7.0'
and then set drawable image using it's id as:
Glide.with(context).load(bImage).into(tipImages);
Also may be other image libraries like Picasso provide this option.
(You can use the latest version of Glide library instead of 3.7.0)
A good approach would be to seperate your Image Resources so that one with Higher Quality are used for Tablet and one with Lower resolution for your Phones.
You App can detect the screen size of the Device that your App is installed on and based on that, it will choose which image resolution to display.
Check here for details:
Supporting Multiple Screen sizes - Android Developer

Getting the real dimensions of an image with titanium

I'm trying to create a cross-platform app.
So I have an image 1000x200 and I want to position it as image on background.
I try to calculate a real image size, to get it perfect on each screen. Because titanium resizes images and scales them in some magic way...
menuBottomImageView.toImage().width works fine on iOS and I get 1000px, but on android I get not the real size, only the displayed size and that's not what I need.
Is there a way to get the real dimensions of a file for both systems?
for Android there is no better method, if you use getWidth() method, it will give createImageView()'s width, mentioned in the object. best one is your method menuBottomImageView.toImage().width .
I don't have Android set up to test it, but on iOS I've discovered you can use:
var imgBlob = menuBottomImageView.toBlob(),
imgWidth = imgBlob.width,
imgHeight = imgBlob.height;
Using toBlob() is also much faster than using toImage(). According to the docs this is supported on Android, but then the docs say lots of things that don't always work out.
If the controller you are asking for toImage() is added and loaded on window then only it will give you proper size.

Cocos2D android background image gets messed up

so im trying to make a game with just a simple static background at the moment, but when i draw it to the screen (no scaling being done as the resolution of the image is the same as the screen) it draws the bottom portion of the image incorrectly where the bottom few hundred pixels of the image are exactly the same going down the image. Sorry it's so difficult to explain but being new here i cant actually post an image of what is going wrong.
Now im just using a simple sprite to render this background image. Here is the code being used:
// background layer: another image
background = CCSprite.sprite("WaterBackground.png");
// change the transform anchor point (optional)
background.setPosition(CGPoint.make(GAME_WIDTH/2, GAME_HEIGHT/2));
addChild(background);
am i doing something wrong here? Does Cocos2D not support such large images for sprites? (resolution of 800*1280)
Any help would be greatly appreciated!
Since i am now able to upload images, here are visuals of what is going wrong:
And the problem in my game:
As you can see, the problem is hard to describe. The problem only exists with this larger image; i scaled it down manually in GIMP and then scaled it up for the game and it looked fine (except for being a lower resolution). I also tried scaling down this larger image which still resulted in the same problem. Hopefully you guys can help me as I have no clue what could possibly cause this error. Especially since i read that Cocos2D's max supported image size is 2048*2048 and my image is well within that.
Thanks for any help you guys can provide!
This is due to limitations on the size of textures. Coсos2d-android supports images with a maximum size of 1024 x 1024 pixels.
I faced the same problem and looking for a way to solve it.
EDIT
I found the solution
In cocos2d project open file CCTexture2d.java in org.cocos2d.opengl package and change kMaxTextureSize from 1024 to 2048
I'm not certain, as from your code and looking at the cocos2d code I can't see a definite reason why this would be happening, but given the number of sprites you've got on the screen, i'd definitely take a look at my answer to this question as you may well be hitting one of cocos2d's quirky little rendering faults around multiple sprites. can't hurt to try spritesheets, and it's certainly the correct way to actually do sprites in cocos.
also, definitely create yourself a helper utility to determine the scaling ratio of a device compared to your original image sizes, as unlike on iphone, android does have a pretty much unlimited variation of screen resolutions, and a simple bit of "scale as you load" utility code now will save you lots of time in the future if you want to use this on any other device.
you should try to make one method for adding background,i am doing this this like this way try this hope it will help full for you...here addBackGroundScene is my method and i am adding my background with this method,scrXScaleFactor is maintaining scaling part of my screen try this...
private void addBackGroundScene() {
CCSprite bgForLevel1 = addBackgroundAtOrigin("prelevel1/bgMenu.jpg");
bgForLevel1 .setScaleX(scrXScaleFactor);
bgForLevel1 .setAnchorPoint(0, 0);
addChild(bgForLevel1 );
}

How to magnify an image programmatically in Android?

I have couple of images showing on Android 2.2 with help of PageViewer (Thanks to supporting libs from android). This works like a charm. But what I am looking for is to magnify each of image (zoom in) when they are displayed automatically/programmatically (Not when the user pinch the image). How can I do this?
I saw this feature on Flickr app of iPhone (this feature is not on Android Flickr app).
Use a good size on the ImageView of each item (match_parent, match_parent) and use android:scaleType='centerCrop' or 'centerInside'

Categories

Resources