(I've made three posts in the last week on SO regarding a Java project I'm working on. I feel guilty, but what the hell, your answers are amazing.)
Here's a chunk of code in C#:
Bitmap bitmap = ...
int dstStride = bitmap.Stride;
byte* bdst = (byte*)bitmap.Scan0;
I want to make an equivalent algorithm in Java. I'm beginning to think this is impossible, based on other, similar questions .
I can actually replicate the stride info of my bitmap, but of course, that byte*
is nigh impossible to reproduce. What happens later is that there's a for
loop that manipulates the bitmap image, a la:
bdst[x * 3 + y * dstStride + 2] = (byte)(alpha * bsrc[dx * 3 + L * srcStride + 2]);
(x & y are iterators in a loop)
Naturally I'm unable to simply make bdst a byte array because that doesn't make sense. According to this totally awesome article , Scan0 is "[t]he address in memory of the fixed data array."
And judging by the above SO post, this is not possible in Java. Confirm / deny?
You cannot get a direct pointer to memory in Java. This is obviously by design.
However you can get an array of pixels from an Image using the PixelGrabber class. Or, if you have a BufferedImage , you can work with the Raster directly. This may help you achieve your goal without accessing memory directly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.