Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC:

Cache for PDFViewThumb 4 years 6 months ago #14625

  • thiagopelikan
  • thiagopelikan's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 36
  • Thank you received: 0
I'm trying to implement above as you mentioned but I'm having problems to do this.
I think the structure is ok but I didn't understood how to use BMP and DIB objects, could you please help me on that?

For now, I have:
protected void RenderThumb() {
        Bitmap bitmap = null;
        if (m_status == 2) return;

        if (m_page == null)
            m_page = m_doc.GetPage(m_pageno);

        File thumbPath = getThumbPath(m_pageno);
        if (thumbPath.exists()) {
            bitmap = CommonUtil.loadThumb(thumbPath);
            BMP bmp = new BMP();
            bmp.Create(bitmap);

            m_dib = new DIB();
            bmp.DrawToDIB(m_dib, m_dibw, m_dibh);
            Matrix mat = new Matrix(m_scale, -m_scale, 0, m_dibh);
            //How to get a Bitmap object and add to DIB Object
            //How to render a page using a DIB OBJECT
            m_page.RenderPrepare(m_dib);
            m_page.Render(m_dib, mat);
            mat.Destroy();
        } else {
            if (m_dib == null) {
                DIB dib = new DIB();
                dib.CreateOrResize(m_dibw, m_dibh);
                m_page.RenderPrepare(dib);
                m_dib = dib;
            } else m_page.RenderPrepare(m_dib);
            if (m_status == 2) return;
            if (!m_page.RenderThumbToDIB(m_dib)) {
                Matrix mat = new Matrix(m_scale, -m_scale, 0, m_dibh);
                m_page.Render(m_dib, mat);

                bitmap = Bitmap.createBitmap(m_dibw, m_dibh, Bitmap.Config.ARGB_8888);
                //IS IT NECESSARY TO RENDER AS THUMB HERE?? I Tried m_dib.ToBMP without success
                m_page.RenderThumb(bitmap);
                CommonUtil.saveThumb(bitmap, thumbPath);
                mat.Destroy();
            }
        }
        if (m_status != 2)
            m_status = 1;
    }

The files are saved correctly but loading it and render the page from the file is not working.

Tks,
Thiago

Please Log in or Create an account to join the conversation.

Cache for PDFViewThumb 4 years 6 months ago #14626

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
            bitmap = CommonUtil.loadThumb(thumbPath);
            BMP bmp = new BMP();
            bmp.Create(bitmap);

            m_dib = new DIB();
            bmp.DrawToDIB(m_dib, m_dibw, m_dibh);
            Matrix mat = new Matrix(m_scale, -m_scale, 0, m_dibh);
            //How to get a Bitmap object and add to DIB Object
            //How to render a page using a DIB OBJECT
            m_page.RenderPrepare(m_dib);
            m_page.Render(m_dib, mat);
            mat.Destroy();
change to:
            m_dib = new DIB();
            m_dib.CreateOrResize(m_dibw, m_dibh);
            Matrix mat = new Matrix(m_scale, -m_scale, 0, m_dibh);
            m_page.RenderPrepare(m_dib);
            m_page.Render(m_dib, mat);
            mat.Destroy();

            bitmap = Bitmap.CreateBitmap(m_dibw, m_dibh, ARGB_8888);
            BMP bmp = new BMP();
            bmp.Create(bitmap);
            m_dib.DrawToBMP(bitmap, m_dibw, m_dibh);
            bmp.Free(bitmap);
            bitmap.Compress(...);

Please Log in or Create an account to join the conversation.

Last edit: by radaee.

Cache for PDFViewThumb 4 years 6 months ago #14627

  • thiagopelikan
  • thiagopelikan's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 36
  • Thank you received: 0
The lines you ask me to change are responsible for loading bitmap from sdcard. Using your lines I'll never read files, isn't that correct?

Please Log in or Create an account to join the conversation.

Cache for PDFViewThumb 4 years 6 months ago #14628

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
sorry, not see your codes in correct way.
        if (thumbPath.exists()) {//if load from storage
            bitmap = CommonUtil.loadThumb(thumbPath);
            BMP bmp = new BMP();
            bmp.Create(bitmap);
            m_dib = new DIB();
	    m_dib.CreateOrResize(m_dibw, m_dibh);
            bmp.DrawToDIB(m_dib, 0, 0);
	    bmp.Free(bitmap);
        } else {//if not load from storage, we render to DIB, then draw to BMP
		if( m_dib == null )
		{
			DIB dib = new DIB();
			dib.CreateOrResize( m_dibw, m_dibh );
			m_page.RenderPrepare(dib);
			m_dib = dib;
		}
		else m_page.RenderPrepare(m_dib);
		if( m_status == 2 ) return;
		if(!m_page.RenderThumbToDIB(m_dib))
		{
			Matrix mat = new Matrix(m_scale, -m_scale, 0, m_dibh);
			m_page.Render(m_dib, mat);
			mat.Destroy();
		}
                bitmap = Bitmap.createBitmap(m_dibw, m_dibh, Bitmap.Config.ARGB_8888);
                BMP bmp = new BMP();
                bmp.Create(bitmap);
	        m_dib.DrawToBMP(bmp, 0, 0);
	        bmp.Free(bitmap);
                CommonUtil.saveThumb(bitmap, thumbPath);
        }
        if (m_status != 2)
            m_status = 1;
    }

Please Log in or Create an account to join the conversation.

Last edit: by radaee.
  • Page:
  • 1
  • 2
Powered by Kunena Forum