I am trying to display an image (with an alpha value) in a window (of size 200X200). The image is loaded into an OpenCV Mat datastructure.
The image I am loading, looks like this:
The image i see when displayed, looks like this:
The code I am using to load the Bitmap is as follows:
NSBitmapImageRep* imageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
pixelsWide:200
pixelsHigh:200
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:(200*4)
bitsPerPixel:32] autorelease];
memcpy(imageRep.bitmapData,paintBuffer.data,160000);
NSSize imageSize = NSMakeSize(200,200);
NSImage* myImage = [[[NSImage alloc] initWithSize: imageSize] autorelease];
[myImage addRepresentation:imageRep];
g_imageView setImage:myImage];
Update:
I was initially reading BGRA instead of the expected RGBA. On changing that, I just get a red version of image above, like this:
Related
Am trying to create transparent mat but am getting black background image in return so any idea how to do it as i have to overlay this image with some content on camera video feed.
code i tried.
cv::Mat comp = cv::Mat::zeros( currentImage.size(), CV_8UC4 );
comp.setTo(cv::Scalar(0,0,0,0));
imshow( "transparent", comp ); // show black background image.
thanks to #HansHire and #Scheff we find out that problem is in cv::imshow() it not render transparency so to check Mat for transparency it need to dumped to disk to be checked using system image viewer which render transparency very well
cv::Mat comp = cv::Mat::zeros( currentImage.size(), CV_8UC4 );
comp.setTo(cv::Scalar(0,0,0,0));
// imshow( "transparent", comp ); // show black background image because it cant render transparency .
imwrite( "C:/opencv_dump.png", comp ); // transparent upon opening , thumbnail may look black.
I have this code to display colored images in tabbar.
_itemOneNavigationController.tabBarItem.image = [[UIImage imageNamed:#"tabbar-trophy"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
_itemOneNavigationControllerr.tabBarItem.selectedImage = [[UIImage imageNamed:#"tabbar-trophy-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
This works well on iPhone5 & 4. However, on iPhone6 & 6+, images are appearing but do not occupy the entire tabBarItem. They are appearing centered.
Try UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage:
UIImage *unselected = [[UIImage imageNamed:#"tabbar-trophy"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selected = [[UIImage imageNamed:#"tabbar-trophy-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[_itemOneNavigationController.tabBarItem setFinishedSelectedImage:selected withFinishedUnselectedImage:unselected];
I have the following jsfiddle which he an existing image with a button that when clicked will change the image src randomly from an array.
JSFIDDLE: http://jsfiddle.net/GpSbd/7/
Some of these images will be very large, is it possible to reduce or compress the image file down before it does setImage and draws it onto the stage as i will eventually be uploading the images onto our server so want them to be as small as possible
// CHANGE IMAGE FUNCTION
$('#changeImage').on("click", function(){
var newImage = new Image();
var img = layer.get('#Image1')[0];
newImage.onload = function() {
<-- CAN I COMPRESS IT AT THIS STAGE? -->
img.setImage(newImage);
layer.draw();
};
var random = pictures[Math.floor(Math.random()*pictures.length)];
newImage.src = random;
});
You already have the image urls saved in your pictures[] array.
Just save that url (random) on your server and not the image itself.
This cuts your storage size by 20-100 times.
If the server needs to temporarily use the image, the server can use the url to fetch it.
I'm having trouble understanding why sprites with shadows (%opacity layer) looks different in ps and on screen. Here is the comparison:
This is simply because of image formate you set. I guess you set RGBA4444 in code or while exporting spriteSheet. Also remove checkmark Premultiply alpha in texture packer.
Also check in AppDelegate Class:
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGBA8 //Guru - replaced kEAGLColorFormatRGB565 with kEAGLColorFormatRGBA8
depthFormat:0 //GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
Can someone explain to me how cocos2d uses png as a font?
I would like to do something similar as my font only contains numbers.
if you do a global search on the string fps_images.png , your IDE should take you real close to the following lines in cocos CCDirector class (version 2.0) :
FPSLabel_ = [[CCLabelAtlas alloc] initWithString:#"00.0" charMapFile:#"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
SPFLabel_ = [[CCLabelAtlas alloc] initWithString:#"0.000" charMapFile:#"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
drawsLabel_ = [[CCLabelAtlas alloc] initWithString:#"000" charMapFile:#"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
then look up CCLabelAtlas. Your image must be for a fixed width font.
If you want to reuse the same image included to make something other than the FPS display the following code should work:
CCLabelAtlas *scoreLabel = [[CCLabelAtlas alloc] initWithString:#"00.0" charMapFile:#"fps_images.png" itemWidth:12 itemHeight:32 startCharMap:'.'];
Then to set it to the numbers you want something like this works:
[scoreLabel setString:[NSString stringWithFormat:#"%d", (int)score]];