Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i scale the gif? #158

Closed
csshuai opened this issue Apr 28, 2015 · 7 comments
Closed

How can i scale the gif? #158

csshuai opened this issue Apr 28, 2015 · 7 comments
Labels

Comments

@csshuai
Copy link

csshuai commented Apr 28, 2015

e.g. :
the gif image size: 1280 * 720,
how can i get a Bitmap with size (800 * 600)?


Just like this:
GifInfoHandle : {
width = 1280;
height = 720;
}

Bitmap buffer = Bitmap.createBitmap(800, 600, Bitmap.Config.ARGB_8888);
GifInfoHandle.renderFrame(buffer);

@koral--
Copy link
Owner

koral-- commented Apr 28, 2015

You can use something like this:

        Bitmap currentFrame = gifDrawable.getCurrentFrame();
        Bitmap scaledFrame = Bitmap.createScaledBitmap(currentFrame, 800, 600, true);

@csshuai
Copy link
Author

csshuai commented Apr 29, 2015

That used more memory. There are ways to save memory?

@koral-- koral-- reopened this Apr 29, 2015
@koral--
Copy link
Owner

koral-- commented Apr 30, 2015

In GifTextureView you can use [TextureView#getBitmap(int, int)](http://developer.android.com/reference/android/view/TextureView.html#getBitmap%28int, int%29)
there is no internal bitmap in such case.

In GifDrawable I have no other ideas without modifying library source.
You can change #getCurrentFrame() implementation to not make a copy but return internal buffer directly.
Bitmap passed to #renderFrame() cannot be smaller than GIF dimensions unless you change native code.

@koral-- koral-- closed this as completed Apr 30, 2015
@csshuai
Copy link
Author

csshuai commented Apr 30, 2015

Whether it will provide #renderFrame() to get smaller Bitmap function in the future?

@koral--
Copy link
Owner

koral-- commented May 1, 2015

I have no plan to do such feature myself, but pull requests are welcome.

@kuabhish
Copy link

kuabhish commented Nov 26, 2020

You can use something like this:

        Bitmap currentFrame = gifDrawable.getCurrentFrame();
        Bitmap scaledFrame = Bitmap.createScaledBitmap(currentFrame, 800, 600, true);

Hey @koral--
Where should I write this code snippet to resize the gif???

@kuabhish
Copy link

Hey @koral--

I made a new class which extends your GifDrawable

    public MyGifDrawable(@NonNull File file, int width , int height) throws IOException {
        super(file);
        this.width = width;
        this.height = height;
        this.mDstRect = new Rect(0, 0, this.width, this.height);
    }

    @Override
    public void draw(@NonNull Canvas canvas) {
//        super.draw(canvas);
        Bitmap bmp = getCurrentFrame();
        Rect mSrcRect = new Rect(0, 0, this.width, this.height);
        Bitmap scaledFrame = Bitmap.createScaledBitmap(bmp, this.width, this.height, true);
        canvas.drawBitmap(scaledFrame, mSrcRect, this.mDstRect, mPaint);
    }

It looks like this. I am unable to fulfil my needs actually. My code can only resize the image.
How should I resize the canvas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants