I am using bitmap to load the image, if the image size is more than 2880 h/w I am getting an error.
BitmapData src = new BitmapData(canvasToPrint.width,canvasToPrint.height)(canvasToPrint.width, canvasToPrint.height);
src.draw(_designArea); // -- encode the jpg
var quality:int = 115;
var jpg:JPEGEncoder = new JPEGEncoder(quality);
var byteArray:ByteArray = jpg.encode(src);
if canvasToPrint.width > 2880 or canvasToPrint.width > 2880 I will get below error at line 1
Error : invalid Bitmap
To over come the above issue I have used bitmapdataunlimited class, as mentioned in the below link.
http://blog.formatlos.de/2008/05/28/bitmapdataunlimited/comment-page-2/#comment-4870
But it only works fine for 4096 pixel of height and width, guide me if any alternative solution is there to create huge bitmap.
If makes a difference which FlashPlayer you are targetting:
versions VS maximum bitmapsize
flashplayer -9 : 2880x2880 px
flashplayer 10 : 4096x4096 px
flashplayer 11 : unlimited
http://www.bit-101.com/blog/?p=2067
Try this
Related
Source: here
With the following segment of code all my Android devices record with a maximum width of 960 rather than the device width.
val metrics = resources.displayMetrics
val rawWidth = metrics.widthPixels
val rawHeight = metrics.heightPixels
val scale = if(maxOf(rawWidth, rawHeight) > 960){
960f / maxOf(rawWidth, rawHeight)
} else 1f
val width = (rawWidth * scale).roundToInt()
val height = (rawHeight * scale).roundToInt()
My phone has a 1080x2400 screen and above code just records video with resolution 432x960. In order to fix it, I modified the code as it follows hoping that now it would record with my device resolution:
val metrics = resources.displayMetrics
val rawWidth = metrics.widthPixels
val rawHeight = metrics.heightPixels
val scale = 1f
val width = (rawWidth * scale).roundToInt()
val height = (rawHeight * scale).roundToInt()
However that causes the app to not record anything at all.
I know I could type manually something like val 'width = 1080' and 'val height = 1920' but then I would have to create an app version for each one of my android devices, that's why I'd like the app to be able to find out the right number for each device running the app
Iam trying to use Imebra library to display DICOM images in android. Iam using version 5.0 of the library.
The bitmap shown is completely gray, transfer syntax for image is 1.2.840.10008.1.2.1.For other supported transfer syntax i.e JPEG it works fine.
Also I am unable to add VOILUT transform functionality as mentioned in documentation it gives error cons tructor not found for VOILUT.
Below is the code Iam using, VOILUT transform part is giving constructor not found. if i remove VOILUT transform part things work fine but for image with transfer syntax 1.2.840.10008.1.2.1 it shows completely grey image
private Bitmap fromDicom(String filePath, int frameNumber){
// have been applied).
Image dicomImage = loadedDataSet.getImageApplyModalityTransform(frameNumber);
// Use a DrawBitmap to build a stream of bytes that can be handled by the
// Android Bitmap class.
com.imebra.TransformsChain chain = new com.imebra.TransformsChain();
if( com.imebra.ColorTransformsFactory.isMonochrome(dicomImage.getColorSpace()))
{
// Retrieve the VOIs (center/width pairs)
com.imebra.VOIs vois = loadedDataSet.getVOIs();
if(!vois.isEmpty())
{
// Get the first VOI setting from the dataset
chain.addTransform(new VOILUT(vois.get(0)));
}
else
{
// The dataset does not have any VOI setting, find the optimal one
com.imebra.SWIGTYPE_p_imebra__VOIDescription voiDescription = VOILUT.getOptimalVOI(dicomImage, 0, 0, dicomImage.getWidth(), dicomImage.getHeight());
chain.addTransform(new VOILUT(voiDescription));
}
}
DrawBitmap drawBitmap = new DrawBitmap(chain);
Memory memory = drawBitmap.getBitmap(dicomImage, drawBitmapType_t.drawBitmapRGBA, 4);
// Build the Android Bitmap from the raw bytes returned by DrawBitmap.
Bitmap renderBitmap = Bitmap.createBitmap((int)dicomImage.getWidth(), (int)dicomImage.getHeight(), Bitmap.Config.ARGB_8888);
byte[] memoryByte = new byte[(int)memory.size()];
memory.data(memoryByte);
ByteBuffer byteBuffer = ByteBuffer.wrap(memoryByte);
renderBitmap.copyPixelsFromBuffer(byteBuffer);
// Update the image
return renderBitmap;
}
After changing the code suggested by you, I don't find classes mentioned
VOIDescription instead i see class SWIGTYPE_p_imebra__VOIDescription should i use that class
There is one more error no getWidth() method available with vois.get(0).getWidth
One last Error i don't see class vois_t instead there is a class VOIs should VOIs be used
Thanks for the reponse
The VOILUT must be initialized with the proper contrast settings from the dataset like in the code below.
However, the dataset contains a VOI setting that is wrong (the window width is 0) so this file will be displayed correctly only if you use custom VOI settings or just use automatic settings when width is zero (see alternative code below which checks for width > 0).
Code that does not check for width:
if(com.imebra.ColorTransformsFactory.isMonochrome(dicomImage.getColorSpace());
{
// Retrieve the VOIs (center/width pairs)
com.imebra.vois_t vois = loadedDataSet.getVOIs();
if(!vois.isEmpty())
{
// Get the first VOI setting from the dataset
chain.addTransform(new VOILUT(vois.get(0)));
}
else
{
// The dataset does not have any VOI setting, find the optimal one
com.imebra.VOIDescription voiDescription = VOILUT.getOptimalVOI(dataSetImage, 0, 0, width, height);
chain.addTransform(new VOILUT(voiDescription));
}
}
Alternative code that checks if width is 0:
if(com.imebra.ColorTransformsFactory.isMonochrome(dicomImage.getColorSpace());
{
// Retrieve the VOIs (center/width pairs)
com.imebra.vois_t vois = loadedDataSet.getVOIs();
if(!vois.isEmpty() && vois.get(0).getWidth() > 0.1)
{
// Get the first VOI setting from the dataset
chain.addTransform(new VOILUT(vois.get(0)));
}
else
{
// The dataset does not have any VOI setting, find the optimal one
com.imebra.VOIDescription voiDescription = VOILUT.getOptimalVOI(dataSetImage, 0, 0, width, height);
chain.addTransform(new VOILUT(voiDescription));
}
}
I have a PDF that when I render it to a png it renders a line crooked, or rather with a step in it. This is the PDF and what it should look like: https://drive.google.com/file/d/1E-zucbreD7pVwWc3Z4MNe_lzsP6D9m49/view
Here is the full PNG rendering using PDFBox 2.0.13 and openjdk version 1.8.0_181:
And here is the specific portion of the PNG that has the step:
Excerpt of the page content stream:
q
1 0 0 1 35.761 450.003 cm
0 i
0.75 w
0 0 m
50.923 0 l
S
Q
q
1 0 0 1 86.139 450 cm
0 i
0.75 w
0 0 m
14.9 0 l
S
Q
("cm" is an affine transform, "m" a moveto, "l" a lineto). One can see that the two lines are slightly different, one at 450.003, the other one at 450.
Here's some code that simulates the error by replicating what PDFBox is doing:
BufferedImage bim = new BufferedImage(612, 792, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) bim.getGraphics();
RenderingHints r = new RenderingHints(null);
r.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
r.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
r.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.addRenderingHints(r);
g.translate(0, 792);
g.scale(1, -1);
g.setStroke(new BasicStroke(0.75f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10));
g.setColor(Color.black);
GeneralPath path = new GeneralPath();
path.moveTo(35.761f, 450.003f);
path.lineTo(35.761f + 50.923f, 450.003f);
g.draw(path);
path = new GeneralPath();
path.moveTo(86.139f, 450f);
path.lineTo(86.139f + 14.9f, 450f);
g.draw(path);
g.dispose();
ImageIO.write(bim, "png", new File("...."));
One can get rid of the error by commenting this line:
r.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
This could be done in the source code of PDFBox, or by passing the renderingHints in PDFRenderer.setRenderingHints(). However that one isn't available now, but will be available in 2.0.14 (see issue PDFBOX-4435, try a snapshot). And you can expect the rendering to be of poor quality by not having anti aliasing.
Update:
instead of removing the line mentioned above, add this one:
r.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
Source.
When I extract an image using pdfbox I am getting incorrect dpi of the image for some PDFs. When I extract an image using Photoshop or Acrobat Reader Pro I can see that the dpi of the image is 200 using windows photo viewer, but when I extract the image using pdfbox the dpi is 72.
For extracting the image I am using following code :
Not able to extract images from PDFA1-a format document
When I check the logs I see an unusual entry:
2015-01-23-main--DEBUG-org.apache.pdfbox.util.TIFFUtil:
<?xml version="1.0" encoding="UTF-8"?><javax_imageio_jpeg_image_1.0>
<JPEGvariety>
<app0JFIF majorVersion="1" minorVersion="2" resUnits="0" Xdensity="1" Ydensity="1" thumbWidth="0" thumbHeight="0"/>
</JPEGvariety>
<markerSequence>
<dqt>
<dqtable elementPrecision="0" qtableId="0"/>
<dqtable elementPrecision="0" qtableId="1"/>
</dqt>
<dht>
<dhtable class="0" htableId="0"/>
<dhtable class="0" htableId="1"/>
<dhtable class="1" htableId="0"/>
<dhtable class="1" htableId="1"/>
</dht>
<sof process="0" samplePrecision="8" numLines="0" samplesPerLine="0" numFrameComponents="3">
<componentSpec componentId="1" HsamplingFactor="2" VsamplingFactor="2" QtableSelector="0"/>
<componentSpec componentId="2" HsamplingFactor="1" VsamplingFactor="1" QtableSelector="1"/>
<componentSpec componentId="3" HsamplingFactor="1" VsamplingFactor="1" QtableSelector="1"/>
</sof>
<sos numScanComponents="3" startSpectralSelection="0" endSpectralSelection="63" approxHigh="0" approxLow="0">
<scanComponentSpec componentSelector="1" dcHuffTable="0" acHuffTable="0"/>
<scanComponentSpec componentSelector="2" dcHuffTable="1" acHuffTable="1"/>
<scanComponentSpec componentSelector="3" dcHuffTable="1" acHuffTable="1"/>
</sos>
</markerSequence>
</javax_imageio_jpeg_image_1.0>
I tried to google but I can see to find out what pdfbox means by this log. What does this mean?
You can download a sample pdf with this problem from this link:
http://myslams.com/test/1.pdf
I have even tried itext but it is extracting image with 96 dpi.
Am I doing something wrong? Or pdfbox and itext have this limitation?
After some digging I found your 1.pdf. Thus,...
PDFBox
In comments to this recent answer #Tilman and you were discussing this older answer in which #Tilman pointed towards the PrintImageLocations PDFBox example. I ran it for your file and got:
Processing page: 0
*******************************************************************
Found image [Im0]
position = 0.0, 0.0
size = 1704px, 888px
size = 613.44, 319.68
size = 8.52in, 4.44in
size = 216.408mm, 112.776mm
Processing page: 1
*******************************************************************
Found image [Im0]
position = 0.0, 0.0
size = 1704px, 2800px
size = 613.44, 1008.0
size = 8.52in, 14.0in
size = 216.408mm, 355.6mm
Processing page: 2
*******************************************************************
Found image [Im0]
position = 0.0, 0.0
size = 1704px, 2800px
size = 613.44, 1008.0
size = 8.52in, 14.0in
size = 216.408mm, 355.6mm
Processing page: 3
*******************************************************************
Found image [Im0]
position = 0.0, 0.0
size = 1704px, 1464px
size = 613.44, 527.04
size = 8.52in, 7.3199997in
size = 216.408mm, 185.928mm
On all pages this amounts to 200 dpi both in x and y directions (1704px / 8.52in = 888px / 4.44in = 2800px / 14.0in = 1464px / 7.32in = 200 dpi).
So PDFBox gives you the dpi values you are after.
(#Tilman: The current 2.0.0-SNAPSHOT version of that sample returns utter nonsense; you might want to fix this.)
iText
A simplified iText version of that PDFBox example would be this:
public void printImageLocations(InputStream stream) throws IOException
{
PdfReader reader = new PdfReader(stream);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
ImageRenderListener listener = new ImageRenderListener();
for (int page = 1; page <= reader.getNumberOfPages(); page++)
{
System.out.printf("\nPage %s:\n", page);
parser.processContent(page, listener);
}
}
static class ImageRenderListener implements RenderListener
{
public void beginTextBlock() { }
public void renderText(TextRenderInfo renderInfo) { }
public void endTextBlock() { }
public void renderImage(ImageRenderInfo renderInfo)
{
try
{
PdfDictionary imageDict = renderInfo.getImage().getDictionary();
float widthPx = imageDict.getAsNumber(PdfName.WIDTH).floatValue();
float heightPx = imageDict.getAsNumber(PdfName.HEIGHT).floatValue();
float widthUu = renderInfo.getImageCTM().get(Matrix.I11);
float heigthUu = renderInfo.getImageCTM().get(Matrix.I22);
System.out.printf("Image %.0fpx*%.0fpx, %.0fuu*%.0fuu, %.2fin*%.2fin\n", widthPx, heightPx, widthUu, heigthUu, widthUu/72, heigthUu/72);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
(Beware: I assumed unrotated and unskewed images.)
The results for your file:
Page 1:
Image 1704px*888px, 613uu*320uu, 8,52in*4,44in
Page 2:
Image 1704px*2800px, 613uu*1008uu, 8,52in*14,00in
Page 3:
Image 1704px*2800px, 613uu*1008uu, 8,52in*14,00in
Page 4:
Image 1704px*1464px, 613uu*527uu, 8,52in*7,32in
Thus, also 200dpi all along. So iText, too, gives you the dpi values you are after.
Your code
Obviously the code you referenced had no chance to report a dpi value sensible in the context of the PDF because it only extracts the images as found in the resources but ignores how the respective image resource is used on the page.
An image resource can be stretched, rotated, skewed, ... any way the author likes when he uses it in the page content.
BTW, a dpi value only makes sense if the author did not skew and rotated only by a multiple of 90°.
I am attempting to write a BufferedImage to png file using ImageIO, but every time I add an ICC_Profile to the IIOMetadata the resulting png image has no ICC_Profile embedded, and running ImageMagick identify on the resulting png file yields an error.
What I need is working code that adds the ICC_Profile. I admit that I am a bit of a novice with ImageIO. My thinking is that I just add the profile to the header and whatever is used to render the image should find the profile and display the image in the associated colorspace (if supported). Am I missing something else that I should be doing to this image?
Also - I would like to be clear that I want to use only ImageIO and not ColorConvertOp from JAI because JAI hasn't been developed in 7 years and the best way to do this is with standard JDK classes, in my opinion. Is this possible and/or has anybody else been able to achieve it?
My Code:
Iterator i = ImageIO.getImageWritersByFormatName("PNG");
if (i.hasNext()) {
ImageWriter imageWriter = (ImageWriter) i.next();
ImageWriteParam param = imageWriter.getDefaultWriteParam();
ImageTypeSpecifier its = new ImageTypeSpecifier(bi.getColorModel(), bi.getSampleModel());
IIOMetadata iomd = imageWriter.getDefaultImageMetadata(its, param);
String formatName = "javax_imageio_png_1.0";
Node node = iomd.getAsTree(formatName);
//add resolution
IIOMetadataNode phys = new IIOMetadataNode("pHYs");
phys.setAttribute("unitSpecifier", "unknown");
phys.setAttribute("pixelsPerUnitXAxis", "300");
phys.setAttribute("pixelsPerUnitYAxis", "300");
//add ICC PROFILE
IIOMetadataNode iccp = new IIOMetadataNode("iCCP");
//ICC_Profile pro = Util.getAdobeRGBICCProfile();
iccp.setUserObject(parameters.getOriginalICC());
iccp.setAttribute("profileName", "AdobeRGB1998");
iccp.setAttribute("compressionMethod", "deflate");
node.appendChild(phys);
node.appendChild(iccp);
try {
iomd.setFromTree(formatName, node);
} catch (IIOInvalidTreeException e) {
System.out.println("IIOInvalidTreeException Occurred setting resolution on PNG EXIF Header.");
e.printStackTrace(System.out);
}
IIOImage iioimage = new IIOImage(bi, null, iomd);
try {
imageWriter.setOutput(new FileImageOutputStream(new File(fileName)));
imageWriter.write(iioimage);
} catch (IOException e) {
System.out.println("Error Occurred setting resolution on PNG.");
e.printStackTrace(System.out);
}
}
Image Magick identify output:
Image: /adobe.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 399x508+0+0
Resolution: 300x300
Print size: 1.33x1.69333
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 34.4178 (0.134972)
standard deviation: 82.6482 (0.324111)
kurtosis: 2.12664
skewness: 2.01838
Green:
min: 0 (0)
max: 252 (0.988235)
mean: 27.8842 (0.10935)
standard deviation: 71.8833 (0.281895)
kurtosis: 4.11874
skewness: 2.41137
Blue:
min: 0 (0)
max: 254 (0.996078)
mean: 28.1182 (0.110267)
standard deviation: 73.4184 (0.287915)
kurtosis: 4.25472
skewness: 2.44667
Alpha:
min: 0 (0)
max: 255 (1)
mean: 38.5321 (0.151106)
standard deviation: 91.3288 (0.358152)
kurtosis: 1.79587
skewness: -1.9483
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 76.722 (0.300871)
standard deviation: 80.2016 (0.314516)
kurtosis: 4.15993
skewness: 2.43672
Alpha: none #00000000
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 399x508+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2013-12-30T10:23:05-06:00
date:modify: 2013-12-30T10:23:05-06:00
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 6
png:IHDR.color_type: 6 (RGBA)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 399, 508
png:pHYs: x_res=300, y_res=300, units=0
png:sRGB: intent=0 (Perceptual Intent)
signature: f03e01954623f646c9b594d0b2234ca444bb5c8282e923c8af520e08753fed0d
Artifacts:
filename: /adobe.png
verbose: true
Tainted: False
Filesize: 68.3KB
Number pixels: 203K
Pixels per second: 20.27MB
User time: 0.000u
Elapsed time: 0:01.009
Version: ImageMagick 6.8.6-6 2013-10-12 Q16 http://www.imagemagick.org
identify: iCCP: Data error in compressed datastream `/adobe.png' # warning/png.c /MagickPNGWarningHandler/1830.
identify: Profile size field missing from iCCP chunk `/adobe.png' # warning/png.c/MagickPNGWarningHandler/1830.
Any help would be much appreciated. Thank You.
The reason I was asking, is I don't think your ICC profile is a deflate compressed byte[]. You state "This is not the problem", but I really think it is. :-)
If I don't apply deflate compression to the ICC profile, I get a similar warning from ExifTool as you get from identify.
Warning : Error inflating iCCP
ICC Profile : (Binary data 526 bytes, use -b option to extract)
If I properly apply deflate compression to the ICC profile, the ICC profile is correctly identified as "Adobe RGB 1998".
Profile CMM Type : ADBE
Profile Version : 2.1.0
Profile Class : Display Device Profile
Color Space Data : RGB
[...]
CMM Flags : Not Embedded, Independent
Rendering Intent : Perceptual
Connection Space Illuminant : 0.9642 1 0.82491
Profile Creator : ADBE
Profile ID : 0
Profile Copyright : Copyright 2000 Adobe Systems Incorporated
Profile Description : Adobe RGB (1998)
The following code works for me:
public class PNGICCProfileIssue {
public static void main(String[] args) throws IOException {
File input = new File(args[0]);
BufferedImage image = ImageIO.read(input);
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("PNG");
if (!writers.hasNext()) {
return;
}
ImageWriter writer = writers.next();
writer.setOutput(ImageIO.createImageOutputStream(new File(input.getParent(), input.getName().replace('.', '_') + "_icc.png")));
IIOMetadata imageMetadata = writer.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(image), writer.getDefaultWriteParam());
//add ICC PROFILE
IIOMetadataNode iccp = new IIOMetadataNode("iCCP");
ICC_ColorSpace colorSpace = (ICC_ColorSpace) ColorSpaces.getColorSpace(ColorSpaces.CS_ADOBE_RGB_1998);
iccp.setUserObject(getAsDeflatedBytes(colorSpace));
iccp.setAttribute("profileName", "AdobeRGB1998");
iccp.setAttribute("compressionMethod", "deflate");
Node nativeTree = imageMetadata.getAsTree(imageMetadata.getNativeMetadataFormatName());
nativeTree.appendChild(iccp);
imageMetadata.mergeTree(imageMetadata.getNativeMetadataFormatName(), nativeTree);
writer.write(new IIOImage(image, null, imageMetadata));
}
private static byte[] getAsDeflatedBytes(ICC_ColorSpace colorSpace) throws IOException {
byte[] data = colorSpace.getProfile().getData();
ByteArrayOutputStream deflated = new ByteArrayOutputStream();
DeflaterOutputStream deflater = new DeflaterOutputStream(deflated);
deflater.write(data);
deflater.flush();
deflater.close();
return deflated.toByteArray();
}
I think this requirement should have been documented in the metadata documentation, as I have to give you it is kind of confusing..
Good luck!