How do I send images from a Java application to an Android application?

I have a client - server application The server is pure Java and the client is Android application They use ServerSocket to communicate over TCP

I want to create an image on the server, edit it (for example, draw lines on it), and then send it to the client to display it as a bitmap on the screen

My first method is to use Android graphics. The bitmap library is imported into the server to use it there, but of course, it doesn't work because you can't use the Android library outside the Android environment

My current method is to use bufferedimage on the server, but the problem is that I can't find how to serialize it in a way that the client can reconstruct the bitmap from it I tried to use imageio Write, but what do I need to do on the client?

Does anyone know how to solve this problem, or there is a better way? I appreciate your help

Solution

You can use bitmapfactory class to decode any PNG or JPG image in Android Get the InputStream of the image and use bitmapfactory decodeStream(inputStream). It doesn't need special serialization... Just send the bytes of the image

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>