开发者

Db4o, Java: Storing images using blobs

开发者 https://www.devze.com 2023-01-15 15:07 出处:网络
I want to store images in Db4o using Blobs. How can I store them and how do I g开发者_StackOverflowet them out again?Take a look at this question answer: How to stores and Pictures in Db40?

I want to store images in Db4o using Blobs. How can I store them and how do I g开发者_StackOverflowet them out again?


Take a look at this question answer: How to stores and Pictures in Db40?

I repost my answer again, a bit updated with the links to the Java documentation:

There are two basic ways to handle Blobs. Either you store a blob as byte-array in the database or you use the special db4o-Blob-Type. Both have their advantages.

Advantages/Disadvantages with byte array:

  • The blobs are in the db4o-database-file. So there's only a single file to copy around.
  • Byte-arrays are part of the normal db4o-transaction and behave as expected.
  • When storing large blobs, you might run into the database-size limitation of db4o. (256 GB)

Advantages/Disadvantaged with db4o-blobs

  • The blobs are stored as regular files outside the database. This keeps the database itself small. Furthermore you just can access all stored blobs with a regular application.
  • You always need to copy the blob-directory and the database.
  • The db4o-blobs works outside the db4o transaction. This means that a db4o-blob behaves different than any other stored object (and the API is a little strange). However this allows to retrieve a db4o-blob without blocking the current transaction.

For your case I would store a byte[] array with the picture in the Person class. Or you create a special Image-class. This image-class contains then a byte-array with the picture. And a few methods to convert this byte-array from and to a Winforms-bitmap.

0

精彩评论

暂无评论...
验证码 换一张
取 消