Blackberry Scrolling in Canvas - blackberry

Hi friends I searched so many threads but I didnt get any solution for scrolling vertically
when the bitmaps are drawn using graphics with paint method.
Please help me.

If you are trying to (as Jonathan said) scroll trough an image that is larger than the screen.
To do it without any fancy function´s help and you are manually painting inside your graphics paint method, i would think of using 2 bitmaps, one as a buffer for your image and another one for the actual frame:
Have your large_image in a "buffer" bitmap, and then create another bitmap to use as a canvas and paint this canvas to the screen (the same size of the screen).
Clip your large_image to the size of the screen on the region of your bitmap that you want to paint on the next frame. Save that clipped bitmap to your canvas.
Draw that canvas bitmap.
Scroll the clipping of your large_image again (move x and y values) into your "canvas" bitmap
repeat 3 and 4 until scrolling ends.
Hope it is clear, think of it as having your canvas as a camera to take smaller snapshots of your large_image and moving the large_image so that each snapshot in sequence creates the scrolling effect.
Cheers and hope it helps!.

Related

ios drawing lines to an imageView and combine the lines and the image to a new image, size of the image changed

I have an imageView and say its size is the screen size. It displays an image which has a larger size, and the imageView's content mode is set to scaleAspectFill. Then I drawing some lines on the imageView by using UIBeizerPath.
Later I would like to generate an new image which includes the lines I drew by using drawViewHierarchyInRect. The problem is the new image size is the imageView's size, since the drawViewHierarchyInRect method works only like taking a snapshot. How Can I combine the original image with the lines I drew and at the same time, keep the image's size?
You want to use the method UIGraphicsBeginImageContextWithOptions to create an off-screen context of the desired size. (In your case, the size of the image.)
Then draw your image into the context, draw the lines on top, and extract your composite image from the context. Finally, dispose of the context.
There is tons of sample code online showing how to use UIGraphicsBeginImageContextWithOptions. It's quite easy.

Get pixel values of image and crop the black part of the image : Objective C

Can I get pixel value of image and crop its black part. For instance, I have the this image:
.
And I want something like this
without the black part.
Any possible solution on how to do this? Any libraries/code?
I am using Objective C.
I have seen this solution to the similar question but I don't understand it in detail. Please kindly provide steps in detail. Thanks.
Probably the fastest way of doing this is iterating through the image and find the border pixels which are not black. Then redraw the image to a new context clipping the rect received by border pixels.
By border pixels I mean the left-most, top-most, bottom-most and right-most. You can find a way to get the raw RGBA buffer from the UIImage through which you may then iterate through width and height and set the border values when appropriate. That means for instance to get leftMostPixel you would first set it to some large value (or to the image width) and then in the iteration if the pixel is not black and if leftMostPixel > x then leftMostPixel = x.
Now that you have the 4 bounding values you can create a frame from it. To redraw just the target rectangle you may use various tools with contexts but probably the easiest is creating the view with size of bounding rect and put an image view with the size of the original image on it and create a screenshot of the view. The image view origin must be minus the origin of the bounded rect though (we put it offscreen a bit).
You may encounter some issues with the orientation of the image though. If the image will have some orientation other then up the raw data will not respect that. So you need to take that into account when creating the bounded rect... Or redraw the image first to make it oriented correctly... Or you can even create a sub buffer with RGBA data and create the CGImage from those data and applying the same orientation to the output UIImage as with input.
So after getting the bounds there are quite a few procedures. Some are slower, some take more memory, some are simply hard to code and have edge cases.

Constrain image Movement in Specific Area in Window RT App

Ok.
To describe what I want to do, have you ever used Telerik Crop function Image Editor control?
I want exactly same functionality.
I want to use that control but, I am working on Universal app that has no control like Image Editor from telerik.
That control does are
1. There is a fixed rect or canvas for cropping image.
2. If the original image is in the area of canvas(or Rect) image's opacity = 1(i guess) and if the original image is out of canvas area, image looks dim(maybe opacity 0.5 or some)
3. Constrain original image movement in the canvas.
I will implement this function in Image.ManipulationDelta event.
Do I have to get each point value of canvas? or can I do it by using Width or Height of Canvas?
How Do I do that?
Can anyone help me?
any hint?
I'm not familiar with that particular control, but I think I understand what you want.
To constrain the movement of an Image within a Canvas you can check where the Image will end up in your ManipulationDelta and limit any translation, scaling, and rotation appropriately. If the bounding box of the Image after the transform applies is within the Canvas then apply the transform. Otherwise roll it back and do nothing. I have sample code for this in my blog entry: Constraining manipulations
To dim the area outside of the crop I'd create a shape and fill it with a partially transparent brush. The all-in-one code framework sample How to crop bitmap in a Windows Store app demonstrates this technique. I believe the sample targets Windows Store 8.0 apps, but essentially the same code should work on Windows Store 8.1 or Windows Phone Store 8.1 apps.

Proportional image size changing without quality decreasing in TImage

I have TImage 800x600 with image 1024x768.
TImage aligns to alClient.
Timage is proportional.
TImage is streched.
When I resize the form, the image resizes too, but it's quality makes lower and the visible text labels on the Image shrinks, makes unreadable, or even after load big image into small TImage, I have the same problem.
How I can resolve that? How resize image in TImage with quality where text still readable in any normal size?(e.g. 1024x768 resized to 500x400, and text still readable in it).
You cannot hope to resize raster graphics and maintain high quality text. Text is rendered to a specific resolution. Any resampling will destroy the quality of the text. The only way to maintain high quality text through a resize operation is to re-render the text at the new resolution. One way to achieve that is to use a vector graphics format rather than raster. Another way is to be able to re-create the text on the fly.
TImage resizing is not perfect. I prefer to keep the original image in the memory, and to use, say, bicubic resizing when needed (or bilinear for shrinkink). Once you resized the image just draw it to the TImage on the form.
Always keep the original image in the memory, and discard the resized one from the memory once you draw it.

Drawing a PNG Graphic to a Canvas without transparency?

I've seen many questions asking how to draw transparent images, but my case is quite the opposite. I have a TPicture where I load any file type, including PNG. I then read TPicture.Graphic and call Draw directly in a TBitmap's canvas. However, when the image is drawn, it carries over the transparency of the original PNG image.
The current code is very simple, just...
MyPicture.LoadFromFile(SomeFilename);
MyBitmap.Canvas.StretchDraw(SomeRect, MyPicture.Graphic);
Now the issue is that the canvas which I'm drawing to already has an image, and this PNG is being drawn over a portion of it. When the PNG has a transparent background, normally it appears white. However, since it's directly drawing a transparent graphic to the canvas, it keeps those areas transparent.
How can I draw a PNG Graphic directly to a canvas without its original transparency while using only the canvas drawing methods? I don't want to create too many graphic objects and draw too many times, hence the reason I only have 2 lines of code above. I'm hoping there's a way I can do something like BitBlt with some special mechanism for this purpose.
The only method pre-built in Delphi XE2 has a defect and doesn't work properly. Instead, draw whitespace, or whatever background you desire, to a blank canvas. Then draw the transparent image on top.
In case you aren't drawing onto a blank canvas, you can call FillRect method of the bitmap canvas for the region you're planning to draw the png.

Resources