Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1063463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:47:14+00:00 2026-05-16T18:47:14+00:00

I’m trying to serialize a class in which I have a bitmap variable. Here

  • 0

I’m trying to serialize a class in which I have a bitmap variable. Here is the code that is a bit working. I need help to find out what is still wrong.

private Bitmap myVideoScreenshotBm;

private void writeObject(ObjectOutputStream out) throws IOException{
    
    out.writeInt(myVideoScreenshotBm.getRowBytes());
    out.writeInt(myVideoScreenshotBm.getHeight());
    out.writeInt(myVideoScreenshotBm.getWidth());
    
    int bmSize = myVideoScreenshotBm.getHeight() * myVideoScreenshotBm.getRowBytes();
    ByteBuffer dst= ByteBuffer.allocate(bmSize);
    
    myVideoScreenshotBm.copyPixelsToBuffer(dst);
    
    byte[] bytesar=new byte[bmSize];
    dst.position(0);
    dst.get(bytesar);
    
    out.write(bytesar);
    
    
}

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
    
    int nbRowBytes=in.readInt();
    int height=in.readInt();
    int width=in.readInt();
    //
    int bmSize = nbRowBytes * height;
    byte[] toread= new byte[bmSize];
    
    in.read(toread, 0, toread.length);
    ByteBuffer dst= ByteBuffer.allocate(bmSize);
    dst.put(toread);
    dst.position(0);
    myVideoScreenshotBm=Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8);
    myVideoScreenshotBm.copyPixelsFromBuffer(dst);
    
}

I’m not getting an error, but the bitmaps I’m getting are wrong. Also, I do not know how to know which Bitmap.Config flag is suitable. How can I know?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:47:15+00:00Added an answer on May 16, 2026 at 6:47 pm

    Here is the code for a serialization with memory optimisation. Im using a static buffer that is growing to the biggest bitmap size and that I reuse each time.

    public class Video implements Serializable{
    public long videoId;
    public String title;
    public String publisher;
    public String language;
    public Date lastModified;
    public Date published;
    public String imageUrl;
    public String url;
    public Bitmap myVideoScreenshotBm;
    public Date expireTime;
    //public Drawable myVideoScreenshotDrawable;
    
    private static ByteBuffer dst;
    private static byte[] bytesar;
    
    public Video (long newVideoId) {
        this.videoId=newVideoId;
    }
    private void writeObject(ObjectOutputStream out) throws IOException{
    
        out.writeLong(videoId);
    
        out.writeObject(title);
        out.writeObject(publisher);
        out.writeObject(language);
        out.writeObject(lastModified);
        out.writeObject(published);
        out.writeObject(expireTime);
    
        out.writeObject(imageUrl);
        out.writeObject(url);
    
    
        out.writeInt(myVideoScreenshotBm.getRowBytes());
        out.writeInt(myVideoScreenshotBm.getHeight());
        out.writeInt(myVideoScreenshotBm.getWidth());
    
        int bmSize = myVideoScreenshotBm.getRowBytes() * myVideoScreenshotBm.getHeight();
        if(dst==null || bmSize > dst.capacity())
            dst= ByteBuffer.allocate(bmSize);
    
        out.writeInt(dst.capacity());
    
        dst.position(0);
    
        myVideoScreenshotBm.copyPixelsToBuffer(dst);
        if(bytesar==null || bmSize > bytesar.length)
            bytesar=new byte[bmSize];
    
        dst.position(0);
        dst.get(bytesar);
    
    
        out.write(bytesar, 0, bytesar.length);
    
    }
    
    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
    
        videoId=in.readLong();
    
        title=(String) in.readObject();
        publisher=(String) in.readObject();
        language=(String) in.readObject();
        lastModified=(Date) in.readObject();
        published=(Date) in.readObject();
        expireTime=(Date) in.readObject();
    
        imageUrl = (String) in.readObject();
        url = (String) in.readObject();
    
    
        int nbRowBytes=in.readInt();
        int height=in.readInt();
        int width=in.readInt();
    
        int bmSize=in.readInt();
    
    
    
        if(bytesar==null || bmSize > bytesar.length)
            bytesar= new byte[bmSize];
    
    
        int offset=0;
    
        while(in.available()>0){
            offset=offset + in.read(bytesar, offset, in.available());
        }
    
    
        if(dst==null || bmSize > dst.capacity())
            dst= ByteBuffer.allocate(bmSize);
        dst.position(0);
        dst.put(bytesar);
        dst.position(0);
        myVideoScreenshotBm=Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        myVideoScreenshotBm.copyPixelsFromBuffer(dst);
        //in.close();
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't change the type attribute of an <input> or… May 16, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer Honestly, I'd just do the low-budget overloading solution: [<Measure>] type… May 16, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer Um, wow. Can't believe I posted this question - it… May 16, 2026 at 11:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.