报错:
java.lang.IllegalArgumentException: Unsupported image type (mirai) for ExternalResource net.mamoe.mirai.internal.utils.ExternalResourceImplByFile@e44b38d, considering use gif/png/bmp/jpg format. image header:
at net.mamoe.mirai.internal.message.image.ImageDecoderKt.calculateImageInfo(ImageDecoder.kt:159)
at net.mamoe.mirai.internal.contact.CommonGroupImpl$uploadImage$lambda-16$$inlined$runBIO$1.invoke(CoroutineUtils.kt:23)
at kotlinx.coroutines.InterruptibleKt.runInterruptibleInExpectedContext(Interruptible.kt:51)
at kotlinx.coroutines.InterruptibleKt.access$runInterruptibleInExpectedContext(Interruptible.kt:1)
at kotlinx.coroutines.InterruptibleKt$runInterruptible$2.invokeSuspend(Interruptible.kt:43)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
代码:
byte[] bytes = Base64.getDecoder().decode(stringR.getData());
String path = dataFile.getPath().substring(0, dataFile.getPath().length() - 9);
File file = FileUtils.byte2image(bytes, path , UUID.randomUUID() + ".png");
ExternalResource resource = ExternalResource.create(file);
Image image = event.getGroup().uploadImage(resource);
MessageChain messageChain = new MessageChainBuilder()
.append(new At(event.getSender().getId()))
.append("\n")
.append(image)
.build();
event.getGroup().sendMessage(messageChain);